Skip to content

Commit b01b99b

Browse files
committed
DOC: Encourage use of pre-commit in the docs
Previously, we stated it as merely optional.
1 parent 371b79e commit b01b99b

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

doc/source/development/contributing.rst

+30-16
Original file line numberDiff line numberDiff line change
@@ -656,27 +656,13 @@ apply ``black`` as you edit files.
656656
You should use a ``black`` version >= 19.10b0 as previous versions are not compatible
657657
with the pandas codebase.
658658

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``.
672-
673659
One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this
674660
command will catch any stylistic errors in your changes specifically, but
675661
be beware it may not catch all of them. For example, if you delete the only
676662
usage of an imported function, it is stylistically incorrect to import an
677663
unused function. However, style-checking the diff will not catch this because
678664
the actual import is not part of the diff. Thus, for completeness, you should
679-
run this command, though it will take longer::
665+
run this command, though it may take longer::
680666

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

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

683+
Note that these commands can be run analogously with ``black``.
684+
697685
.. _contributing.import-formatting:
698686

699687
Import formatting
@@ -716,7 +704,6 @@ A summary of our current import sections ( in order ):
716704

717705
Imports are alphabetically sorted within these sections.
718706

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

722709
isort --recursive --check-only pandas
@@ -740,8 +727,35 @@ to automatically format imports correctly. This will modify your local copy of t
740727

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

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

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

0 commit comments

Comments
 (0)