Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up check.sh, move stuff to pre-commit #3157

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Dec 17, 2024

Ruff, Black, Codespell and gen-exports are all run in pre-commit, so there's no need to also run them in check.sh
moving uv pip-compile to pre-commit was easy

The only remaining tools in check.sh now are:

  1. pyright pyright+pre-commit+CI does not play well, as pyright ~requires an internet connection and pre-commit in CI isolates the environment not to have it. In flake8-async we have a dedicated CI action for pyright that uses an unofficial github action.
    EDIT: Though we also have check_type_completeness.py that won't play well with that pyright-action.

  2. mypy I think doing 3 full runs (all platforms) would be overly slow for local development, but I'm not sure it's possible to specify manual stages to run with the pre-commit github action. So best solution here is perhaps to configure a mypy pre-commit hook (using current system?) and once again add a dedicated CI action.

Addresses some of #2699

@jakkdl jakkdl requested a review from CoolCat467 December 17, 2024 11:51
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00000%. Comparing base (92b0480) to head (2bc884c).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3157   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             124          124           
  Lines           18427        18427           
  Branches         1215         1215           
===============================================
  Hits            18427        18427           

@jakkdl
Copy link
Member Author

jakkdl commented Dec 17, 2024

ah right, of course pip-compile also requires internet. There's maybe a configuration with repo: local and language: system but eh. Unclear if it's worth running locally

echo "::group::Generate Exports"
python ./src/trio/_tools/gen_exports.py --test \
|| EXIT_STATUS=$?
echo "::endgroup::"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably should do this in another PR but I think we should move gen exports out of pre-commit and back here. Unfortunately, as things currently are, if you modify a file that the pre-commit hook says it uses then commit with a git client (ie not just git commit -m "..." in the venv you have for trio), gen_exports doesn't get the dependencies it needs.

So far I've been getting that error then going to my terminal to run git there, but that's a bit much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-commit with a external git client doesn't install required dependencies?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, because we don't specify them. We don't specify them because pre-commit doesn't let you install from a requirements file :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specified them in the latest commit:

additional_dependencies: ["astor", "attrs", "black", "ruff"]

but that doesn't let us pin the versions (in a non-awful way), so yeah if we don't want that then it has to go outside of pre-commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional_dependencies: ["astor", "attrs", "black", "ruff"]

Keep in mind that the pre-commit cache is virtually immortal. You can clean it locally, but not in the pre-commit.ci service. For that, changing the deps list or the hook version is required. This may be problematic sometimes.

So I've found that the best thing to do here is to keep the version pins in the list and bump them periodically. Just so that the cache doesn't grow too old.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that means we need to keep it in check.sh and skip it in ci for now. I'll keep the changes to the pre-commit hook to alleviate @A5rocks's problem, and maybe use tox or something later on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tox sounds wonderful. I've been meaning to suggest it. I've actually been working on some reusable workflows for tox-based projects + experimented with some cool GHA integrations.
When you get to it, I may offer some help / experimentation in simplifying things here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm personally a big fan of tox. #2790 discussed hatchling too but we ended up bikeshedding too much to actually do anything in the end.

@@ -94,8 +56,6 @@ if git status --porcelain | grep -q "requirements.txt"; then
echo "::endgroup::"
fi

codespell || EXIT_STATUS=$?
Copy link
Contributor

@A5rocks A5rocks Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not the right line because github isn't letting me comment there)

Should you remove the uv pip compile lines above? And also update the error message + add a pre-commit run -a line in check.sh so people can run check.sh locally? (I'm not sure people do run check.sh locally but...)

Copy link
Member Author

@jakkdl jakkdl Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized we can't do uv pip compile in pre-commit in CI since it needs internet, so it needs to be here (or somewhere).

My goal is not to require/expect people to run check.sh locally as it's unintuitive and clunky, but given the limitations of pre-commit we do need to stash these somewhere and make it easy for users to run them locally if they want.
I'd personally vote for tox (due to familiarity), and set up environments for the different tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually wrap the pre-commit invocation in tox for local run anyway + run it in CI too, which covers the case of the service not having the internet during testing.

Copy link
Member

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving things to pre-commit looks great, just wondering about how this will work with CI. Will CI check to make sure pre-commit run succeeds before allowing merge, or do we have to change what is required in the "all greens" workflow?

@jakkdl
Copy link
Member Author

jakkdl commented Dec 22, 2024

[once again registering my displeasure with not being able to squash on merge]
I'll manually squash and force push after giving y'all a chance to review, since force pushing breaks review history on github.

I've scaled back the PR to:

  1. remove redundant formatting/linting from check.sh (although I'm not sure if pre-commit is 'required' to merge? so not strictly 100% redundant)
  2. change pre-commit entry for regenerate-files to have dependencies instead of relying on the local environment having them.
  3. Add pip-compile checks to pre-commit, which are skipped in CI.

@webknjaz
Copy link
Member

  • remove redundant formatting/linting from check.sh (although I'm not sure if pre-commit is 'required' to merge? so not strictly 100% redundant)

No, it's not required, but I'd ask @A5rocks to make it mandatory in the ruleset.

  • Add pip-compile checks to pre-commit, which are skipped in CI.

To address such cases, I like duplicating the pre-commit invocation in conventional CI, which I'd recommend here as well. If you want to, you can select/skip some checks to make sure that only those that can't run in the pre-commit.ci platform would run on GHA. But you can also not care and run everything additionally — it's usually inexpensive.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hook stage manual?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?
We don't have any manual hooks anymore

@jakkdl
Copy link
Member Author

jakkdl commented Dec 23, 2024

Hrm, I just noticed this warning

warning: The requested Python version 3.11 is not available; 3.13.1 will be used to build dependencies instead.

https://github.com/python-trio/trio/actions/runs/12465050038/job/34790209503?pr=3157
which is also happening on main/ atm @A5rocks

warning: The requested Python version 3.9 is not available; 3.13.1 will be used to build dependencies instead.

https://github.com/python-trio/trio/actions/runs/12446716072/job/34749424898#step:5:1098

I think the easiest fix will be tox, although it doesn't seem to have mattered so far

(3.9 vs 3.11 is because we compile test-requirements on 3.9 and docs-requirements on 3.11)

@jakkdl
Copy link
Member Author

jakkdl commented Dec 23, 2024

running it through pre-commit I appear to have bumped uv from 5.5 to ~5.11, so I suppose they started sorting the version/platform constraints at some point (though not seeing it from a quick skim of the changelogs https://github.com/astral-sh/uv/releases).

@graingert
Copy link
Member

graingert commented Dec 23, 2024

Can we use '3.x' for dists and code checks, instead of 3.11?

@jakkdl
Copy link
Member Author

jakkdl commented Dec 23, 2024

Can we use '3.x' for dists and code checks, instead of 3.11?

if the python version doesn't matter for uv pip-compile we could simply opt out of passing --python-version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants