-
Notifications
You must be signed in to change notification settings - Fork 410
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
Add pre-commit hook to stop linting errors being pushed. #2632
Conversation
In general I am supportive of this. The main question I have is how we can ensure that this stays in sync with the versions as defined in https://github.com/pytorch/botorch/blob/main/requirements-fmt.txt. Note that the versions in that file are synced with our internal linting tools, and so these may be updated without us actively doing those updates. If we hard-code versions of the tools in |
So your concern is immediately apparent given this v2.3.0 vs v2.8.0 issue there were 3 lines of code which were changed by Is the SSOT for the internal tools |
So the SSOT for this lives in our internal repos; the way it works is that if changes are made there this automatically gets exported to the different github repos that we have for OSS projects. So for all intents and purposes, from the PoV of OSS versioning and pre-commit hooks, the versions defined in |
Having had a think about this I think the best I can do is define a script called in the pre-commit that parses the file and the action file and then fails if the two do not match. This isn't automatic but it would mean that anyone using the pre-commit would be forced to fix the divergence in order to satisfy the hook with would give eventual consistency to the SSOT -- it would only significantly diverge if no-one used the pre-commit. That said given the linked issue that would put this PR on ice until omnilib/ufmt#251 is resolved. Has the internal team considered |
I think this makes sense to me, seems like a reasonable approach and I don't have any better one off the top of my head...
There are ongoing discussions, yes, but making these kind of changes in a monorepo of our size is no small effort. We'll keep plugged in and see where this goes. |
This now implements the proposed solution and it's easy to do the downstream fix and set ruff-api in the action I defined and so not actually blocked by omnilib/ufmt#251. |
No, and this is a known/intentional limitation of pre-commit — they don't offer any option beyond explicit package lists in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks this overall lgtm, just some nits.
The formatting changes here, are those things that snuck through previously on our end? It doesn't seem like there are any changes in terms of the versions?
Will get the nits and then double check it still works. They were flake8 errors I got running flake globally with |
Makes sense, let's just import it and see if the internal linter complains... Main thing would be that flake8 honors the settings in |
Checked the edge cases manually and tested that it takes the flake8 settings from I think this is good to go. |
@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hmm @CompRhys this seems like this is need of another rebase :( |
I think this is actually a real error based on the behaviour of f-strings f"{xyz=}" (which flake8 wants) being different to f"{xyz = }" as it keeps the spaces.
|
I wasn't referring to the error as much as that I wasn't able to re-import the PR. Also, did you mean to close this? |
force-pushing on reset/rebase closes PRs |
@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
So one thought I had to ensure that the hard-coded yaml versions stay in sync with the SOT in the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2632 +/- ##
=======================================
Coverage 99.98% 99.98%
=======================================
Files 196 196
Lines 17362 17365 +3
=======================================
+ Hits 17360 17363 +3
Misses 2 2 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
could I change the lint CI to be this:
as then that would check in CI and also creates a SSOT connection between the pre-commit and the lint action, or is the lint action created by some internal tool? (This is how many projects I have worked on that give pre-commit hooks have their linting actions setup). I think doing it with the unit tests is more messy but could do if needed |
Co-authored-by: Max Balandat <[email protected]>
Yeah I guess that could work? Though that would require setting up |
@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
I realized we shold probably have updated the |
Ah nvm I forgot that you had already included that. Thanks a lot for the contribution, @CompRhys! |
thanks for your patience, now to run it back for |
Summary: Mirrors PR to botorch: pytorch/botorch#2632 applying the same solution to ensure that there is eventual consistency to the source of truth in `requirements-fmt.txt`. Fixes flake8 errors that occured when running ```python (base) ➜ Ax git:(pre-commit) ✗ pre-commit run --all-files [INFO] Installing environment for https://github.com/pycqa/flake8. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... Check pre-commit formatting versions.....................................Passed Format files with µfmt...................................................Passed flake8...................................................................Failed - hook id: flake8 - exit code: 1 ax/benchmark/tests/problems/test_mixed_integer_problems.py:60:23: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:70:23: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:76:29: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:77:29: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:78:29: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:84:23: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:90:29: E226 missing whitespace around arithmetic operator ax/benchmark/tests/problems/test_mixed_integer_problems.py:91:29: E226 missing whitespace around arithmetic operator ax/modelbridge/tests/test_prediction_utils.py:165:39: E226 missing whitespace around arithmetic operator ax/service/tests/test_global_stopping.py:50:43: E226 missing whitespace around arithmetic operator scripts/insert_api_refs.py:47:35: E226 missing whitespace around arithmetic operator ``` Pull Request resolved: #3082 Reviewed By: sdaulton Differential Revision: D66190310 Pulled By: Balandat fbshipit-source-id: 05ce2786cf15baf3554f7d5f8e835e17e1258ed4
Motivation
I am so used to relying on
pre-commit
that I have forgotten to run manual linting when making PRs tobotorch
. This adds a simplepre-commit
config to automate linting.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
This PR should not affect anything. There are tools to run pre-commit in ci that maintainers could add to the package: https://pre-commit.ci/
Related Issues:
omnilib/ufmt#251 The pre-commit hook only seems to work for v2.3.0 of ufmt. This issue tracks the error following from ruff_api.