diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13e1cf7d7..ff1a42f28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,9 @@ ci: autofix_prs: true autoupdate_schedule: weekly submodules: false - skip: [regenerate-files] + # pip-compile requires internet, regenerate-files may get cache + # issues in CI, so they're run in check.sh + skip: [pip-compile, regenerate-files] repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -44,7 +46,30 @@ repos: hooks: - id: regenerate-files name: regenerate generated files - language: system + language: python entry: python src/trio/_tools/gen_exports.py pass_filenames: false + additional_dependencies: ["astor", "attrs", "black", "ruff"] files: ^src\/trio\/_core\/(_run|(_i(o_(common|epoll|kqueue|windows)|nstrumentation)))\.py$ + - repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.5.9 + hooks: + # Compile requirements + - id: pip-compile + name: uv pip-compile test-requirements.in + args: [ + "--universal", + "--python-version=3.9", + "test-requirements.in", + "-o", + "test-requirements.txt"] + files: ^test-requirements\.(in|txt)$ + - id: pip-compile + name: uv pip-compile docs-requirements.in + args: [ + "--universal", + "--python-version=3.11", + "docs-requirements.in", + "-o", + "docs-requirements.txt"] + files: ^docs-requirements\.(in|txt)$ diff --git a/check.sh b/check.sh index b65967596..701db8ce6 100755 --- a/check.sh +++ b/check.sh @@ -17,38 +17,6 @@ python ./src/trio/_tools/gen_exports.py --test \ || EXIT_STATUS=$? echo "::endgroup::" -# Autoformatter *first*, to avoid double-reporting errors -# (we'd like to run further autoformatters but *after* merging; -# see https://forum.bors.tech/t/pre-test-and-pre-merge-hooks/322) -# autoflake --recursive --in-place . -# pyupgrade --py3-plus $(find . -name "*.py") -echo "::group::Black" -if ! black --check src/trio; then - echo "* Black found issues" >> "$GITHUB_STEP_SUMMARY" - EXIT_STATUS=1 - black --diff src/trio - echo "::endgroup::" - echo "::error:: Black found issues" -else - echo "::endgroup::" -fi - -# Run ruff, configured in pyproject.toml -echo "::group::Ruff" -if ! ruff check .; then - echo "* ruff found issues." >> "$GITHUB_STEP_SUMMARY" - EXIT_STATUS=1 - if $ON_GITHUB_CI; then - ruff check --output-format github --diff . - else - ruff check --diff . - fi - echo "::endgroup::" - echo "::error:: ruff found issues" -else - echo "::endgroup::" -fi - # Run mypy on all supported platforms # MYPY is set if any of them fail. MYPY=0 @@ -77,25 +45,11 @@ if [ $MYPY -ne 0 ]; then fi # Check pip compile is consistent -echo "::group::Pip Compile - Tests" -uv pip compile --universal --python-version=3.9 test-requirements.in -o test-requirements.txt -echo "::endgroup::" -echo "::group::Pip Compile - Docs" -uv pip compile --universal --python-version=3.11 docs-requirements.in -o docs-requirements.txt +echo "::group::Pip Compile - Tests & Docs" +pre-commit run pip-compile --all-files \ + || EXIT_STATUS=$? echo "::endgroup::" -if git status --porcelain | grep -q "requirements.txt"; then - echo "::error::requirements.txt changed." - echo "::group::requirements.txt changed" - echo "* requirements.txt changed" >> "$GITHUB_STEP_SUMMARY" - git status --porcelain - git --no-pager diff --color ./*requirements.txt - EXIT_STATUS=1 - echo "::endgroup::" -fi - -codespell || EXIT_STATUS=$? - echo "::group::Pyright interface tests" python src/trio/_tests/check_type_completeness.py || EXIT_STATUS=$? @@ -113,8 +67,7 @@ Problems were found by static analysis (listed above). To fix formatting and see remaining errors, run uv pip install -r test-requirements.txt - black src/trio - ruff check src/trio + pre-commit run --all-files ./check.sh in your local checkout. diff --git a/docs-requirements.txt b/docs-requirements.txt index 03cefbc9a..5764bd9c6 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -12,7 +12,7 @@ beautifulsoup4==4.12.3 # via sphinx-codeautolink certifi==2024.8.30 # via requests -cffi==1.17.1 ; platform_python_implementation != 'PyPy' or os_name == 'nt' +cffi==1.17.1 ; os_name == 'nt' or platform_python_implementation != 'PyPy' # via # -r docs-requirements.in # cryptography @@ -20,7 +20,7 @@ charset-normalizer==3.4.0 # via requests click==8.1.7 # via towncrier -colorama==0.4.6 ; sys_platform == 'win32' or platform_system == 'Windows' +colorama==0.4.6 ; platform_system == 'Windows' or sys_platform == 'win32' # via # click # sphinx @@ -51,7 +51,7 @@ outcome==1.3.0.post0 # via -r docs-requirements.in packaging==24.2 # via sphinx -pycparser==2.22 ; platform_python_implementation != 'PyPy' or os_name == 'nt' +pycparser==2.22 ; os_name == 'nt' or platform_python_implementation != 'PyPy' # via cffi pygments==2.18.0 # via sphinx diff --git a/test-requirements.in b/test-requirements.in index 809e171e3..2e29cda42 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -17,6 +17,7 @@ ruff >= 0.8.0 astor # code generation uv >= 0.2.24 codespell +pre-commit # https://github.com/python-trio/trio/pull/654#issuecomment-420518745 mypy-extensions diff --git a/test-requirements.txt b/test-requirements.txt index a5c17a256..351e3fc17 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -18,17 +18,19 @@ black==24.10.0 ; implementation_name == 'cpython' # via -r test-requirements.in certifi==2024.8.30 # via requests -cffi==1.17.1 ; platform_python_implementation != 'PyPy' or os_name == 'nt' +cffi==1.17.1 ; os_name == 'nt' or platform_python_implementation != 'PyPy' # via # -r test-requirements.in # cryptography +cfgv==3.4.0 + # via pre-commit charset-normalizer==3.4.0 # via requests click==8.1.7 ; implementation_name == 'cpython' # via black codespell==2.3.0 # via -r test-requirements.in -colorama==0.4.6 ; (implementation_name != 'cpython' and sys_platform == 'win32') or (platform_system != 'Windows' and sys_platform == 'win32') or (implementation_name == 'cpython' and platform_system == 'Windows') +colorama==0.4.6 ; (implementation_name == 'cpython' and platform_system == 'Windows') or sys_platform == 'win32' # via # click # pylint @@ -44,12 +46,18 @@ cryptography==43.0.3 # types-pyopenssl dill==0.3.9 # via pylint +distlib==0.3.9 + # via virtualenv docutils==0.21.2 # via sphinx exceptiongroup==1.2.2 ; python_full_version < '3.11' # via # -r test-requirements.in # pytest +filelock==3.16.1 + # via virtualenv +identify==2.6.3 + # via pre-commit idna==3.10 # via # -r test-requirements.in @@ -79,7 +87,9 @@ mypy-extensions==1.0.0 # black # mypy nodeenv==1.9.1 - # via pyright + # via + # pre-commit + # pyright orjson==3.10.12 ; implementation_name == 'cpython' # via -r test-requirements.in outcome==1.3.0.post0 @@ -97,9 +107,12 @@ platformdirs==4.3.6 # via # black # pylint + # virtualenv pluggy==1.5.0 # via pytest -pycparser==2.22 ; platform_python_implementation != 'PyPy' or os_name == 'nt' +pre-commit==4.0.1 + # via -r test-requirements.in +pycparser==2.22 ; os_name == 'nt' or platform_python_implementation != 'PyPy' # via cffi pygments==2.18.0 # via sphinx @@ -111,6 +124,8 @@ pyright==1.1.389 # via -r test-requirements.in pytest==8.3.3 # via -r test-requirements.in +pyyaml==6.0.2 + # via pre-commit requests==2.32.3 # via sphinx ruff==0.8.4 @@ -168,5 +183,7 @@ urllib3==2.2.3 # via requests uv==0.5.5 # via -r test-requirements.in +virtualenv==20.28.0 + # via pre-commit zipp==3.21.0 ; python_full_version < '3.10' # via importlib-metadata