Skip to content

Commit 3429ca2

Browse files
max-sixtyshoyer
authored andcommitted
Use flake8 rather than pycodestyle (pydata#3010)
* A few flake fixes * isort * bunch of flake8 errors fixed * flake8 config * pep8speaks config * run flake8 in travis * docs to flake8 * pep8speaks configs inherited from setup.cfg * too much isort, skipped base __init__ * imports * install flake8 in travis * update 3.6 reqs
1 parent fda6056 commit 3429ca2

Some content is hidden

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

47 files changed

+116
-134
lines changed

.pep8speaks.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
# File : .pep8speaks.yml
2-
3-
# This should be kept in sync with the duplicate config in the [pycodestyle]
4-
# block of setup.cfg.
1+
# https://github.com/OrkoHunter/pep8speaks for more info
2+
# pep8speaks will use the flake8 configs in `setup.cfg`
53

64
scanner:
7-
diff_only: False # If True, errors caused by only the patch are shown
8-
9-
pycodestyle:
10-
max-line-length: 79
11-
ignore: # Errors and warnings to ignore
12-
- E402 # module level import not at top of file
13-
- E731 # do not assign a lambda expression, use a def
14-
- E741 # ambiguous variable name
15-
- W503 # line break before binary operator
16-
- W504 # line break after binary operator
5+
diff_only: False
6+
linter: flake8

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ script:
6060
cd doc;
6161
sphinx-build -n -j auto -b html -d _build/doctrees . _build/html;
6262
elif [[ "$CONDA_ENV" == "lint" ]]; then
63-
pycodestyle xarray ;
63+
flake8 ;
6464
elif [[ "$CONDA_ENV" == "py36-hypothesis" ]]; then
6565
pytest properties ;
6666
else

asv_bench/benchmarks/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from __future__ import absolute_import
2-
from __future__ import division
3-
from __future__ import print_function
1+
from __future__ import absolute_import, division, print_function
2+
43
import itertools
54

65
import numpy as np

ci/requirements-py36.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- pytest-cov
1515
- pytest-env
1616
- coveralls
17-
- pycodestyle
17+
- flake8
1818
- numpy>=1.12
1919
- pandas>=0.19
2020
- scipy

ci/requirements-py37.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- pytest-cov
1616
- pytest-env
1717
- coveralls
18-
- pycodestyle
18+
- flake8
1919
- numpy>=1.12
2020
- pandas>=0.19
2121
- scipy

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# serve to show the default.
1414
from __future__ import absolute_import, division, print_function
1515

16-
from contextlib import suppress
1716
import datetime
1817
import os
1918
import subprocess
2019
import sys
20+
from contextlib import suppress
2121

2222
import xarray
2323

doc/contributing.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,20 +351,18 @@ the more common ``PEP8`` issues:
351351
- passing arguments should have spaces after commas, e.g. ``foo(arg1, arg2, kw1='bar')``
352352

353353
:ref:`Continuous Integration <contributing.ci>` will run
354-
the `pycodestyle <http://pypi.python.org/pypi/pycodestyle>`_ tool
354+
the `flake8 <http://flake8.pycqa.org/en/latest/>`_ tool
355355
and report any stylistic errors in your code. Therefore, it is helpful before
356-
submitting code to run the check yourself::
356+
submitting code to run the check yourself:
357357

358-
pycodestyle xarray
358+
flake8
359359

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

363363
- `mypy <http://mypy-lang.org/>`_ performs static type checking, which can
364364
make it easier to catch bugs. Please run ``mypy xarray`` if you annotate any
365365
code with `type hints <https://docs.python.org/3/library/typing.html>`_.
366-
- `flake8 <http://pypi.python.org/pypi/flake8>`_ includes a few more automated
367-
checks than those enforced by pycodestyle.
368366
- `isort <https://github.com/timothycrosley/isort>`_ will highlight
369367
incorrectly sorted imports. ``isort -y`` will automatically fix them. See
370368
also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.

doc/examples/_code/weather_data_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import pandas as pd
3-
import seaborn as sns # pandas aware plotting library
3+
import seaborn as sns # noqa, pandas aware plotting library
44

55
import xarray as xr
66

setup.cfg

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ env =
1111
UVCDAT_ANONYMOUS_LOG=no
1212

1313
# This should be kept in sync with .pep8speaks.yml
14-
[pycodestyle]
14+
[flake8]
1515
max-line-length=79
16-
ignore=E402,E731,E741,W503,W504
16+
ignore=
17+
E402
18+
E731
19+
E741
20+
W503
21+
W504
22+
# Unused imports; TODO: Allow typing to work without triggering errors
23+
F401
24+
exclude=
25+
doc
1726

1827
[isort]
1928
default_section=THIRDPARTY

xarray/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
""" isort:skip_file """
12
# flake8: noqa
23

34
from ._version import get_versions

xarray/backends/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
DataStores provide a uniform interface for saving and loading data in different
44
formats. They should not be used directly, but rather through Dataset objects.
55
"""
6-
from .common import AbstractDataStore
7-
from .file_manager import FileManager, CachingFileManager, DummyFileManager
86
from .cfgrib_ import CfGribDataStore
7+
from .common import AbstractDataStore
8+
from .file_manager import CachingFileManager, DummyFileManager, FileManager
9+
from .h5netcdf_ import H5NetCDFStore
910
from .memory import InMemoryDataStore
1011
from .netCDF4_ import NetCDF4DataStore
12+
from .pseudonetcdf_ import PseudoNetCDFDataStore
1113
from .pydap_ import PydapDataStore
1214
from .pynio_ import NioDataStore
1315
from .scipy_ import ScipyDataStore
14-
from .h5netcdf_ import H5NetCDFStore
15-
from .pseudonetcdf_ import PseudoNetCDFDataStore
1616
from .zarr import ZarrStore
1717

1818
__all__ = [

xarray/backends/file_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import contextlib
22
import threading
3-
from typing import Any, Dict
43
import warnings
4+
from typing import Any, Dict
55

66
from ..core import utils
77
from ..core.options import OPTIONS

xarray/backends/locks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import multiprocessing
22
import threading
3-
from typing import Any, MutableMapping
43
import weakref
4+
from typing import Any, MutableMapping
55

66
try:
77
from dask.utils import SerializableLock

xarray/backends/netCDF4_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _force_native_endianness(var):
174174
# if endian exists, remove it from the encoding.
175175
var.encoding.pop('endian', None)
176176
# check to see if encoding has a value for endian its 'native'
177-
if not var.encoding.get('endian', 'native') is 'native':
177+
if not var.encoding.get('endian', 'native') == 'native':
178178
raise NotImplementedError("Attempt to write non-native endian type, "
179179
"this is not supported by the netCDF4 "
180180
"python library.")
@@ -237,6 +237,7 @@ def _extract_nc4_variable_encoding(variable, raise_on_invalid=False,
237237

238238
class GroupWrapper:
239239
"""Wrap netCDF4.Group objects so closing them closes the root group."""
240+
240241
def __init__(self, value):
241242
self.value = value
242243

xarray/coding/variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Coders for individual Variable objects."""
2-
from typing import Any
32
import warnings
43
from functools import partial
4+
from typing import Any
55

66
import numpy as np
77
import pandas as pd

xarray/core/accessor_str.py

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

4646
from .computation import apply_ufunc
4747

48-
4948
_cpython_optimized_encoders = (
5049
"utf-8", "utf8", "latin-1", "latin1", "iso-8859-1", "mbcs", "ascii"
5150
)

xarray/core/alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
import pandas as pd
1010

11-
from . import utils, dtypes
11+
from . import dtypes, utils
1212
from .indexing import get_indexer_nd
1313
from .utils import is_dict_like, is_full_slice
1414
from .variable import IndexVariable, Variable

xarray/core/combine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import pandas as pd
66

7-
from . import utils, dtypes
7+
from . import dtypes, utils
88
from .alignment import align
9+
from .computation import result_name
910
from .merge import merge
1011
from .variable import IndexVariable, Variable, as_variable
1112
from .variable import concat as concat_vars
12-
from .computation import result_name
1313

1414

1515
def concat(objs, dim=None, data_vars='all', coords='different',

xarray/core/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from collections import OrderedDict
22
from contextlib import suppress
33
from textwrap import dedent
4-
from typing import (Any, Callable, Hashable, Iterable, Iterator, List, Mapping,
5-
MutableMapping, Optional, Tuple, TypeVar, Union)
4+
from typing import (
5+
Any, Callable, Hashable, Iterable, Iterator, List, Mapping, MutableMapping,
6+
Optional, Tuple, TypeVar, Union)
67

78
import numpy as np
89
import pandas as pd
@@ -13,7 +14,6 @@
1314
from .pycompat import dask_array_type
1415
from .utils import Frozen, ReprObject, SortedKeysDict, either_dict_or_kwargs
1516

16-
1717
# Used as a sentinel value to indicate a all dimensions
1818
ALL_DIMS = ReprObject('<all-dims>')
1919

xarray/core/dataset.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from distutils.version import LooseVersion
99
from numbers import Number
1010
from typing import (
11-
Any, Callable, Dict, List, Optional, Set, Tuple, TypeVar, Union, Sequence)
11+
Any, Callable, Dict, List, Optional, Sequence, Set, Tuple, TypeVar, Union)
1212

1313
import numpy as np
1414
import pandas as pd
@@ -35,8 +35,7 @@
3535
from .pycompat import TYPE_CHECKING, dask_array_type
3636
from .utils import (
3737
Frozen, SortedKeysDict, _check_inplace, decode_numpy_dict_values,
38-
either_dict_or_kwargs, ensure_us_time_resolution, hashable, is_dict_like,
39-
maybe_wrap_array)
38+
either_dict_or_kwargs, hashable, maybe_wrap_array)
4039
from .variable import IndexVariable, Variable, as_variable, broadcast_variables
4140

4241
if TYPE_CHECKING:
@@ -4145,7 +4144,7 @@ def _integrate_one(self, coord, datetime_unit=None):
41454144
from .variable import Variable
41464145

41474146
if coord not in self.variables and coord not in self.dims:
4148-
raise ValueError('Coordinate {} does not exist.'.format(dim))
4147+
raise ValueError('Coordinate {} does not exist.'.format(coord))
41494148

41504149
coord_var = self[coord].variable
41514150
if coord_var.ndim != 1:

xarray/core/duck_array_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
accept or return xarray objects.
55
"""
66
import contextlib
7-
from functools import partial
87
import inspect
98
import warnings
9+
from functools import partial
1010

1111
import numpy as np
1212
import pandas as pd

xarray/core/missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import utils
1010
from .common import _contains_datetime_like_objects
1111
from .computation import apply_ufunc
12-
from .duck_array_ops import dask_array_type, datetime_to_numeric
12+
from .duck_array_ops import dask_array_type
1313
from .utils import OrderedSet, is_scalar
1414
from .variable import Variable, broadcast_variables
1515

xarray/core/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _warn_on_setting_enable_cftimeindex(enable_cftimeindex):
5959
def _get_keep_attrs(default):
6060
global_choice = OPTIONS['keep_attrs']
6161

62-
if global_choice is 'default':
62+
if global_choice == 'default':
6363
return default
6464
elif global_choice in [True, False]:
6565
return global_choice

xarray/core/resample_cftime.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@
3636
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3737
# POSSIBILITY OF SUCH DAMAGE.
3838

39-
from ..coding.cftimeindex import CFTimeIndex
40-
from ..coding.cftime_offsets import (cftime_range, normalize_date,
41-
Day, MonthEnd, QuarterEnd, YearEnd,
42-
CFTIME_TICKS, to_offset)
4339
import datetime
40+
4441
import numpy as np
4542
import pandas as pd
4643

44+
from ..coding.cftime_offsets import (
45+
CFTIME_TICKS, Day, MonthEnd, QuarterEnd, YearEnd, cftime_range,
46+
normalize_date, to_offset)
47+
from ..coding.cftimeindex import CFTimeIndex
48+
4749

4850
class CFTimeGrouper:
4951
"""This is a simple container for the grouping parameters that implements a

xarray/core/rolling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from . import dtypes, duck_array_ops, utils
88
from .dask_array_ops import dask_rolling_wrapper
99
from .ops import (
10-
bn, has_bottleneck, inject_coarsen_methods,
11-
inject_bottleneck_rolling_methods, inject_datasetrolling_methods)
10+
bn, has_bottleneck, inject_bottleneck_rolling_methods,
11+
inject_coarsen_methods, inject_datasetrolling_methods)
1212
from .pycompat import dask_array_type
1313

1414

xarray/core/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
import re
88
import warnings
99
from collections import OrderedDict
10-
from typing import (AbstractSet, Any, Callable, Container, Dict, Hashable,
11-
Iterable, Iterator, Optional, Sequence,
12-
Tuple, TypeVar, cast)
10+
from typing import (
11+
AbstractSet, Any, Callable, Container, Dict, Hashable, Iterable, Iterator,
12+
Mapping, MutableMapping, MutableSet, Optional, Sequence, Tuple, TypeVar,
13+
cast)
1314

1415
import numpy as np
1516
import pandas as pd
1617

1718
from .pycompat import dask_array_type
1819

19-
from typing import Mapping, MutableMapping, MutableSet
2020
try: # Fix typed collections in Python 3.5.0~3.5.2
2121
from .pycompat import Mapping, MutableMapping, MutableSet # noqa: F811
2222
except ImportError:

xarray/plot/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from .plot import (plot, line, step, contourf, contour,
2-
hist, imshow, pcolormesh)
3-
41
from .facetgrid import FacetGrid
2+
from .plot import contour, contourf, hist, imshow, line, pcolormesh, plot, step
53

64
__all__ = [
75
'plot',

xarray/plot/facetgrid.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import functools
22
import itertools
33
import warnings
4-
from inspect import getfullargspec
54

65
import numpy as np
76

87
from ..core.formatting import format_item
98
from .utils import (
10-
_infer_xy_labels, _process_cmap_cbar_kwargs,
11-
import_matplotlib_pyplot, label_from_attrs)
9+
_infer_xy_labels, _process_cmap_cbar_kwargs, import_matplotlib_pyplot,
10+
label_from_attrs)
1211

1312
# Overrides axes.labelsize, xtick.major.size, ytick.major.size
1413
# from mpl.rcParams
@@ -483,7 +482,7 @@ def map(self, func, *args, **kwargs):
483482
# TODO: better way to verify that an artist is mappable?
484483
# https://stackoverflow.com/questions/33023036/is-it-possible-to-detect-if-a-matplotlib-artist-is-a-mappable-suitable-for-use-w#33023522
485484
if (maybe_mappable and
486-
hasattr(maybe_mappable, 'autoscale_None')):
485+
hasattr(maybe_mappable, 'autoscale_None')):
487486
self._mappables.append(maybe_mappable)
488487

489488
self._finalize_grid(*args[:2])

0 commit comments

Comments
 (0)