@@ -656,27 +656,13 @@ apply ``black`` as you edit files.
656
656
You should use a ``black `` version >= 19.10b0 as previous versions are not compatible
657
657
with the pandas codebase.
658
658
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
-
673
659
One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff ``: this
674
660
command will catch any stylistic errors in your changes specifically, but
675
661
be beware it may not catch all of them. For example, if you delete the only
676
662
usage of an imported function, it is stylistically incorrect to import an
677
663
unused function. However, style-checking the diff will not catch this because
678
664
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::
680
666
681
667
git diff upstream/master --name-only -- "*.py" | xargs -r flake8
682
668
@@ -694,6 +680,8 @@ behaviour as follows::
694
680
This will get all the files being changed by the PR (and ending with ``.py ``),
695
681
and run ``flake8 `` on them, one after the other.
696
682
683
+ Note that these commands can be run analogously with ``black ``.
684
+
697
685
.. _contributing.import-formatting :
698
686
699
687
Import formatting
@@ -716,7 +704,6 @@ A summary of our current import sections ( in order ):
716
704
717
705
Imports are alphabetically sorted within these sections.
718
706
719
-
720
707
As part of :ref: `Continuous Integration <contributing.ci >` checks we run::
721
708
722
709
isort --recursive --check-only pandas
@@ -740,8 +727,35 @@ to automatically format imports correctly. This will modify your local copy of t
740
727
741
728
The `--recursive ` flag can be passed to sort all files in a directory.
742
729
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
+
743
736
You can then verify the changes look ok, then git :ref: `commit <contributing.commit-code >` and :ref: `push <contributing.push-code >`.
744
737
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
+
745
759
Backwards compatibility
746
760
~~~~~~~~~~~~~~~~~~~~~~~
747
761
0 commit comments