-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CI: mypy&pyright in manual pre-commit stage #47075
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b9ca491
CI: mypy&pyright in manual pre-commit stage
twoertwein cc0c6f0
move mypy+pyright to pre-commit
twoertwein d249177
Revert "move mypy+pyright to pre-commit"
twoertwein a8ad73f
system+manual
twoertwein bc3b01a
Update .pre-commit-config.yaml
twoertwein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,15 +67,6 @@ jobs: | |
environment-file: ${{ env.ENV_FILE }} | ||
use-only-tar-bz2: true | ||
|
||
- name: Install node.js (for pyright) | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16" | ||
|
||
- name: Install pyright | ||
# note: keep version in sync with .pre-commit-config.yaml | ||
run: npm install -g [email protected] | ||
|
||
- name: Build Pandas | ||
id: build | ||
uses: ./.github/actions/build_pandas | ||
|
@@ -96,8 +87,16 @@ jobs: | |
run: ci/code_checks.sh docstrings | ||
if: ${{ steps.build.outcome == 'success' }} | ||
|
||
- name: Run typing validation | ||
run: ci/code_checks.sh typing | ||
- name: Use existing environment for type checking | ||
run: | | ||
echo $PATH >> $GITHUB_PATH | ||
echo "PYTHONHOME=$PYTHONHOME" >> $GITHUB_ENV | ||
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV | ||
|
||
- name: Typing | ||
uses: pre-commit/[email protected] | ||
with: | ||
extra_args: --hook-stage manual --all-files | ||
if: ${{ steps.build.outcome == 'success' }} | ||
|
||
- name: Run docstring validation script tests | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
minimum_pre_commit_version: 2.9.2 | ||
minimum_pre_commit_version: 2.15.0 | ||
exclude: ^LICENSES/|\.(html|csv|svg)$ | ||
# reserve "manual" for mypy and pyright | ||
default_stages: [commit, merge-commit, push, prepare-commit-msg, commit-msg, post-checkout, post-commit, post-merge, post-rewrite] | ||
ci: | ||
autofix_prs: false | ||
repos: | ||
|
@@ -31,7 +33,9 @@ repos: | |
- id: debug-statements | ||
- id: end-of-file-fixer | ||
exclude: \.txt$ | ||
stages: [commit, merge-commit, push, prepare-commit-msg, commit-msg, post-checkout, post-commit, post-merge, post-rewrite] | ||
- id: trailing-whitespace | ||
stages: [commit, merge-commit, push, prepare-commit-msg, commit-msg, post-checkout, post-commit, post-merge, post-rewrite] | ||
- repo: https://github.com/cpplint/cpplint | ||
rev: 1.6.0 | ||
hooks: | ||
|
@@ -84,12 +88,22 @@ repos: | |
- id: pyright | ||
name: pyright | ||
entry: pyright | ||
# note: assumes python env is setup and activated | ||
language: node | ||
pass_filenames: false | ||
types: [python] | ||
stages: [manual] | ||
# note: keep version in sync with .github/workflows/code-checks.yml | ||
additional_dependencies: ['[email protected]'] | ||
additional_dependencies: ['[email protected]'] | ||
- repo: local | ||
hooks: | ||
- id: mypy | ||
name: mypy | ||
entry: mypy | ||
# note: assumes python env is setup and activated | ||
language: system | ||
pass_filenames: false | ||
types: [python] | ||
stages: [manual] | ||
- repo: local | ||
hooks: | ||
- id: flake8-rst | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
would it work to use the mypy hook, and add
numpy
(and whatever else is needed for types) inadditional_dependencies
? I tried this a while ago and there some were inconsistencies with how mypy runs on the whole project versus as a hook, but if we were able to get it to pass as a hook, then it'd solve a whole bunch of typing headachesI've seen a bunch of other projects do this, and it seems pretty reliable
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.
I would like that! I think the only downside is that the current pre-commit run is very fast as it doesn't need to install all the dependencies from environment.yml. I'm not familiar with pre-commit, is there a nice way of sharing the exact dependency versions (basically everything in environment.yml)?
I guess to get pyright working, we would need to use its
venv
argument to point it to pre-commit/mypy's environment (I don't think pre-commit allows installing python dependencies for a node program).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.
does it need to be everything in
environment.yml
? I would've thought that only a few packages would be necessary, likenumpy
and maybepytest
I don't think so, other than writing our own script (like the one that checks flake8 versions match)
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.
Probably almost everything: imported libraries might have type annotations (and pyright explicitly checks that it can find all imported modules).
I think I will just see what a mess it will be :) then we can decide on whether it is worth it or not
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.
😄 no worries then,
system
is fine, as long as the stage is manual (it used to not besystem
, and then there were a tonne of false-positives, and people would tend to just turn offpre-commit
)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.
Okay, let's try
system
for this PR! Two questions:manual
. By default all hooks are in all stages. Could changedefault_stages
, then we need to call pre-commit only once for mypy+pyright (might reduce some overhead). Do you think that would be helpful? If so, what value shoulddefault_stages
have?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.
It is actually not that bad listing all dependencies for mypy, see the latest commit.
The issue is to programmatically find the python env that pre-commit created for mypy so that pyright can use it as well.
While it is possible to move mypy and later move pyright, I would really like to make sure that pyright uses the same env as mypy, as pyright errors when it encounters any missing modules. It is easy to forget a module, which is then resolved as
Any
(can hide errors).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.
I thought I found an ugly way that should work on linux but it seems that pyright (and probably mypy too?) needs pandas to be compiled for some of its checks, see the error in pre-commit now.
Compiling pandas in the pre-commit is a little bit too much (more dependencies and it takes much longer). Let's go back to the
system+manual
approach.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.
@MarcoGorelli I'm mostly pattern matching when it comes to github action+pre-commit but I found a working
system+manual
version :)