Files
airflow/go-sdk/.pre-commit-config.yaml
Jarek PotiukandWei Lee 0cde487d42 Stop parallel prek hooks racing on __pycache__ cleanup (#73823)
* Stop parallel prek hooks racing on __pycache__ cleanup

prek runs hooks in parallel and every breeze invocation removes all
__pycache__ directories in the checkout on start-up. Any other hook
process importing from the source tree (breeze itself, prek hook
scripts, local mypy runs) can write a fresh .pyc between rmtree emptying
a directory and removing it, which fails the breeze hook with
"OSError: [Errno 39] Directory not empty" - a flaky Static checks
failure in CI.

Redirecting bytecode of every hook into a hidden, gitignored .build/
directory keeps the source tree free of new .pyc files while hooks run,
and a new check keeps future hooks from reintroducing the race. The
cleanup additionally tolerates ENOTEMPTY for writers prek does not
control, such as an IDE.

Generated-by: Claude Opus 5

* Set PYTHONPYCACHEPREFIX on the hooks added since the branch was cut

Eight hooks that landed on main after this branch was created did not redirect their bytecode, so the new check-prek-hooks-pycache-prefix hook failed after the rebase.

Generated-by: Claude Opus 5

* Update scripts/ci/prek/check_prek_hooks_pycache_prefix.py

Co-authored-by: Wei Lee <hello@wei-lee.me>

---------

Co-authored-by: Wei Lee <hello@wei-lee.me>
2026-10-21 00:58:38 +02:00

90 lines
3.2 KiB
YAML

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
default_stages: [pre-commit, pre-push]
minimum_prek_version: '0.3.4'
default_language_version:
python: python3
node: 22.19.0
golang: 1.25.0
repos:
- repo: meta
hooks:
- id: identity
name: Print checked files
env:
PYTHONPYCACHEPREFIX: .build/pycache
description: Print input to the static check hooks for troubleshooting
- id: check-hooks-apply
name: Check if all hooks apply to the repository
env:
PYTHONPYCACHEPREFIX: .build/pycache
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: ad1b27d73581aa16cca06fc4a0761fc563ffe8e8 # frozen: v1.5.6
hooks:
- id: insert-license
name: Add license for all Go files
env:
PYTHONPYCACHEPREFIX: .build/pycache
types: [go]
exclude: mocks/.*\.go$|\.pb\.go$
args:
- --comment-style
- "|//|"
- --license-filepath
- ../scripts/ci/license-templates/LICENSE.txt
- --insert-license-after-regex
# We need this 'generated by' line at the top for `golines` to not format it
- '// Code generated by .*'
- repo: local
hooks:
- id: go-mod-tidy
name: Run go mod tidy
env:
PYTHONPYCACHEPREFIX: .build/pycache
entry: go mod tidy
types: [go]
exclude: mocks/.*\.go$
pass_filenames: false
language: golang
- id: imports
name: Consistent import ordering for Go files
env:
PYTHONPYCACHEPREFIX: .build/pycache
entry: goimports-reviser -rm-unused -set-exit-status
additional_dependencies: [github.com/incu6us/goimports-reviser/v3@v3.10.0]
types: [go]
language: golang
require_serial: true
- id: gofmt
name: Format go code
env:
PYTHONPYCACHEPREFIX: .build/pycache
entry: golines --base-formatter=gofumpt --write-output --max-len=100 --chain-split-dots
additional_dependencies: [github.com/segmentio/golines@latest, mvdan.cc/gofumpt@v0.8.0]
types: [go]
language: golang
- id: staticcheck
name: Check naming in Go code
env:
PYTHONPYCACHEPREFIX: .build/pycache
entry: staticcheck -checks ST1003 ./...
additional_dependencies: [honnef.co/go/tools/cmd/staticcheck@v0.7.0]
types: [go]
pass_filenames: false
language: golang