Skip to content

Commit d1b9598

Browse files
authored
DOC: Encourage use of pre-commit in the docs (#30864)
Previously, we stated it as merely optional xref: #30773 #30814
1 parent 6f2c509 commit d1b9598

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

doc/source/development/contributing.rst

+36-15
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ many errors as possible, but it may not correct *all* of them. Thus, it is
635635
recommended that you run ``cpplint`` to double check and make any other style
636636
fixes manually.
637637

638+
.. _contributing.code-formatting:
639+
638640
Python (PEP8 / black)
639641
~~~~~~~~~~~~~~~~~~~~~
640642

@@ -656,27 +658,16 @@ apply ``black`` as you edit files.
656658
You should use a ``black`` version >= 19.10b0 as previous versions are not compatible
657659
with the pandas codebase.
658660

659-
Optionally, you may wish to setup `pre-commit hooks <https://pre-commit.com/>`_
660-
to automatically run ``black`` and ``flake8`` when you make a git commit. This
661-
can be done by installing ``pre-commit``::
662-
663-
pip install pre-commit
664-
665-
and then running::
666-
667-
pre-commit install
668-
669-
from the root of the pandas repository. Now ``black`` and ``flake8`` will be run
670-
each time you commit changes. You can skip these checks with
671-
``git commit --no-verify``.
661+
If you wish to run these checks automatically, we encourage you to use
662+
:ref:`pre-commits <contributing.pre-commit>` instead.
672663

673664
One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this
674665
command will catch any stylistic errors in your changes specifically, but
675666
be beware it may not catch all of them. For example, if you delete the only
676667
usage of an imported function, it is stylistically incorrect to import an
677668
unused function. However, style-checking the diff will not catch this because
678669
the actual import is not part of the diff. Thus, for completeness, you should
679-
run this command, though it will take longer::
670+
run this command, though it may take longer::
680671

681672
git diff upstream/master --name-only -- "*.py" | xargs -r flake8
682673

@@ -694,6 +685,8 @@ behaviour as follows::
694685
This will get all the files being changed by the PR (and ending with ``.py``),
695686
and run ``flake8`` on them, one after the other.
696687

688+
Note that these commands can be run analogously with ``black``.
689+
697690
.. _contributing.import-formatting:
698691

699692
Import formatting
@@ -716,7 +709,6 @@ A summary of our current import sections ( in order ):
716709

717710
Imports are alphabetically sorted within these sections.
718711

719-
720712
As part of :ref:`Continuous Integration <contributing.ci>` checks we run::
721713

722714
isort --recursive --check-only pandas
@@ -740,8 +732,37 @@ to automatically format imports correctly. This will modify your local copy of t
740732

741733
The `--recursive` flag can be passed to sort all files in a directory.
742734

735+
Alternatively, you can run a command similar to what was suggested for ``black`` and ``flake8`` :ref:`right above <contributing.code-formatting>`::
736+
737+
git diff upstream/master --name-only -- "*.py" | xargs -r isort
738+
739+
Where similar caveats apply if you are on OSX or Windows.
740+
743741
You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.
744742

743+
.. _contributing.pre-commit:
744+
745+
Pre-Commit
746+
~~~~~~~~~~
747+
748+
You can run many of these styling checks manually as we have described above. However,
749+
we encourage you to use `pre-commit hooks <https://pre-commit.com/>`_ instead
750+
to automatically run ``black``, ``flake8``, ``isort`` when you make a git commit. This
751+
can be done by installing ``pre-commit``::
752+
753+
pip install pre-commit
754+
755+
and then running::
756+
757+
pre-commit install
758+
759+
from the root of the pandas repository. Now all of the styling checks will be
760+
run each time you commit changes without your needing to run each one manually.
761+
In addition, using this pre-commit hook will also allow you to more easily
762+
remain up-to-date with our code checks as they change.
763+
764+
Note that if needed, you can skip these checks with ``git commit --no-verify``.
765+
745766
Backwards compatibility
746767
~~~~~~~~~~~~~~~~~~~~~~~
747768

0 commit comments

Comments
 (0)