Skip to content

Commit 2d87c0e

Browse files
authored
Merge pull request #3157 from jakkdl/cleanup_checksh
Clean up check.sh, move stuff to pre-commit
2 parents 3260974 + 2bc884c commit 2d87c0e

File tree

5 files changed

+56
-60
lines changed

5 files changed

+56
-60
lines changed

.pre-commit-config.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ ci:
22
autofix_prs: true
33
autoupdate_schedule: weekly
44
submodules: false
5-
skip: [regenerate-files]
5+
# pip-compile requires internet, regenerate-files may get cache
6+
# issues in CI, so they're run in check.sh
7+
skip: [pip-compile, regenerate-files]
68

79
repos:
810
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -44,7 +46,30 @@ repos:
4446
hooks:
4547
- id: regenerate-files
4648
name: regenerate generated files
47-
language: system
49+
language: python
4850
entry: python src/trio/_tools/gen_exports.py
4951
pass_filenames: false
52+
additional_dependencies: ["astor", "attrs", "black", "ruff"]
5053
files: ^src\/trio\/_core\/(_run|(_i(o_(common|epoll|kqueue|windows)|nstrumentation)))\.py$
54+
- repo: https://github.com/astral-sh/uv-pre-commit
55+
rev: 0.5.9
56+
hooks:
57+
# Compile requirements
58+
- id: pip-compile
59+
name: uv pip-compile test-requirements.in
60+
args: [
61+
"--universal",
62+
"--python-version=3.9",
63+
"test-requirements.in",
64+
"-o",
65+
"test-requirements.txt"]
66+
files: ^test-requirements\.(in|txt)$
67+
- id: pip-compile
68+
name: uv pip-compile docs-requirements.in
69+
args: [
70+
"--universal",
71+
"--python-version=3.11",
72+
"docs-requirements.in",
73+
"-o",
74+
"docs-requirements.txt"]
75+
files: ^docs-requirements\.(in|txt)$

check.sh

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,6 @@ python ./src/trio/_tools/gen_exports.py --test \
1717
|| EXIT_STATUS=$?
1818
echo "::endgroup::"
1919

20-
# Autoformatter *first*, to avoid double-reporting errors
21-
# (we'd like to run further autoformatters but *after* merging;
22-
# see https://forum.bors.tech/t/pre-test-and-pre-merge-hooks/322)
23-
# autoflake --recursive --in-place .
24-
# pyupgrade --py3-plus $(find . -name "*.py")
25-
echo "::group::Black"
26-
if ! black --check src/trio; then
27-
echo "* Black found issues" >> "$GITHUB_STEP_SUMMARY"
28-
EXIT_STATUS=1
29-
black --diff src/trio
30-
echo "::endgroup::"
31-
echo "::error:: Black found issues"
32-
else
33-
echo "::endgroup::"
34-
fi
35-
36-
# Run ruff, configured in pyproject.toml
37-
echo "::group::Ruff"
38-
if ! ruff check .; then
39-
echo "* ruff found issues." >> "$GITHUB_STEP_SUMMARY"
40-
EXIT_STATUS=1
41-
if $ON_GITHUB_CI; then
42-
ruff check --output-format github --diff .
43-
else
44-
ruff check --diff .
45-
fi
46-
echo "::endgroup::"
47-
echo "::error:: ruff found issues"
48-
else
49-
echo "::endgroup::"
50-
fi
51-
5220
# Run mypy on all supported platforms
5321
# MYPY is set if any of them fail.
5422
MYPY=0
@@ -77,25 +45,11 @@ if [ $MYPY -ne 0 ]; then
7745
fi
7846

7947
# Check pip compile is consistent
80-
echo "::group::Pip Compile - Tests"
81-
uv pip compile --universal --python-version=3.9 test-requirements.in -o test-requirements.txt
82-
echo "::endgroup::"
83-
echo "::group::Pip Compile - Docs"
84-
uv pip compile --universal --python-version=3.11 docs-requirements.in -o docs-requirements.txt
48+
echo "::group::Pip Compile - Tests & Docs"
49+
pre-commit run pip-compile --all-files \
50+
|| EXIT_STATUS=$?
8551
echo "::endgroup::"
8652

87-
if git status --porcelain | grep -q "requirements.txt"; then
88-
echo "::error::requirements.txt changed."
89-
echo "::group::requirements.txt changed"
90-
echo "* requirements.txt changed" >> "$GITHUB_STEP_SUMMARY"
91-
git status --porcelain
92-
git --no-pager diff --color ./*requirements.txt
93-
EXIT_STATUS=1
94-
echo "::endgroup::"
95-
fi
96-
97-
codespell || EXIT_STATUS=$?
98-
9953
echo "::group::Pyright interface tests"
10054
python src/trio/_tests/check_type_completeness.py || EXIT_STATUS=$?
10155

@@ -113,8 +67,7 @@ Problems were found by static analysis (listed above).
11367
To fix formatting and see remaining errors, run
11468
11569
uv pip install -r test-requirements.txt
116-
black src/trio
117-
ruff check src/trio
70+
pre-commit run --all-files
11871
./check.sh
11972
12073
in your local checkout.

docs-requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ beautifulsoup4==4.12.3
1212
# via sphinx-codeautolink
1313
certifi==2024.8.30
1414
# via requests
15-
cffi==1.17.1 ; platform_python_implementation != 'PyPy' or os_name == 'nt'
15+
cffi==1.17.1 ; os_name == 'nt' or platform_python_implementation != 'PyPy'
1616
# via
1717
# -r docs-requirements.in
1818
# cryptography
1919
charset-normalizer==3.4.0
2020
# via requests
2121
click==8.1.7
2222
# via towncrier
23-
colorama==0.4.6 ; sys_platform == 'win32' or platform_system == 'Windows'
23+
colorama==0.4.6 ; platform_system == 'Windows' or sys_platform == 'win32'
2424
# via
2525
# click
2626
# sphinx
@@ -51,7 +51,7 @@ outcome==1.3.0.post0
5151
# via -r docs-requirements.in
5252
packaging==24.2
5353
# via sphinx
54-
pycparser==2.22 ; platform_python_implementation != 'PyPy' or os_name == 'nt'
54+
pycparser==2.22 ; os_name == 'nt' or platform_python_implementation != 'PyPy'
5555
# via cffi
5656
pygments==2.18.0
5757
# via sphinx

test-requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ruff >= 0.8.0
1717
astor # code generation
1818
uv >= 0.2.24
1919
codespell
20+
pre-commit
2021

2122
# https://github.com/python-trio/trio/pull/654#issuecomment-420518745
2223
mypy-extensions

test-requirements.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ black==24.10.0 ; implementation_name == 'cpython'
1818
# via -r test-requirements.in
1919
certifi==2024.8.30
2020
# via requests
21-
cffi==1.17.1 ; platform_python_implementation != 'PyPy' or os_name == 'nt'
21+
cffi==1.17.1 ; os_name == 'nt' or platform_python_implementation != 'PyPy'
2222
# via
2323
# -r test-requirements.in
2424
# cryptography
25+
cfgv==3.4.0
26+
# via pre-commit
2527
charset-normalizer==3.4.0
2628
# via requests
2729
click==8.1.7 ; implementation_name == 'cpython'
2830
# via black
2931
codespell==2.3.0
3032
# via -r test-requirements.in
31-
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')
33+
colorama==0.4.6 ; (implementation_name == 'cpython' and platform_system == 'Windows') or sys_platform == 'win32'
3234
# via
3335
# click
3436
# pylint
@@ -44,12 +46,18 @@ cryptography==43.0.3
4446
# types-pyopenssl
4547
dill==0.3.9
4648
# via pylint
49+
distlib==0.3.9
50+
# via virtualenv
4751
docutils==0.21.2
4852
# via sphinx
4953
exceptiongroup==1.2.2 ; python_full_version < '3.11'
5054
# via
5155
# -r test-requirements.in
5256
# pytest
57+
filelock==3.16.1
58+
# via virtualenv
59+
identify==2.6.3
60+
# via pre-commit
5361
idna==3.10
5462
# via
5563
# -r test-requirements.in
@@ -79,7 +87,9 @@ mypy-extensions==1.0.0
7987
# black
8088
# mypy
8189
nodeenv==1.9.1
82-
# via pyright
90+
# via
91+
# pre-commit
92+
# pyright
8393
orjson==3.10.12 ; implementation_name == 'cpython'
8494
# via -r test-requirements.in
8595
outcome==1.3.0.post0
@@ -97,9 +107,12 @@ platformdirs==4.3.6
97107
# via
98108
# black
99109
# pylint
110+
# virtualenv
100111
pluggy==1.5.0
101112
# via pytest
102-
pycparser==2.22 ; platform_python_implementation != 'PyPy' or os_name == 'nt'
113+
pre-commit==4.0.1
114+
# via -r test-requirements.in
115+
pycparser==2.22 ; os_name == 'nt' or platform_python_implementation != 'PyPy'
103116
# via cffi
104117
pygments==2.18.0
105118
# via sphinx
@@ -111,6 +124,8 @@ pyright==1.1.389
111124
# via -r test-requirements.in
112125
pytest==8.3.3
113126
# via -r test-requirements.in
127+
pyyaml==6.0.2
128+
# via pre-commit
114129
requests==2.32.3
115130
# via sphinx
116131
ruff==0.8.4
@@ -168,5 +183,7 @@ urllib3==2.2.3
168183
# via requests
169184
uv==0.5.5
170185
# via -r test-requirements.in
186+
virtualenv==20.28.0
187+
# via pre-commit
171188
zipp==3.21.0 ; python_full_version < '3.10'
172189
# via importlib-metadata

0 commit comments

Comments
 (0)