-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CI: add pre-commit action, include pyupgrade #36471
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
CI: add pre-commit action, include pyupgrade #36471
Conversation
@@ -3,23 +3,19 @@ repos: | |||
rev: 19.10b0 | |||
hooks: | |||
- id: black | |||
language_version: python3 |
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.
This is already specified here: https://github.com/psf/black/blob/master/.pre-commit-hooks.yaml
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.8.3 | ||
hooks: | ||
- id: flake8 | ||
language: python_venv |
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.
Same, they already specify this here https://gitlab.com/pycqa/flake8/-/blob/master/.pre-commit-hooks.yaml
and according to pre-commit docs https://pre-commit.com/
The python_venv language is now an alias to python
files: \.pxi\.in$ | ||
types: | ||
- file | ||
args: [--append-config=flake8/cython-template.cfg] | ||
- repo: https://github.com/pre-commit/mirrors-isort |
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.
this is deprecated, see https://github.com/pre-commit/mirrors-isort
This mirror repository is deprecated, use isort directly.
hooks: | ||
- id: isort | ||
language: python_venv |
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.
already specified in https://github.com/PyCQA/isort/blob/develop/.pre-commit-hooks.yaml
Might need to rework the code_check docs if we do this: https://pandas.pydata.org/docs/development/contributing.html#code-standards |
ci/code_checks.sh
Outdated
@@ -48,31 +48,6 @@ fi | |||
### LINTING ### | |||
if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then | |||
|
|||
echo "black --version" |
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.
how are these no longer needed?
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.
They're run during the pre-commit CI check, see https://github.com/pandas-dev/pandas/pull/36471/checks?check_run_id=1137265216 . Could always duplicate them just in case if you like
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.
but do we run the pre-commit checks on CI? i think have a script that is separate from the pre-commit is needed as well (it can duplicate or be called by pre-commit), but key is to have everything in sync.
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.
Two cents: I think keeping this for a time just to ensure it never disagrees with pre-commit makes sense, then can remove later once we're fairly sure they're identical (also makes it easier to revert if misconfigured)
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.
but do we run the pre-commit checks on CI?
That's what this PR adds - if you go down to "All checks have passed" and expand, you'll see an extra GitHub Action called "pre-commit". If you expand that one further, it says
Run pre-commit/[email protected]
install pre-commit
Cache Size: ~21 MB (21895398 B)
/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/f09139a0-b8b5-427f-bc76-10b2403b8816/cache.tzst -P -C /home/runner/work/pandas/pandas
/opt/hostedtoolcache/Python/3.8.5/x64/bin/pre-commit run --show-diff-on-failure --color=always --all-files
black....................................................................Passed
flake8...................................................................Passed
flake8-pyx...............................................................Passed
flake8-pxd...............................................................Passed
isort....................................................................Passed
pyupgrade................................................................Passed
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.
Two cents: I think keeping this for a time just to ensure it never disagrees with pre-commit makes sense, then can remove later once we're fairly sure they're identical (also makes it easier to revert if misconfigured)
This seems like a good approach! Also would be good to check that github actions CI fails if any of these pre commit stages doesn’t pass.
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.
Sure - have added the ci/code checks back in for now then
Also would be good to check that github actions CI fails if any of these pre commit stages doesn’t pass.
From my experience using this in my own repo (https://github.com/nbQA-dev/nbQA) that's what happens
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.
Should we open an issue to remember to deduplicate these checks 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.
sure
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. Happy to have these run in both code_checks and the pre-commit GH Action for a bit to make sure things are working properly. |
@MarcoGorelli should pyupgrade be added to environment.yml? |
Not necessary, as pre-commit runs it a separate environment and that's the only place here pyupgrade is being used https://github.com/pandas-dev/pandas/pull/36471/checks?check_run_id=1143999007 shows:
|
pre-commit for the contributor is optional. (https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#pre-commit) so as a reviewer, what's the process to recommend if a pyupgrade failure occurs. advise the contributor to install pyupgrade or does the output of the failed job tell you what needs to be done? |
That's a really good point, and yes - it'll show you the diff, e.g. see here https://github.com/pymc-devs/pymc3/runs/1121338004 for an example from PyMC3, which shows: nbqa-isort...............................................................Failed
- hook id: nbqa
- files were modified by this hook
Fixing /home/runner/work/pymc3/pymc3/docs/source/notebooks/GLM-logistic.ipynb
pre-commit hook(s) made changes.
If you are seeing this message in CI, reproduce locally with: `pre-commit run --all-files`.
To run `pre-commit` as part of git workflow, use `pre-commit install`.
All changes made by hooks:
diff --git a/docs/source/notebooks/GLM-logistic.ipynb b/docs/source/notebooks/GLM-logistic.ipynb
index 96c9d11..71d53e8 100644
--- a/docs/source/notebooks/GLM-logistic.ipynb
+++ b/docs/source/notebooks/GLM-logistic.ipynb
@@ -29,6 +29,9 @@
}
],
"source": [
+ "from collections import OrderedDict\n",
+ "from time import time\n",
+ "\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
@@ -37,10 +40,8 @@
"import theano as thno\n",
"import theano.tensor as T\n",
"\n",
- "from collections import OrderedDict\n",
"from scipy import integrate\n",
"from scipy.optimize import fmin_powell\n",
- "from time import time\n",
"\n",
"print(\"Running on PyMC3 v{}\".format(pm.__version__))"
]
##[error]The process '/opt/hostedtoolcache/Python/3.8.5/x64/bin/pre-commit' failed with exit code 1 |
Since all the other development tools (e.g., testing, typing and linting) are in environment.yml I think adding it makes sense, especially if it's also in CI (would probably minimize friction later when errors do occur). Thoughts @MarcoGorelli ? |
Makes sense - have added that an pre-commit (since its the recommended way to run pyupgrade) |
AFAIK pre-commit doesn't run out-of-the-box on Windows after using you get
so I think additional instructions/link to relevant docs could be included to lower the barrier to entry for new contributors. |
🤔 I have it working on my Windows laptop for work, pretty sure all I did was The docs already link to the pre-commit website https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#pre-commit , do you think more should be added (in terms of installation instructions)? |
using but creating a clean environment from environment.yml (from this PR)
moving pre-commit to the pip section and creating a new environment from that seems to work out-the-box.
of course, this comparison is not very well controlled without caches etc being cleared and the first environment installing pre-commit using conda now works as well.
and I'm can't remember what I did in the past to get pre-commit to work in conda environments that may have affected my settings/configuration. so maybe just leave as is and see if any other contributors report issues. |
Cool, thanks for the detailed report |
thanks @MarcoGorelli lgtm. @TomAugspurger @simonjayhawkins if ok pls merge. |
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.
lgtm.
Thanks! |
xref this comment #36426 (comment) by @TomAugspurger
So, this PR does that.
It also adds pyupgrade as a pre-commit hook (xref #36450 ) and removes some unnecessary configurations from the
.pre-commit-config.yaml
file (all of these hooks already specifylanguage: python
, see e.g. https://github.com/psf/black/blob/master/.pre-commit-hooks.yaml )TODO
update https://pandas.pydata.org/docs/development/contributing.html#code-standards (thanks Ali!)