Skip to content

Commit d39626e

Browse files
committed
Merge pull request #402 from bcipolli/flake8-in-travis
STY/TST: Flake8 in travis
2 parents 5970787 + 54ef609 commit d39626e

File tree

123 files changed

+1844
-1701
lines changed

Some content is hidden

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

123 files changed

+1844
-1701
lines changed

.travis.yml

+27-15
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ matrix:
5757
- python: 2.7
5858
env:
5959
- INSTALL_TYPE=requirements
60+
- python: 2.7
61+
env:
62+
- STYLE=1
63+
- python: 3.5
64+
env:
65+
- STYLE=1
6066
before_install:
6167
- source tools/travis_tools.sh
6268
- virtualenv --python=python venv
6369
- source venv/bin/activate
6470
- python --version # just to check
65-
- pip install -U pip # upgrade to latest pip to find 3.5 wheels
66-
- retry pip install nose # always
71+
- pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
72+
- retry pip install nose flake8 # always
6773
- wheelhouse_pip_install $DEPENDS
6874
# pydicom <= 0.9.8 doesn't install on python 3
6975
- if [ "${TRAVIS_PYTHON_VERSION:0:1}" == "2" ]; then
@@ -98,20 +104,26 @@ install:
98104
- export NIBABEL_DATA_DIR="$PWD/nibabel-data"
99105
# command to run tests, e.g. python setup.py test
100106
script:
101-
# Change into an innocuous directory and find tests from installation
102-
- mkdir for_testing
103-
- cd for_testing
104-
- if [ "${COVERAGE}" == "1" ]; then
105-
cp ../.coveragerc .;
106-
COVER_ARGS="--with-coverage --cover-package nibabel";
107-
fi
108-
- if [ "$DOC_DOC_TEST" == "1" ]; then
109-
pip install sphinx numpydoc texext;
110-
cd ../doc;
111-
make html;
112-
make doctest;
107+
- |
108+
if [ "${STYLE}" == "1" ]; then
109+
# Run styles only on core nibabel code.
110+
flake8 nibabel
113111
else
114-
nosetests --with-doctest $COVER_ARGS nibabel;
112+
# Change into an innocuous directory and find tests from installation
113+
mkdir for_testing
114+
cd for_testing
115+
if [ "${COVERAGE}" == "1" ]; then
116+
cp ../.coveragerc .;
117+
COVER_ARGS="--with-coverage --cover-package nibabel";
118+
fi
119+
if [ "$DOC_DOC_TEST" == "1" ]; then
120+
pip install sphinx numpydoc texext;
121+
cd ../doc;
122+
make html;
123+
make doctest;
124+
else
125+
nosetests --with-doctest $COVER_ARGS nibabel;
126+
fi
115127
fi
116128
after_success:
117129
- if [ "${COVERAGE}" == "1" ]; then coveralls; fi

nibabel/affines.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def from_matvec(matrix, vector=None):
166166
t = np.zeros((nin + 1, nout + 1), matrix.dtype)
167167
t[0:nin, 0:nout] = matrix
168168
t[nin, nout] = 1.
169-
if not vector is None:
169+
if vector is not None:
170170
t[0:nin, nout] = vector
171171
return t
172172

@@ -214,7 +214,7 @@ def append_diag(aff, steps, starts=()):
214214
starts = np.zeros(n_steps, dtype=steps.dtype)
215215
elif len(starts) != n_steps:
216216
raise ValueError('Steps should have same length as starts')
217-
old_n_out, old_n_in = aff.shape[0]-1, aff.shape[1]-1
217+
old_n_out, old_n_in = aff.shape[0] - 1, aff.shape[1] - 1
218218
# make new affine
219219
aff_plus = np.zeros((old_n_out + n_steps + 1,
220220
old_n_in + n_steps + 1), dtype=aff.dtype)
@@ -223,7 +223,7 @@ def append_diag(aff, steps, starts=()):
223223
aff_plus[:old_n_out, -1] = aff[:old_n_out, -1]
224224
# Add new diagonal elements
225225
for i, el in enumerate(steps):
226-
aff_plus[old_n_out+i, old_n_in+i] = el
226+
aff_plus[old_n_out + i, old_n_in + i] = el
227227
# Add translations for new affine, plus last 1
228228
aff_plus[old_n_out:, -1] = list(starts) + [1]
229229
return aff_plus

nibabel/analyze.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
('session_error', 'i2'),
108108
('regular', 'S1'),
109109
('hkey_un0', 'S1')
110-
]
110+
]
111111
image_dimension_dtd = [
112112
('dim', 'i2', (8,)),
113113
('vox_units', 'S4'),
@@ -127,7 +127,7 @@
127127
('verified', 'i4'),
128128
('glmax', 'i4'),
129129
('glmin', 'i4')
130-
]
130+
]
131131
data_history_dtd = [
132132
('descrip', 'S80'),
133133
('aux_file', 'S24'),
@@ -147,7 +147,7 @@
147147
('omin', 'i4'),
148148
('smax', 'i4'),
149149
('smin', 'i4')
150-
]
150+
]
151151

152152
# Full header numpy dtype combined across sub-fields
153153
header_dtype = np.dtype(header_key_dtd + image_dimension_dtd +
@@ -606,7 +606,7 @@ def get_data_shape(self):
606606
ndims = dims[0]
607607
if ndims == 0:
608608
return 0,
609-
return tuple(int(d) for d in dims[1:ndims+1])
609+
return tuple(int(d) for d in dims[1:ndims + 1])
610610

611611
def set_data_shape(self, shape):
612612
''' Set shape of data
@@ -624,18 +624,18 @@ def set_data_shape(self, shape):
624624
dims[:] = 1
625625
dims[0] = ndims
626626
try:
627-
dims[1:ndims+1] = shape
627+
dims[1:ndims + 1] = shape
628628
except (ValueError, OverflowError):
629629
# numpy 1.4.1 at least generates a ValueError from trying to set a
630630
# python long into an int64 array (dims are int64 for nifti2)
631631
values_fit = False
632632
else:
633-
values_fit = np.all(dims[1:ndims+1] == shape)
633+
values_fit = np.all(dims[1:ndims + 1] == shape)
634634
# Error if we did not succeed setting dimensions
635635
if not values_fit:
636636
raise HeaderDataError('shape %s does not fit in dim datatype' %
637637
(shape,))
638-
self._structarr['pixdim'][ndims+1:] = 1.0
638+
self._structarr['pixdim'][ndims + 1:] = 1.0
639639

640640
def get_base_affine(self):
641641
''' Get affine from basic (shared) header fields
@@ -659,8 +659,8 @@ def get_base_affine(self):
659659
hdr = self._structarr
660660
dims = hdr['dim']
661661
ndim = dims[0]
662-
return shape_zoom_affine(hdr['dim'][1:ndim+1],
663-
hdr['pixdim'][1:ndim+1],
662+
return shape_zoom_affine(hdr['dim'][1:ndim + 1],
663+
hdr['pixdim'][1:ndim + 1],
664664
self.default_x_flip)
665665

666666
get_best_affine = get_base_affine
@@ -691,7 +691,7 @@ def get_zooms(self):
691691
if ndim == 0:
692692
return (1.0,)
693693
pixdims = hdr['pixdim']
694-
return tuple(pixdims[1:ndim+1])
694+
return tuple(pixdims[1:ndim + 1])
695695

696696
def set_zooms(self, zooms):
697697
''' Set zooms into header fields
@@ -708,7 +708,7 @@ def set_zooms(self, zooms):
708708
if np.any(zooms < 0):
709709
raise HeaderDataError('zooms must be positive')
710710
pixdims = hdr['pixdim']
711-
pixdims[1:ndim+1] = zooms[:]
711+
pixdims[1:ndim + 1] = zooms[:]
712712

713713
def as_analyze_map(self):
714714
""" Return header as mapping for conversion to Analyze types
@@ -794,7 +794,7 @@ def set_slope_inter(self, slope, inter=None):
794794
If float, value must be 0.0 or we raise a ``HeaderTypeError``
795795
'''
796796
if ((slope in (None, 1) or np.isnan(slope)) and
797-
(inter in (None, 0) or np.isnan(inter))):
797+
(inter in (None, 0) or np.isnan(inter))):
798798
return
799799
raise HeaderTypeError('Cannot set slope != 1 or intercept != 0 '
800800
'for Analyze headers')

nibabel/batteryrunners.py

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def __len__(self):
175175

176176

177177
class Report(object):
178+
178179
def __init__(self,
179180
error=Exception,
180181
problem_level=0,

nibabel/benchmarks/bench_array_to_file.py

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import numpy as np
2121

22-
from ..externals.six import BytesIO
23-
from ..volumeutils import array_to_file
2422

2523
from .butils import print_git_title
2624

nibabel/benchmarks/bench_finite_range.py

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import numpy as np
2121

22-
from ..externals.six import BytesIO
23-
from ..volumeutils import finite_range
2422

2523
from .butils import print_git_title
2624

nibabel/casting.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ def type_info(np_type):
269269
# Oh dear, we don't recognize the type information. Try some known types
270270
# and then give up. At this stage we're expecting exotic longdouble or
271271
# their complex equivalent.
272-
if not np_type in (np.longdouble, np.longcomplex) or width not in (16, 32):
272+
if np_type not in (np.longdouble, np.longcomplex) or width not in (16, 32):
273273
raise FloatingError('We had not expected type %s' % np_type)
274274
if (vals == (1, 1, 16) and on_powerpc() and
275-
_check_maxexp(np.longdouble, 1024)):
275+
_check_maxexp(np.longdouble, 1024)):
276276
# double pair on PPC. The _check_nmant routine does not work for this
277277
# type, hence the powerpc platform check instead
278278
ret.update(dict(nmant=106, width=width))
@@ -439,7 +439,7 @@ def int_to_float(val, flt_type):
439439
f : numpy scalar
440440
of type `flt_type`
441441
"""
442-
if not flt_type is np.longdouble:
442+
if flt_type is not np.longdouble:
443443
return flt_type(val)
444444
# The following works around a nasty numpy 1.4.1 bug such that:
445445
# >>> int(np.uint32(2**32-1)
@@ -664,7 +664,7 @@ def best_float():
664664
except FloatingError:
665665
return np.float64
666666
if (long_info['nmant'] > type_info(np.float64)['nmant'] and
667-
machine() != 'sparc64'): # sparc has crazy-slow float128
667+
machine() != 'sparc64'): # sparc has crazy-slow float128
668668
return np.longdouble
669669
return np.float64
670670

nibabel/checkwarns.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
from .testing import (error_warnings, suppress_warnings)
1616

1717

18-
warnings.warn('The checkwarns module is deprecated and will be removed in nibabel v3.0', FutureWarning)
18+
warnings.warn('The checkwarns module is deprecated and will be removed '
19+
'in nibabel v3.0', FutureWarning)
1920

2021

2122
class ErrorWarnings(error_warnings):
23+
2224
def __init__(self, *args, **kwargs):
2325
warnings.warn('ErrorWarnings is deprecated and will be removed in '
2426
'nibabel v3.0; use nibabel.testing.error_warnings.',
@@ -27,6 +29,7 @@ def __init__(self, *args, **kwargs):
2729

2830

2931
class IgnoreWarnings(suppress_warnings):
32+
3033
def __init__(self, *args, **kwargs):
3134
warnings.warn('IgnoreWarnings is deprecated and will be removed in '
3235
'nibabel v3.0; use nibabel.testing.suppress_warnings.',

nibabel/data.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BomberError(DataError, AttributeError):
3333

3434
class Datasource(object):
3535
''' Simple class to add base path to relative path '''
36+
3637
def __init__(self, base_path):
3738
''' Initialize datasource
3839
@@ -87,7 +88,7 @@ def list_files(self, relative=True):
8788
out_list = list()
8889
for base, dirs, files in os.walk(self.base_path):
8990
if relative:
90-
base = base[len(self.base_path)+1:]
91+
base = base[len(self.base_path) + 1:]
9192
for filename in files:
9293
out_list.append(pjoin(base, filename))
9394
return out_list
@@ -97,6 +98,7 @@ class VersionedDatasource(Datasource):
9798
''' Datasource with version information in config file
9899
99100
'''
101+
100102
def __init__(self, base_path, config_filename=None):
101103
''' Initialize versioned datasource
102104
@@ -239,8 +241,8 @@ def find_data_dir(root_dirs, *names):
239241
if os.path.isdir(pth):
240242
return pth
241243
raise DataError('Could not find datasource "%s" in data path "%s"' %
242-
(ds_relative,
243-
os.path.pathsep.join(root_dirs)))
244+
(ds_relative,
245+
os.path.pathsep.join(root_dirs)))
244246

245247

246248
def make_datasource(pkg_def, **kwargs):
@@ -296,14 +298,15 @@ def make_datasource(pkg_def, **kwargs):
296298
e)
297299
if 'name' in pkg_def:
298300
msg += '\n\nYou may need the package "%s"' % pkg_def['name']
299-
if not pkg_hint is None:
301+
if pkg_hint is not None:
300302
msg += '\n\n%s' % pkg_hint
301303
raise DataError(msg)
302304
return VersionedDatasource(pth)
303305

304306

305307
class Bomber(object):
306308
''' Class to raise an informative error when used '''
309+
307310
def __init__(self, name, msg):
308311
self.name = name
309312
self.msg = msg
@@ -350,7 +353,7 @@ def datasource_or_bomber(pkg_def, **options):
350353
return Bomber(sys_relpath, str(e))
351354
# check version
352355
if (version is None or
353-
LooseVersion(ds.version) >= LooseVersion(version)):
356+
LooseVersion(ds.version) >= LooseVersion(version)):
354357
return ds
355358
if 'name' in pkg_def:
356359
pkg_name = pkg_def['name']

nibabel/deprecated.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ModuleProxy(object):
2424
when you do attribute access and return the attributes of the imported
2525
module.
2626
"""
27+
2728
def __init__(self, module_name):
2829
self._module_name = module_name
2930

nibabel/dft.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ def __init__(self, series, i, si):
5757

5858
def __str__(self):
5959
fmt = 'expecting instance number %d, got %d'
60-
return fmt % (self.i+1, self.si.instance_number)
60+
return fmt % (self.i + 1, self.si.instance_number)
6161

6262

6363
class _Study(object):
64+
6465
def __init__(self, d):
6566
self.uid = d['uid']
6667
self.date = d['date']
@@ -93,6 +94,7 @@ def patient_name_or_uid(self):
9394

9495

9596
class _Series(object):
97+
9698
def __init__(self, d):
9799
self.uid = d['uid']
98100
self.study = d['study']
@@ -160,7 +162,7 @@ def as_nifti(self):
160162
for (i, si) in enumerate(self.storage_instances):
161163
if i + 1 != si.instance_number:
162164
raise InstanceStackError(self, i, si)
163-
logger.info('reading %d/%d' % (i+1, len(self.storage_instances)))
165+
logger.info('reading %d/%d' % (i + 1, len(self.storage_instances)))
164166
d = self.storage_instances[i].dicom()
165167
data[i, :, :] = d.pixel_array
166168

@@ -190,7 +192,7 @@ def as_nifti(self):
190192
m = ((pdi * cosi[0], pdj * cosj[0], pdk * cosk[0], pos_1[0]),
191193
(pdi * cosi[1], pdj * cosj[1], pdk * cosk[1], pos_1[1]),
192194
(pdi * cosi[2], pdj * cosj[2], pdk * cosk[2], pos_1[2]),
193-
( 0, 0, 0, 1))
195+
(0, 0, 0, 1))
194196

195197
m = numpy.array(m)
196198

@@ -212,6 +214,7 @@ def nifti_size(self):
212214

213215

214216
class _StorageInstance(object):
217+
215218
def __init__(self, d):
216219
self.uid = d['uid']
217220
self.instance_number = d['instance_number']
@@ -238,6 +241,7 @@ def dicom(self):
238241

239242
class _db_nochange:
240243
"""context guard for read-only database access"""
244+
241245
def __enter__(self):
242246
self.c = DB.cursor()
243247
return self.c
@@ -251,6 +255,7 @@ def __exit__(self, type, value, traceback):
251255

252256
class _db_change:
253257
"""context guard for database access requiring a commit"""
258+
254259
def __enter__(self):
255260
self.c = DB.cursor()
256261
return self.c

0 commit comments

Comments
 (0)