From 9b3783f0d824e21da442be90ba772f5956c981f1 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 17 Dec 2024 12:10:32 +0100 Subject: [PATCH 1/8] remove ruff, black, codespell, and gen-exports from check.sh as they're now run in pre-commit --- .pre-commit-config.yaml | 2 +- check.sh | 40 ---------------------------------------- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e06d1c7ac..9322661da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autofix_prs: true autoupdate_schedule: weekly submodules: false - skip: [regenerate-files] + skip: [] repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/check.sh b/check.sh index b65967596..8e3329272 100755 --- a/check.sh +++ b/check.sh @@ -11,44 +11,6 @@ if [ -z "${GITHUB_STEP_SUMMARY+x}" ]; then ON_GITHUB_CI=false fi -# Test if the generated code is still up to date -echo "::group::Generate Exports" -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 @@ -94,8 +56,6 @@ if git status --porcelain | grep -q "requirements.txt"; then echo "::endgroup::" fi -codespell || EXIT_STATUS=$? - echo "::group::Pyright interface tests" python src/trio/_tests/check_type_completeness.py || EXIT_STATUS=$? From 84433f496b7b4efb00dc93e8dba27a68af101bd1 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 17 Dec 2024 12:43:48 +0100 Subject: [PATCH 2/8] move pip-compile tests to pre-commit --- .pre-commit-config.yaml | 22 ++++++++++++++++++++++ check.sh | 18 ------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9322661da..e3fe8e364 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,3 +44,25 @@ repos: entry: python src/trio/_tools/gen_exports.py pass_filenames: false 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 8e3329272..a6bc44f4c 100755 --- a/check.sh +++ b/check.sh @@ -38,24 +38,6 @@ if [ $MYPY -ne 0 ]; then EXIT_STATUS=1 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 "::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 - echo "::group::Pyright interface tests" python src/trio/_tests/check_type_completeness.py || EXIT_STATUS=$? From 7557558b2a55ca73e7b1bfde664e52099a635b43 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 17 Dec 2024 14:16:24 +0100 Subject: [PATCH 3/8] restore pip-compile in check.sh, skip in CI --- .pre-commit-config.yaml | 2 +- check.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e3fe8e364..d19544e90 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autofix_prs: true autoupdate_schedule: weekly submodules: false - skip: [] + skip: ["pip-compile", "pip-compile-docs"] repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/check.sh b/check.sh index a6bc44f4c..8e3329272 100755 --- a/check.sh +++ b/check.sh @@ -38,6 +38,24 @@ if [ $MYPY -ne 0 ]; then EXIT_STATUS=1 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 "::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 + echo "::group::Pyright interface tests" python src/trio/_tests/check_type_completeness.py || EXIT_STATUS=$? From b38faba639b0440006b336ba7bf3e47a0f7be973 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 17 Dec 2024 14:16:58 +0100 Subject: [PATCH 4/8] make regenerate-files runnable in CI, with the downside of not freezing deps --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d19544e90..6e94bc5d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,9 +40,10 @@ 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 From 17d3d051fe7486a8f3731852a14438b87046cf60 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Tue, 17 Dec 2024 14:18:38 +0100 Subject: [PATCH 5/8] fix skip --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e94bc5d4..505169f42 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autofix_prs: true autoupdate_schedule: weekly submodules: false - skip: ["pip-compile", "pip-compile-docs"] + skip: ["pip-compile"] repos: - repo: https://github.com/pre-commit/pre-commit-hooks From 22215d0ecef3a4a96ea12e09c3a37f66cb6ef467 Mon Sep 17 00:00:00 2001 From: jakkdl Date: Sun, 22 Dec 2024 12:52:06 +0100 Subject: [PATCH 6/8] restore gen_exports in check.sh, skip in pre-commit+ci --- .pre-commit-config.yaml | 4 +++- check.sh | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6153cf224..590bf0cc9 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: ["pip-compile"] + # 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 diff --git a/check.sh b/check.sh index 8e3329272..81ff3a394 100755 --- a/check.sh +++ b/check.sh @@ -11,6 +11,12 @@ if [ -z "${GITHUB_STEP_SUMMARY+x}" ]; then ON_GITHUB_CI=false fi +# Test if the generated code is still up to date +echo "::group::Generate Exports" +python ./src/trio/_tools/gen_exports.py --test \ + || EXIT_STATUS=$? +echo "::endgroup::" + # Run mypy on all supported platforms # MYPY is set if any of them fail. MYPY=0 From b4d08e1897aca3b7263b1f7e91a3cc00497e66ac Mon Sep 17 00:00:00 2001 From: jakkdl Date: Mon, 23 Dec 2024 11:08:50 +0100 Subject: [PATCH 7/8] make check.sh call pre-commit --- check.sh | 21 ++++----------------- test-requirements.in | 1 + test-requirements.txt | 25 +++++++++++++++++++++---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/check.sh b/check.sh index 81ff3a394..701db8ce6 100755 --- a/check.sh +++ b/check.sh @@ -45,23 +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 - echo "::group::Pyright interface tests" python src/trio/_tests/check_type_completeness.py || EXIT_STATUS=$? @@ -79,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/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 87b3c581e..e3dae1d49 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.2 @@ -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 From 8f787d63afcfd2d0b132347d6f131c6275d93a4e Mon Sep 17 00:00:00 2001 From: jakkdl Date: Mon, 23 Dec 2024 11:33:35 +0100 Subject: [PATCH 8/8] it seems uv pip-compile is sorting the requirements now --- docs-requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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