Skip to content

Commit

Permalink
Merge pull request #3157 from jakkdl/cleanup_checksh
Browse files Browse the repository at this point in the history
Clean up check.sh, move stuff to pre-commit
  • Loading branch information
jakkdl authored Dec 24, 2024
2 parents 3260974 + 2bc884c commit 2d87c0e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 60 deletions.
29 changes: 27 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)$
55 changes: 4 additions & 51 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=$?

Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 21 additions & 4 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 2d87c0e

Please sign in to comment.