@@ -635,6 +635,8 @@ many errors as possible, but it may not correct *all* of them. Thus, it is
635
635
recommended that you run ``cpplint `` to double check and make any other style
636
636
fixes manually.
637
637
638
+ .. _contributing.code-formatting :
639
+
638
640
Python (PEP8 / black)
639
641
~~~~~~~~~~~~~~~~~~~~~
640
642
@@ -656,27 +658,16 @@ apply ``black`` as you edit files.
656
658
You should use a ``black `` version >= 19.10b0 as previous versions are not compatible
657
659
with the pandas codebase.
658
660
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.
672
663
673
664
One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff ``: this
674
665
command will catch any stylistic errors in your changes specifically, but
675
666
be beware it may not catch all of them. For example, if you delete the only
676
667
usage of an imported function, it is stylistically incorrect to import an
677
668
unused function. However, style-checking the diff will not catch this because
678
669
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::
680
671
681
672
git diff upstream/master --name-only -- "*.py" | xargs -r flake8
682
673
@@ -694,6 +685,8 @@ behaviour as follows::
694
685
This will get all the files being changed by the PR (and ending with ``.py ``),
695
686
and run ``flake8 `` on them, one after the other.
696
687
688
+ Note that these commands can be run analogously with ``black ``.
689
+
697
690
.. _contributing.import-formatting :
698
691
699
692
Import formatting
@@ -716,7 +709,6 @@ A summary of our current import sections ( in order ):
716
709
717
710
Imports are alphabetically sorted within these sections.
718
711
719
-
720
712
As part of :ref: `Continuous Integration <contributing.ci >` checks we run::
721
713
722
714
isort --recursive --check-only pandas
@@ -740,8 +732,37 @@ to automatically format imports correctly. This will modify your local copy of t
740
732
741
733
The `--recursive ` flag can be passed to sort all files in a directory.
742
734
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
+
743
741
You can then verify the changes look ok, then git :ref: `commit <contributing.commit-code >` and :ref: `push <contributing.push-code >`.
744
742
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
+
745
766
Backwards compatibility
746
767
~~~~~~~~~~~~~~~~~~~~~~~
747
768
0 commit comments