-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update contributing guidelines for black #27233
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
- [ ] closes #xxxx | ||
- [ ] tests added / passed | ||
- [ ] passes `black pandas` | ||
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff` | ||
- [ ] whatsnew entry |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
repos: | ||
- repo: https://github.com/python/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
language_version: python3.7 | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomAugspurger do you know if there is a difference taking flake8 from its own repo or from the pre-commit-hooks repo? |
||
rev: 3.7.7 | ||
hooks: | ||
- id: flake8 | ||
language: python_venv | ||
- repo: https://github.com/pre-commit/mirrors-isort | ||
rev: v4.3.20 | ||
hooks: | ||
- id: isort | ||
language: python_venv |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -562,23 +562,38 @@ many errors as possible, but it may not correct *all* of them. Thus, it is | |
recommended that you run ``cpplint`` to double check and make any other style | ||
fixes manually. | ||
|
||
Python (PEP8) | ||
~~~~~~~~~~~~~ | ||
|
||
*pandas* uses the `PEP8 <http://www.python.org/dev/peps/pep-0008/>`_ standard. | ||
There are several tools to ensure you abide by this standard. Here are *some* of | ||
the more common ``PEP8`` issues: | ||
Python (PEP8 / black) | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
* we restrict line-length to 79 characters to promote readability | ||
* passing arguments should have spaces after commas, e.g. ``foo(arg1, arg2, kw1='bar')`` | ||
*pandas* follows the `PEP8 <http://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. | ||
|
||
:ref:`Continuous Integration <contributing.ci>` will run | ||
the `flake8 <https://pypi.org/project/flake8>`_ tool | ||
and report any stylistic errors in your code. Therefore, it is helpful before | ||
submitting code to run the check yourself on the diff:: | ||
:ref:`Continuous Integration <contributing.ci>` will run those tools and | ||
report any stylistic errors in your code. Therefore, it is helpful before | ||
submitting code to run the check yourself:: | ||
|
||
black pandas | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
git diff upstream/master -u -- "*.py" | flake8 --diff | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
to auto-format your code. Additionally, many editors have plugins that will | ||
apply ``black`` as you edit files. | ||
|
||
Optionally, you may wish to setup `pre-commit hooks <https://pre-commit.com/>`_ | ||
to automatically run ``black`` and ``flake8`` when you make a git commit. This | ||
can be done by installing ``pre-commit``:: | ||
|
||
pip install pre-commit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the conda-forge package is pre_commit (that's a bit an annoying name difference ..) |
||
|
||
and then running:: | ||
|
||
pre-commit install | ||
|
||
from the root of the pandas repository. Now ``black`` and ``flake8`` will be run | ||
each time you commit changes. You can skip these checks with | ||
``git commit --no-verify``. | ||
|
||
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 | ||
usage of an imported function, it is stylistically incorrect to import an | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what should we be recommending here? Still keep both flake8 and black?
The problem with this version of the black command is also that it does the full code base and takes a while
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make black is pretty fast currently so i would just have this