Skip to content

DOC: Highlight pre-commit section #37701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/source/development/code_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ pandas code style guide
pandas follows the `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_
standard and uses `Black <https://black.readthedocs.io/en/stable/>`_
and `Flake8 <https://flake8.pycqa.org/en/latest/>`_ to ensure a
consistent code format throughout the project. For details see the
:ref:`contributing guide to pandas<contributing.code-formatting>`.
consistent code format throughout the project. We encourage you to use
:ref:`pre-commits <contributing.pre-commit>` to automatically run ``black``,
``flake8``, ``isort``, and related code checks when you make a git commit.

Patterns
========
Expand Down
85 changes: 41 additions & 44 deletions doc/source/development/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,46 @@ In addition to ``./ci/code_checks.sh``, some extra checks are run by
``pre-commit`` - see :ref:`here <contributing.pre-commit>` for how to
run them.

Additional standards are outlined on the :ref:`pandas code style guide <code_style>`
Additional standards are outlined on the :ref:`pandas code style guide <code_style>`.

.. _contributing.pre-commit:

Pre-commit
----------

You can run many of these styling checks manually as we have described above. However,
we encourage you to use `pre-commit hooks <https://pre-commit.com/>`_ instead
to automatically run ``black``, ``flake8``, ``isort`` when you make a git commit. This
can be done by installing ``pre-commit``::

pip install pre-commit

and then running::

pre-commit install

from the root of the pandas repository. Now all of the styling checks will be
run each time you commit changes without your needing to run each one manually.
In addition, using this pre-commit hook will also allow you to more easily
remain up-to-date with our code checks as they change.

Note that if needed, you can skip these checks with ``git commit --no-verify``.

If you don't want to use ``pre-commit`` as part of your workflow, you can still use it
to run its checks by running::

pre-commit run --files <files you have modified>

without having to have done ``pre-commit install`` beforehand.

.. note::

If you have conflicting installations of ``virtualenv``, then you may get an
error - see `here <https://github.com/pypa/virtualenv/issues/1875>`_.

Also, due to a `bug in virtualenv <https://github.com/pypa/virtualenv/issues/1986>`_,
you may run into issues if you're using conda. To solve this, you can downgrade
``virtualenv`` to version ``20.0.33``.

Optional dependencies
---------------------
Expand Down Expand Up @@ -712,7 +751,7 @@ Python (PEP8 / black)
pandas follows the `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ standard
and uses `Black <https://black.readthedocs.io/en/stable/>`_ and
`Flake8 <http://flake8.pycqa.org/en/latest/>`_ to ensure a consistent code
format throughout the project.
format throughout the project. We encourage you to use :ref:`pre-commits <contributing.pre-commit>`.

:ref:`Continuous Integration <contributing.ci>` will run those tools and
report any stylistic errors in your code. Therefore, it is helpful before
Expand All @@ -727,9 +766,6 @@ apply ``black`` as you edit files.
You should use a ``black`` version 20.8b1 as previous versions are not compatible
with the pandas codebase.

If you wish to run these checks automatically, we encourage you to use
:ref:`pre-commits <contributing.pre-commit>` instead.

One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this
command will catch any stylistic errors in your changes specifically, but
be beware it may not catch all of them. For example, if you delete the only
Expand Down Expand Up @@ -807,45 +843,6 @@ Where similar caveats apply if you are on OSX or Windows.

You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.

.. _contributing.pre-commit:

Pre-commit
~~~~~~~~~~

You can run many of these styling checks manually as we have described above. However,
we encourage you to use `pre-commit hooks <https://pre-commit.com/>`_ instead
to automatically run ``black``, ``flake8``, ``isort`` when you make a git commit. This
can be done by installing ``pre-commit``::

pip install pre-commit

and then running::

pre-commit install

from the root of the pandas repository. Now all of the styling checks will be
run each time you commit changes without your needing to run each one manually.
In addition, using this pre-commit hook will also allow you to more easily
remain up-to-date with our code checks as they change.

Note that if needed, you can skip these checks with ``git commit --no-verify``.

If you don't want to use ``pre-commit`` as part of your workflow, you can still use it
to run its checks by running::

pre-commit run --files <files you have modified>

without having to have done ``pre-commit install`` beforehand.

.. note::

If you have conflicting installations of ``virtualenv``, then you may get an
error - see `here <https://github.com/pypa/virtualenv/issues/1875>`_.

Also, due to a `bug in virtualenv <https://github.com/pypa/virtualenv/issues/1986>`_,
you may run into issues if you're using conda. To solve this, you can downgrade
``virtualenv`` to version ``20.0.33``.

Backwards compatibility
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down