Skip to content

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

Merged
merged 11 commits into from
Sep 22, 2020
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ repos:
rev: 19.10b0
hooks:
- id: black
language_version: python3
Copy link
Member Author

Choose a reason for hiding this comment

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

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
language: python_venv
Copy link
Member Author

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

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

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.

rev: v5.2.2
- repo: https://github.com/PyCQA/isort
rev: 5.2.2
hooks:
- id: isort
language: python_venv
Copy link
Member Author

Choose a reason for hiding this comment

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

exclude: ^pandas/__init__\.py$|^pandas/core/api\.py$
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
hooks:
- id: pyupgrade
args: [--py37-plus]
11 changes: 11 additions & 0 deletions doc/source/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ do not make sudden changes to the code that could have the potential to break
a lot of user code as a result, that is, we need it to be as *backwards compatible*
as possible to avoid mass breakages.

In addition to ``./ci/code_checks.sh``, some extra checks are run by
``pre-commit`` - see :ref:`here <contributing.pre-commit>` for how to
run them.

Additional standards are outlined on the :ref:`pandas code style guide <code_style>`

Optional dependencies
Expand Down Expand Up @@ -826,6 +830,13 @@ remain up-to-date with our code checks as they change.

Note that if needed, you can skip these checks with ``git commit --no-verify``.

If you don't want to use ``pre-commit`` as part of your workflow, you can still use it
to run its checks by running::

pre-commit run --files <files you have modified>

without having to have done ``pre-commit install`` beforehand.

Backwards compatibility
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion doc/sphinxext/announce.py
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

Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ dependencies:
- flake8-rst>=0.6.0,<=0.7.0 # linting of code blocks in rst files
- isort>=5.2.1 # check that imports are in the right order
- mypy=0.782
- pre-commit
- pycodestyle # used by flake8
- pyupgrade

# documentation
- gitpython # obtain contributors from git for whatsnew
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ flake8-comprehensions>=3.1.0
flake8-rst>=0.6.0,<=0.7.0
isort>=5.2.1
mypy==0.782
pre-commit
pycodestyle
pyupgrade
gitpython
gitdb
sphinx
Expand Down