Skip to content

Commit 278e4e3

Browse files
authored
Add isort to sort imports alphabetically (#745)
1 parent 6c7a673 commit 278e4e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+105
-141
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Install packages
3434
run: |
35-
pip install black blackdoc flake8 pylint
35+
pip install black blackdoc flake8 pylint isort
3636
sudo apt-get install dos2unix
3737
3838
- name: Formatting check (black and flake8)

.github/workflows/format-command.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
# Install formatting tools
2727
- name: Install formatting tools
2828
run: |
29-
pip install black blackdoc flake8
29+
pip install black blackdoc flake8 isort
3030
sudo apt-get install dos2unix
3131
3232
# Run "make format" and commit the change to the PR branch

CONTRIBUTING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ directory).
245245

246246
### Code style
247247

248-
We use [Black](https://github.com/ambv/black) and [blackdoc](https://github.com/keewis/blackdoc)
248+
We use some tools:
249+
250+
- [Black](https://github.com/ambv/black)
251+
- [blackdoc](https://github.com/keewis/blackdoc)
252+
- [isort](https://pycqa.github.io/isort/)
253+
249254
to format the code so we don't have to think about it.
250255
Black loosely follows the [PEP8](http://pep8.org) guide but with a few differences.
251256
Regardless, you won't have to worry about formatting the code yourself.
@@ -268,7 +273,7 @@ common errors.
268273
The [`Makefile`](Makefile) contains rules for running both checks:
269274

270275
```bash
271-
make check # Runs flake8, black and blackdoc (in check mode)
276+
make check # Runs flake8, black, blackdoc and isort (in check mode)
272277
make lint # Runs pylint, which is a bit slower
273278
```
274279

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ help:
1515
@echo " install install in editable mode"
1616
@echo " test run the test suite (including doctests) and report coverage"
1717
@echo " format run black and blackdoc to automatically format the code"
18-
@echo " check run code style and quality checks (black, blackdoc and flake8)"
18+
@echo " check run code style and quality checks (black, blackdoc, isort and flake8)"
1919
@echo " lint run pylint for a deeper (and slower) quality check"
2020
@echo " clean clean up build and generated files"
2121
@echo " distclean clean up build and generated files, including project metadata files"
@@ -36,10 +36,12 @@ test:
3636
rm -r $(TESTDIR)
3737

3838
format:
39+
isort .
3940
black $(BLACK_FILES)
4041
blackdoc $(BLACKDOC_OPTIONS) $(BLACK_FILES)
4142

4243
check:
44+
isort . --check
4345
black --check $(BLACK_FILES)
4446
blackdoc --check $(BLACKDOC_OPTIONS) $(BLACK_FILES)
4547
flake8 $(FLAKE8_FILES)

doc/conf.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
# pylint: disable=invalid-name
66

77
import datetime
8+
9+
# isort: off
810
from sphinx_gallery.sorting import ( # pylint: disable=no-name-in-module
9-
FileNameSortKey,
1011
ExplicitOrder,
12+
FileNameSortKey,
1113
)
12-
from pygmt import __version__, __commit__
14+
from pygmt import __commit__, __version__
1315
from pygmt.sphinx_gallery import PyGMTScraper
1416

17+
# isort: on
1518

1619
extensions = [
1720
"sphinx.ext.autodoc",

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies:
2020
- coverage[toml]
2121
- black
2222
- blackdoc
23+
- isort>=5
2324
- pylint
2425
- flake8
2526
- sphinx

examples/gallery/grid/grdview_surface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
45° with ``shading="+a45"``.
1313
"""
1414

15-
import pygmt
1615
import numpy as np
16+
import pygmt
1717
import xarray as xr
1818

1919

examples/tutorials/plot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import pygmt
1313

14-
1514
########################################################################################
1615
# For example, let's load the sample dataset of tsunami generating earthquakes around
1716
# Japan (:func:`pygmt.datasets.load_japan_quakes`). The data is loaded as a

examples/tutorials/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
import os
10+
1011
import pygmt
1112

1213
###############################################################################

pygmt/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
from pkg_resources import get_distribution
1313

1414
# Import modules to make the high-level GMT Python API
15-
from pygmt.session_management import begin as _begin, end as _end
15+
from pygmt import datasets
1616
from pygmt.figure import Figure
1717
from pygmt.filtering import blockmedian
1818
from pygmt.gridding import surface
19-
from pygmt.sampling import grdtrack
20-
from pygmt.mathops import makecpt
21-
from pygmt.modules import GMTDataArrayAccessor, config, info, grdinfo, which
2219
from pygmt.gridops import grdcut, grdfilter
23-
from pygmt.x2sys import x2sys_init, x2sys_cross
24-
from pygmt import datasets
20+
from pygmt.mathops import makecpt
21+
from pygmt.modules import GMTDataArrayAccessor, config, grdinfo, info, which
22+
from pygmt.sampling import grdtrack
23+
from pygmt.session_management import begin as _begin
24+
from pygmt.session_management import end as _end
25+
from pygmt.x2sys import x2sys_cross, x2sys_init
2526

2627
# Get semantic version through setuptools-scm
2728
__version__ = f'v{get_distribution("pygmt").version}' # e.g. v0.1.2.dev3+g0ab3cd78
@@ -60,10 +61,10 @@ def show_versions():
6061
- GMT library information
6162
"""
6263

63-
import sys
64-
import platform
6564
import importlib
65+
import platform
6666
import subprocess
67+
import sys
6768

6869
def _get_module_version(modname):
6970
"""Get version information of a Python module."""

0 commit comments

Comments
 (0)