-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 4 commits
8197c61
1a6b477
e8135b4
f4788fa
27e285e
1e5bc80
9c98406
635b8d7
e2a334a
b8aea46
5b6faa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: pre-commit | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [master] | ||
dsaxton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: pre-commit/[email protected] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,30 @@ repos: | |
rev: 19.10b0 | ||
hooks: | ||
- id: black | ||
language_version: python3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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/
|
||
additional_dependencies: [flake8-comprehensions>=3.1.0] | ||
- id: flake8 | ||
name: flake8-pyx | ||
language: python_venv | ||
files: \.(pyx|pxd)$ | ||
types: | ||
- file | ||
args: [--append-config=flake8/cython.cfg] | ||
- id: flake8 | ||
name: flake8-pxd | ||
language: python_venv | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. this is deprecated, see https://github.com/pre-commit/mirrors-isort
|
||
rev: v5.2.2 | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.2.2 | ||
hooks: | ||
- id: isort | ||
language: python_venv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
exclude: ^pandas/__init__\.py$|^pandas/core/api\.py$ | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v2.7.2 | ||
hooks: | ||
- id: pyupgrade | ||
args: [--py37-plus] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,38 +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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe reason will be displayed to describe this comment to others. Learn more. Sure - have added the ci/code checks back in for now then
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
black --version | ||
|
||
MSG='Checking black formatting' ; echo $MSG | ||
black . --check | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
|
||
# `setup.cfg` contains the list of error codes that are being ignored in flake8 | ||
|
||
echo "flake8 --version" | ||
flake8 --version | ||
|
||
# pandas/_libs/src is C code, so no need to search there. | ||
MSG='Linting .py code' ; echo $MSG | ||
flake8 --format="$FLAKE8_FORMAT" . | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
|
||
MSG='Linting .pyx and .pxd code' ; echo $MSG | ||
flake8 --format="$FLAKE8_FORMAT" pandas --append-config=flake8/cython.cfg | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
|
||
MSG='Linting .pxi.in' ; echo $MSG | ||
flake8 --format="$FLAKE8_FORMAT" pandas/_libs --append-config=flake8/cython-template.cfg | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
|
||
echo "flake8-rst --version" | ||
flake8-rst --version | ||
|
||
MSG='Linting code-blocks in .rst documentation' ; echo $MSG | ||
flake8-rst doc/source --filename=*.rst --format="$FLAKE8_FORMAT" | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`; | ||
# it doesn't make a difference, but we want to be internally consistent. | ||
# Note: this grep pattern is (intended to be) equivalent to the python | ||
|
@@ -132,19 +100,6 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then | |
fi | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
|
||
echo "isort --version-number" | ||
isort --version-number | ||
|
||
# Imports - Check formatting using isort see setup.cfg for settings | ||
MSG='Check import format using isort' ; echo $MSG | ||
ISORT_CMD="isort --quiet --check-only pandas asv_bench scripts web" | ||
if [[ "$GITHUB_ACTIONS" == "true" ]]; then | ||
eval $ISORT_CMD | awk '{print "##[error]" $0}'; RET=$(($RET + ${PIPESTATUS[0]})) | ||
else | ||
eval $ISORT_CMD | ||
fi | ||
RET=$(($RET + $?)) ; echo $MSG "DONE" | ||
|
||
fi | ||
|
||
### PATTERNS ### | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# -*- encoding:utf-8 -*- | ||
""" | ||
Script to generate contributor and pull request lists | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.