Skip to content

Commit 20dd7dc

Browse files
crusaderkydcherian
authored andcommitted
Add isort to CI (#3721)
* Add isort to CI * Run isort before black * Run isort before black * What's new * Run isort before black * DEMO: deliberate isort failure * Fix isort failure
1 parent b350561 commit 20dd7dc

10 files changed

+42
-25
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
- [ ] Closes #xxxx
44
- [ ] Tests added
5-
- [ ] Passes `black . && mypy . && flake8`
5+
- [ ] Passes `isort -rc . && black . && mypy . && && flake8`
66
- [ ] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# https://pre-commit.com/
2-
# https://github.com/python/black#version-control-integration
32
repos:
3+
# isort should run before black as black sometimes tweaks the isort output
4+
- repo: https://github.com/timothycrosley/isort
5+
rev: 4.3.21-2
6+
hooks:
7+
- id: isort
8+
# https://github.com/python/black#version-control-integration
49
- repo: https://github.com/python/black
510
rev: stable
611
hooks:
@@ -14,7 +19,7 @@ repos:
1419
rev: v0.761 # Must match ci/requirements/*.yml
1520
hooks:
1621
- id: mypy
17-
# run these occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
22+
# run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
1823
# - repo: https://github.com/asottile/pyupgrade
1924
# rev: v1.22.1
2025
# hooks:
@@ -23,7 +28,3 @@ repos:
2328
# - "--py3-only"
2429
# # remove on f-strings in Py3.7
2530
# - "--keep-percent-format"
26-
# - repo: https://github.com/timothycrosley/isort
27-
# rev: 4.3.21-2
28-
# hooks:
29-
# - id: isort

azure-pipelines.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ jobs:
8484
mypy .
8585
displayName: mypy type checks
8686
87+
- job: isort
88+
variables:
89+
conda_env: py37
90+
pool:
91+
vmImage: 'ubuntu-16.04'
92+
steps:
93+
- template: ci/azure/install.yml
94+
- bash: |
95+
source activate xarray-tests
96+
isort -rc --check .
97+
displayName: isort formatting checks
98+
8799
- job: MinimumVersionsPolicy
88100
pool:
89101
vmImage: 'ubuntu-16.04'

ci/min_deps_check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"coveralls",
1616
"flake8",
1717
"hypothesis",
18+
"isort",
1819
"mypy",
1920
"pip",
2021
"pytest",

ci/requirements/py36-min-all-deps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
- hdf5=1.10
2424
- hypothesis
2525
- iris=2.2
26+
- isort
2627
- lxml=4.4 # Optional dep of pydap
2728
- matplotlib=3.1
2829
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py36.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22+
- isort
2223
- lxml # optional dep of pydap
2324
- matplotlib
2425
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py37-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22+
- isort
2223
- lxml # Optional dep of pydap
2324
- matplotlib
2425
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py37.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22+
- isort
2223
- lxml # Optional dep of pydap
2324
- matplotlib
2425
- mypy=0.761 # Must match .pre-commit-config.yaml

doc/contributing.rst

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,33 +345,31 @@ as possible to avoid mass breakages.
345345
Code Formatting
346346
~~~~~~~~~~~~~~~
347347

348-
Xarray uses `Black <https://black.readthedocs.io/en/stable/>`_ and
349-
`Flake8 <http://flake8.pycqa.org/en/latest/>`_ to ensure a consistent code
350-
format throughout the project. ``black`` and ``flake8`` can be installed with
348+
xarray uses several tools to ensure a consistent code format throughout the project:
349+
350+
- `Black <https://black.readthedocs.io/en/stable/>`_ for standardized code formatting
351+
- `Flake8 <http://flake8.pycqa.org/en/latest/>`_ for general code quality
352+
- `isort <https://github.com/timothycrosley/isort>`_ for standardized order in imports.
353+
See also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.
354+
- `mypy <http://mypy-lang.org/>`_ for static type checking on `type hints
355+
<https://docs.python.org/3/library/typing.html>`_
356+
351357
``pip``::
352358

353-
pip install black flake8
359+
pip install black flake8 isort mypy
354360

355361
and then run from the root of the Xarray repository::
356362

357-
black .
363+
isort -rc .
364+
black -t py36 .
358365
flake8
366+
mypy .
359367

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

363-
Other recommended but optional tools for checking code quality (not currently
364-
enforced in CI):
365-
366-
- `mypy <http://mypy-lang.org/>`_ performs static type checking, which can
367-
make it easier to catch bugs. Please run ``mypy xarray`` if you annotate any
368-
code with `type hints <https://docs.python.org/3/library/typing.html>`_.
369-
- `isort <https://github.com/timothycrosley/isort>`_ will highlight
370-
incorrectly sorted imports. ``isort -y`` will automatically fix them. See
371-
also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.
372-
373371
Optionally, you may wish to setup `pre-commit hooks <https://pre-commit.com/>`_
374-
to automatically run ``black`` and ``flake8`` when you make a git commit. This
372+
to automatically run all the above tools every time you make a git commit. This
375373
can be done by installing ``pre-commit``::
376374

377375
pip install pre-commit
@@ -380,8 +378,7 @@ and then running::
380378

381379
pre-commit install
382380

383-
from the root of the Xarray repository. Now ``black`` and ``flake8`` will be run
384-
each time you commit changes. You can skip these checks with
381+
from the root of the xarray repository. You can skip the pre-commit checks with
385382
``git commit --no-verify``.
386383

387384
.. note::

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Internal Changes
157157
- Replaced versioneer with setuptools-scm. Moved contents of setup.py to setup.cfg.
158158
Removed pytest-runner from setup.py, as per deprecation notice on the pytest-runner
159159
project. (:pull:`3714`) by `Guido Imperiale <https://github.com/crusaderky>`_
160+
- Use of isort is now enforced by CI.
161+
(:pull:`3721`) by `Guido Imperiale <https://github.com/crusaderky>`_
160162

161163

162164
v0.14.1 (19 Nov 2019)

0 commit comments

Comments
 (0)