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

Style: enforce import ordering with isort (YTEP0037 1/6) #2592

Merged
merged 7 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ detail. Why is this change required? What problem does it solve?-->

<!-- Note that some of these check boxes may not apply to all pull requests -->

- [ ] Code passes flake8 checker
- [ ] pass `flake8 yt/`
- [ ] pass `isort -rc . --check-only`
- [ ] New features are documented, with docstrings and narrative docs
- [ ] Adds a test for any bugs fixed. Adds tests for new features.

Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ jobs:
python: 3.6
script: flake8 yt/

- stage: Lint
python: 3.6
script: isort --check-only -rc yt/

- stage: tests
name: "Python: 3.6 Minimal Dependency Unit Tests"
python: 3.6
Expand Down
21 changes: 21 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,27 @@ error and warning list
blacklist a large number of the full list of rules that are checked by
``flake8`` by default.

Import Formatting
-----------------

We use ``isort`` to enforce PEP-8 guidelines for import ordering.
By decreasing priority order:
FUTURE > STDLIB > THIRD PARTY > FIRST PARTY > EXPLICITLY LOCAL

``isort`` can be installed via ``pip``

.. code-block:: bash

$ pip install isort

To validate import order, run ``isort`` recursively at the top level

.. code-block:: bash

$ isort -rc . --check-only

If any error is detected, rerun this without the ``--check-only`` flag to fix them.

Source code style guide
-----------------------

Expand Down
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ exclude = doc,benchmarks,*/api.py,*/__init__.py,*/__config__.py,yt/visualization
max-line-length=999
ignore = E111,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E202,E211,E221,E222,E227,E228,E241,E301,E203,E225,E226,E231,E251,E261,E262,E265,E266,E302,E303,E305,E306,E402,E502,E701,E703,E722,E741,E731,W291,W292,W293,W391,W503,W504,W605
jobs=8

# To be kept consistent with "Import Formatting" section in CONTRIBUTING.rst
[tool:isort]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
line_length=88
# isort can't be applied to yt/__init__.py because it creates circular imports
skip = venv, doc, benchmarks, yt/__init__.py, yt/extern
known_third_party = IPython, nose, numpy, sympy, matplotlib, unyt, git, yaml, dateutil, requests, coverage, pytest
known_first_party = yt
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
3 changes: 2 additions & 1 deletion tests/lint_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
flake8==3.6.0
mccabe==0.6.1
pycodestyle==2.4.0
pyflakes==2.0.0
pyflakes==2.0.0
isort==4.3
2 changes: 1 addition & 1 deletion yt/exthook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
:license: BSD, see LICENSE for more details.
"""
# This source code was originally in flask/exthook.py
import sys
import os
import sys


class ExtensionImporter:
Expand Down
3 changes: 1 addition & 2 deletions yt/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import numpy as np
import itertools
import base64
import numpy
import matplotlib
import getpass
import glob
Expand Down Expand Up @@ -652,7 +651,7 @@ def get_yt_version():
def get_version_stack():
version_info = {}
version_info['yt'] = get_yt_version()
version_info['numpy'] = numpy.version.version
version_info['numpy'] = np.version.version
version_info['matplotlib'] = matplotlib.__version__
return version_info

Expand Down
12 changes: 6 additions & 6 deletions yt/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
# we import this in a weird way from numpy.testing to avoid triggering
# flake8 errors from the unused imports. These test functions are imported
# elsewhere in yt from here so we want them to be imported here.
from numpy.testing import assert_array_equal, assert_almost_equal # NOQA
from numpy.testing import assert_approx_equal, assert_array_almost_equal # NOQA
from numpy.testing import assert_equal, assert_array_less # NOQA
from numpy.testing import assert_string_equal # NOQA
from numpy.testing import assert_array_almost_equal_nulp # NOQA
from numpy.testing import assert_allclose, assert_raises # NOQA
from numpy.testing import assert_array_equal, assert_almost_equal # NOQA isort:skip
from numpy.testing import assert_approx_equal, assert_array_almost_equal # NOQA isort:skip
from numpy.testing import assert_equal, assert_array_less # NOQA isort:skip
from numpy.testing import assert_string_equal # NOQA isort:skip
from numpy.testing import assert_array_almost_equal_nulp # NOQA isort:skip
from numpy.testing import assert_allclose, assert_raises # NOQA isort:skip
from numpy.random import RandomState
from yt.convenience import load
from yt.units.yt_array import YTArray, YTQuantity
Expand Down