Skip to content

Commit 65e123c

Browse files
jorisvandenbosschejreback
authored andcommitted
DOC: update contributing guidelines for black (pandas-dev#27233)
* DOC: update contributing guidelines for black * add pre-commit-config file * update pre-commit hook for pandas * correct name for config file
1 parent 845d4b8 commit 65e123c

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- [ ] closes #xxxx
22
- [ ] tests added / passed
3+
- [ ] passes `black pandas`
34
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
45
- [ ] whatsnew entry

.pre-commit-config.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/python/black
3+
rev: stable
4+
hooks:
5+
- id: black
6+
language_version: python3.7
7+
- repo: https://gitlab.com/pycqa/flake8
8+
rev: 3.7.7
9+
hooks:
10+
- id: flake8
11+
language: python_venv
12+
- repo: https://github.com/pre-commit/mirrors-isort
13+
rev: v4.3.20
14+
hooks:
15+
- id: isort
16+
language: python_venv

doc/source/development/contributing.rst

+27-12
Original file line numberDiff line numberDiff line change
@@ -562,23 +562,38 @@ many errors as possible, but it may not correct *all* of them. Thus, it is
562562
recommended that you run ``cpplint`` to double check and make any other style
563563
fixes manually.
564564

565-
Python (PEP8)
566-
~~~~~~~~~~~~~
567-
568-
*pandas* uses the `PEP8 <http://www.python.org/dev/peps/pep-0008/>`_ standard.
569-
There are several tools to ensure you abide by this standard. Here are *some* of
570-
the more common ``PEP8`` issues:
565+
Python (PEP8 / black)
566+
~~~~~~~~~~~~~~~~~~~~~
571567

572-
* we restrict line-length to 79 characters to promote readability
573-
* passing arguments should have spaces after commas, e.g. ``foo(arg1, arg2, kw1='bar')``
568+
*pandas* follows the `PEP8 <http://www.python.org/dev/peps/pep-0008/>`_ standard
569+
and uses `Black <https://black.readthedocs.io/en/stable/>`_ and
570+
`Flake8 <http://flake8.pycqa.org/en/latest/>`_ to ensure a consistent code
571+
format throughout the project.
574572

575-
:ref:`Continuous Integration <contributing.ci>` will run
576-
the `flake8 <https://pypi.org/project/flake8>`_ tool
577-
and report any stylistic errors in your code. Therefore, it is helpful before
578-
submitting code to run the check yourself on the diff::
573+
:ref:`Continuous Integration <contributing.ci>` will run those tools and
574+
report any stylistic errors in your code. Therefore, it is helpful before
575+
submitting code to run the check yourself::
579576

577+
black pandas
580578
git diff upstream/master -u -- "*.py" | flake8 --diff
581579

580+
to auto-format your code. Additionally, many editors have plugins that will
581+
apply ``black`` as you edit files.
582+
583+
Optionally, you may wish to setup `pre-commit hooks <https://pre-commit.com/>`_
584+
to automatically run ``black`` and ``flake8`` when you make a git commit. This
585+
can be done by installing ``pre-commit``::
586+
587+
pip install pre-commit
588+
589+
and then running::
590+
591+
pre-commit install
592+
593+
from the root of the pandas repository. Now ``black`` and ``flake8`` will be run
594+
each time you commit changes. You can skip these checks with
595+
``git commit --no-verify``.
596+
582597
This command will catch any stylistic errors in your changes specifically, but
583598
be beware it may not catch all of them. For example, if you delete the only
584599
usage of an imported function, it is stylistically incorrect to import an

0 commit comments

Comments
 (0)