Skip to content

Commit

Permalink
Use flake8 (#93)
Browse files Browse the repository at this point in the history
* Require flake8 be installed on CI

* Require `flake8` and `pytest-flake8` for testing

As the tests make use of flake8 (specifically a pytest plugin for
flake8), require `flake8` and `pytest-flake8`.

* Ensure flake8 is run with pytest

Uses the flake8 plugin for pytest to ensure that flake8 checks are run
as part of pytest.

* Exclude versioneer and docs from flake8

* Drop unused external imports caught by flake8

These imports were probably used for code that no longer needs them. So
go ahead and drop these unused imports.

* Wrap long warning line

Running flake8 picked out this line as too long. This wraps it some to
try and fix this issue.

* Break up warning string across multiple lines

To fit the 79 character limit constraint, split this warning into two
strings on two lines that are concatenated.

* Drop some internal unused imports

Some internal imports are unused according to flake8. So we drop them
here to fix these flake8 errors.

* Avoid flake8 unused import error

To workaround flake8 unused import errors where we know these functions
are imported and used elsewhere, go ahead and perform trivial
assignments to make use of these functions. This still passes the tests
and removes the flake8 errors.

* Reorder imports in ndfilters

Make sure that all imports in `ndfilters` happen before other statements
to fix flake8 errors.

* Ignore `lambda` assignment with flake8

We are not really interested in flake8's `lambda` assignment rule in
these cases. So simply tell flake8 to ignore these lines.

* Adjust line wrapping of `lambda`

Removes the need for the `\`, which seems to be causing issues with
`flake8`.

* Disable the flake8 lambda assignment on both lines

For some reason disabling this flake8 error on the second line is not
sufficient. So disable it on the first lines as well.

* Drop flake8 noqa from second `lambda` line

This `noqa` seems to have no effect. So just drop it to avoid having
these in excess.

* Remove whitespace before `:` for flake8

* Have flake8 ignore `lambda` assignment

* Wrap parameterized arguments

As flake8 complains the line length is too long here, wrap these
arguments to fit them within the recommended line length.

* Wrap test parameterized arguments

To fit the recommended line length, wrap the test function's
parameterized arguments.

* Ignore `lambda` assignment with flake8

We are not really interested in flake8's `lambda` assignment rule in
these cases. So simply tell flake8 to ignore these lines.

* Wrap parameterized arguments

As flake8 complains the line length is too long here, wrap these
arguments to fit them within the recommended line length.

* Wrap parameterized arguments

As flake8 complains the line length is too long here, wrap these
arguments to fit them within the recommended line length.

* Ignore `lambda` assignment with flake8

We are not really interested in flake8's `lambda` assignment rule in
these cases. So simply tell flake8 to ignore these lines.

* Trim whitespace before `:` in `lambda` for flake8

* Ignore `lambda` assignment with flake8

We are not really interested in flake8's `lambda` assignment rule in
these cases. So simply tell flake8 to ignore these lines.

* Drop extra blank line

* Compare `str`s with `==`s instead of `is`

* Drop unused import

As the `operator` module is not being used in this test module, drop it
from the imports.

* Allow a couple of long lines

These are a little annoying to wrap currently. So simply tell flake8 to
not worry about these.

* Require flake8 and pytest plugin on Python 3.5

As Python 3.5 is not supported in conda-forge any more, this uses the
slightly older versions of packages that work with Python 3.5 in order
to run the flake8 tests there as well.

* Switch to `[tool:pytest]` in `setup.cfg`

As the `[pytest]` section in `setup.cfg` seems to be deprecated and
raises errors when used with newer pytest versions, switch to using
`[tool:pytest]` instead. This seems to work ok even with old versions of
pytest used with Python 3.5.

* Cleanup SciPy check in `test_fourier_filter_type`

As flake8 did not like how this line was formatted, we simplify it a bit
and adjust the indentation to make it happier.

* Cleanup SciPy check in `test_measure_props`

As flake8 did not like how this line was formatted, we simplify it a bit
and adjust the indentation to make it happier.
  • Loading branch information
jakirkham authored Feb 2, 2019
1 parent c367172 commit d5bac99
Show file tree
Hide file tree
Showing 35 changed files with 119 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .appveyor_support/environments/tst_py27.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.7.2
- pytest==3.8.2
- pytest-flake8==1.0.4
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .appveyor_support/environments/tst_py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.5.0
- pytest==3.8.1
- pytest-flake8==1.0.1
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .appveyor_support/environments/tst_py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.7.2
- pytest==3.8.2
- pytest-flake8==1.0.4
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .appveyor_support/environments/tst_py37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==19.0.1
- wheel==0.32.3
- coverage==4.5.2
- flake8==3.7.2
- pytest==4.2.0
- pytest-flake8==1.0.4
- dask==1.1.1
- numpy==1.15.4
- scipy==1.2.0
Expand Down
2 changes: 2 additions & 0 deletions .circleci/environments/tst_py27.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.7.2
- pytest==3.8.2
- pytest-flake8==1.0.4
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .circleci/environments/tst_py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.5.0
- pytest==3.8.1
- pytest-flake8==1.0.1
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .circleci/environments/tst_py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.7.2
- pytest==3.8.2
- pytest-flake8==1.0.4
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .circleci/environments/tst_py37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==19.0.1
- wheel==0.32.3
- coverage==4.5.2
- flake8==3.7.2
- pytest==4.2.0
- pytest-flake8==1.0.4
- dask==1.1.1
- numpy==1.16.0
- scipy==1.2.0
Expand Down
2 changes: 2 additions & 0 deletions .travis_support/environments/tst_py27.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.7.2
- pytest==3.8.2
- pytest-flake8==1.0.4
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .travis_support/environments/tst_py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.5.0
- pytest==3.8.1
- pytest-flake8==1.0.1
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .travis_support/environments/tst_py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==18.0
- wheel==0.31.1
- coverage==4.5.1
- flake8==3.7.2
- pytest==3.8.2
- pytest-flake8==1.0.4
- dask==0.16.1
- numpy==1.11.3
- scipy==1.1.0
Expand Down
2 changes: 2 additions & 0 deletions .travis_support/environments/tst_py37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ dependencies:
- pip==19.0.1
- wheel==0.32.3
- coverage==4.5.2
- flake8==3.7.2
- pytest==4.2.0
- pytest-flake8==1.0.4
- dask==1.1.1
- numpy==1.16.0
- scipy==1.2.0
Expand Down
37 changes: 20 additions & 17 deletions dask_image/ndfilters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,25 @@
convolve,
correlate,
)
convolve.__module__ = __name__
correlate.__module__ = __name__

from ._diff import (
laplace,
)
laplace.__module__ = __name__


from ._edge import (
prewitt,
sobel,
)
prewitt.__module__ = __name__
sobel.__module__ = __name__


from ._gaussian import (
gaussian_filter,
gaussian_gradient_magnitude,
gaussian_laplace,
)
gaussian_filter.__module__ = __name__
gaussian_gradient_magnitude.__module__ = __name__
gaussian_laplace.__module__ = __name__


from ._generic import (
generic_filter,
)
generic_filter.__module__ = __name__


from ._order import (
minimum_filter,
Expand All @@ -48,14 +35,30 @@
rank_filter,
percentile_filter,
)

from ._smooth import (
uniform_filter,
)


convolve.__module__ = __name__
correlate.__module__ = __name__

laplace.__module__ = __name__

prewitt.__module__ = __name__
sobel.__module__ = __name__

gaussian_filter.__module__ = __name__
gaussian_gradient_magnitude.__module__ = __name__
gaussian_laplace.__module__ = __name__

generic_filter.__module__ = __name__

minimum_filter.__module__ = __name__
median_filter.__module__ = __name__
maximum_filter.__module__ = __name__
rank_filter.__module__ = __name__
percentile_filter.__module__ = __name__


from ._smooth import (
uniform_filter,
)
uniform_filter.__module__ = __name__
2 changes: 0 additions & 2 deletions dask_image/ndfilters/_diff.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-


import numbers

import scipy.ndimage.filters

from . import _utils
Expand Down
3 changes: 0 additions & 3 deletions dask_image/ndfilters/_generic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-


import numbers

import numpy
import scipy.ndimage.filters

from . import _utils
Expand Down
3 changes: 0 additions & 3 deletions dask_image/ndfilters/_order.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-


import numbers

import numpy
import scipy.ndimage.filters

from . import _utils
Expand Down
6 changes: 3 additions & 3 deletions dask_image/ndfilters/_smooth.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-


import numbers

import numpy
import scipy.ndimage.filters

from . import _utils
from ._gaussian import gaussian_filter


gaussian_filter = gaussian_filter


@_utils._update_wrapper(scipy.ndimage.filters.uniform_filter)
def uniform_filter(input,
size=3,
Expand Down
10 changes: 5 additions & 5 deletions dask_image/ndfilters/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

import numpy

from .._pycompat import imap, irange, izip, strlike, unicode
from .._pycompat import irange, izip, strlike


def _get_docstring(func):
# Drop the output parameter from the docstring.
split_doc_params = lambda s: \
re.subn("( [A-Za-z]+ : )", "\0\\1", s)[0].split("\0")
drop_doc_param = lambda s: not s.startswith(" output : ")
split_doc_params = lambda s: re.subn( # noqa: E731
"( [A-Za-z]+ : )", "\0\\1", s)[0].split("\0")
drop_doc_param = lambda s: not s.startswith(" output : ") # noqa: E731
func_doc = "" if func.__doc__ is None else func.__doc__
cleaned_docstring = "".join([
l for l in split_doc_params(func_doc) if drop_doc_param(l)
Expand Down Expand Up @@ -87,7 +87,7 @@ def _get_depth_boundary(ndim, depth, boundary=None):
if not isinstance(boundary, collections.Mapping):
raise TypeError("Unexpected type for `boundary`.")

type_check = lambda b: (b is None) or isinstance(b, strlike)
type_check = lambda b: (b is None) or isinstance(b, strlike) # noqa: E731
if not all(map(type_check, boundary.values())):
raise TypeError("Expected string-like values for `boundary`.")

Expand Down
3 changes: 1 addition & 2 deletions dask_image/ndfourier/_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-


import itertools
import numbers

import numpy

import dask.array

from .._pycompat import imap, irange, izip
from .._pycompat import izip


def _get_freq_grid(shape, chunks, dtype=float):
Expand Down
6 changes: 5 additions & 1 deletion dask_image/ndmeasure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ def label(input, structure=None):
input = dask.array.asarray(input)

if not all([len(c) == 1 for c in input.chunks]):
warn("``input`` does not have 1 chunk in all dimensions; it will be consolidated first", RuntimeWarning)
warn(
"``input`` does not have 1 chunk in all dimensions; "
"it will be consolidated first",
RuntimeWarning
)

label_func = dask.delayed(scipy.ndimage.label, nout=2)
label, num_features = label_func(input, structure)
Expand Down
3 changes: 0 additions & 3 deletions dask_image/ndmeasure/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

from __future__ import division

import operator
import warnings

import numpy

import dask
import dask.array

from .. import _pycompat


def _norm_input_labels_index(input, labels=None, index=None):
"""
Expand Down
2 changes: 0 additions & 2 deletions dask_image/ndmorph/_ops.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-


import numpy

import dask.array

from . import _utils
Expand Down
10 changes: 6 additions & 4 deletions dask_image/ndmorph/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
import dask.array

from ..ndfilters._utils import (
_get_docstring,
_update_wrapper,
_get_depth_boundary,
_get_size,
_get_origin,
_get_depth,
_get_footprint
_get_depth
)

_update_wrapper = _update_wrapper
_get_depth_boundary = _get_depth_boundary
_get_origin = _get_origin
_get_depth = _get_depth


def _get_structure(input, structure):
# Create square connectivity as default
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ parentdir_prefix = dask-image
universal = 1

[flake8]
exclude = docs
exclude = docs/conf.py,versioneer.py

[tool:pytest]
addopts = --flake8
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def run_tests(self):
]

test_requirements = [
"flake8 >=3.4.1",
"pytest >=3.0.5",
"pytest-flake8 >=0.8.1",
"scikit-image >=0.12.3",
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_dask_image/test__pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_irange():


def test_imap():
r = dask_image._pycompat.imap(lambda e : e ** 2, [0, 1, 2, 3])
r = dask_image._pycompat.imap(lambda e: e ** 2, [0, 1, 2, 3])

assert not isinstance(r, list)

Expand Down
Loading

0 comments on commit d5bac99

Please sign in to comment.