Skip to content
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

Black #3142

Merged
merged 15 commits into from
Aug 8, 2019
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

- [ ] Closes #xxxx
- [ ] Tests added
- [ ] Passes `black .` & `flake8`
- [ ] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://pre-commit.com/
# https://github.com/python/black#version-control-integration
repos:
- repo: https://github.com/python/black
rev: stable
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
- id: flake8
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ xarray: N-D labeled arrays and datasets
:target: https://pandas.pydata.org/speed/xarray/
.. image:: https://img.shields.io/pypi/v/xarray.svg
:target: https://pypi.python.org/pypi/xarray/
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/python/black


**xarray** (formerly **xray**) is an open source project and Python package
that makes working with labelled multi-dimensional arrays simple,
Expand Down
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ jobs:
displayName: Install flake8
- bash: flake8
displayName: flake8 lint checks
- bash: python -m pip install black
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
displayName: Install black
- bash: black .
displayName: black formatting check

- job: TypeChecking
variables:
Expand Down
39 changes: 26 additions & 13 deletions doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -340,23 +340,24 @@ do not make sudden changes to the code that could have the potential to break
a lot of user code as a result, that is, we need it to be as *backwards compatible*
as possible to avoid mass breakages.

Python (PEP8)
~~~~~~~~~~~~~
Code Formatting
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
~~~~~~~~~~~~~~~

*xarray* 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:
Xarray 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. ``black`` and ``flake8`` can be installed with
``pip``::

- we restrict line-length to 79 characters to promote readability
- passing arguments should have spaces after commas, e.g. ``foo(arg1, arg2, kw1='bar')``
pip install black flake8

:ref:`Continuous Integration <contributing.ci>` will run
the `flake8 <http://flake8.pycqa.org/en/latest/>`_ tool
and report any stylistic errors in your code. Therefore, it is helpful before
submitting code to run the check yourself:
and then run from the root of the Xarray repository::

black .
flake8

to auto-format your code. Additionally, many editors have plugins that will
apply ``black`` as you edit files.

Other recommended but optional tools for checking code quality (not currently
enforced in CI):

Expand All @@ -367,8 +368,20 @@ enforced in CI):
incorrectly sorted imports. ``isort -y`` will automatically fix them. See
also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.

Note that your code editor probably supports extensions that can show results
of these checks inline as you type.
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

and then running::

pre-commit install

from the root of the Xarray repository. Now ``black`` and ``flake8`` will be run
each time you commit changes. You can skip these checks with
``git commit --no-verify``.


Backwards Compatibility
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
10 changes: 6 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ markers =
slow: slow tests

[flake8]
max-line-length=79
max-line-length=88
ignore=
E402
E731
Expand All @@ -28,9 +28,11 @@ exclude=
doc

[isort]
default_section=THIRDPARTY
known_first_party=xarray
multi_line_output=4
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88

# Most of the numerical computing stack doesn't have type annotations yet.
[mypy-affine.*]
Expand Down