Skip to content
Snippets Groups Projects
Commit 4193746d authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Fixing important pylint issues

parent ea38d1aa
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,7 @@ def isFEATImage(path): ...@@ -64,7 +64,7 @@ def isFEATImage(path):
try: try:
path = fslimage.addExt(path, mustExist=True) path = fslimage.addExt(path, mustExist=True)
except: except fslimage.PathError:
return False return False
dirname = op.dirname( path) dirname = op.dirname( path)
...@@ -115,7 +115,7 @@ def hasStats(featdir): ...@@ -115,7 +115,7 @@ def hasStats(featdir):
try: try:
getZStatFile(featdir, 0) getZStatFile(featdir, 0)
return True return True
except: except fslimage.PathError:
return False return False
......
...@@ -326,7 +326,8 @@ class VoxelwiseEV(NormalEV): ...@@ -326,7 +326,8 @@ class VoxelwiseEV(NormalEV):
if op.exists(filename): if op.exists(filename):
self.filename = filename self.filename = filename
else: else:
log.warning('Voxelwise EV file does not exist: '.format(filename)) log.warning('Voxelwise EV file does not '
'exist: {}'.format(filename))
self.filename = None self.filename = None
...@@ -406,8 +407,8 @@ class VoxelwiseConfoundEV(EV): ...@@ -406,8 +407,8 @@ class VoxelwiseConfoundEV(EV):
if op.exists(filename): if op.exists(filename):
self.filename = filename self.filename = filename
else: else:
log.warning('Voxelwise confound EV file ' log.warning('Voxelwise confound EV file does '
'does not exist: '.format(filename)) 'not exist: {}'.format(filename))
self.filename = None self.filename = None
...@@ -547,7 +548,7 @@ def getFirstLevelEVs(featDir, settings, designMat): ...@@ -547,7 +548,7 @@ def getFirstLevelEVs(featDir, settings, designMat):
# Create the voxelwise confound EVs. # Create the voxelwise confound EVs.
# We make a name for the EV from the # We make a name for the EV from the
# file name. # file name.
for i, (f, l) in enumerate(zip(voxConfFiles, voxConfLocs)): for i, f in enumerate(voxConfFiles):
title = op.basename(fslimage.removeExt(f)) title = op.basename(fslimage.removeExt(f))
evs.append(VoxelwiseConfoundEV(len(evs), i, title, f)) evs.append(VoxelwiseConfoundEV(len(evs), i, title, f))
......
...@@ -222,6 +222,8 @@ class Nifti(notifier.Notifier): ...@@ -222,6 +222,8 @@ class Nifti(notifier.Notifier):
# qform = header.get('qform_code', -1) # qform = header.get('qform_code', -1)
# sform = header.get('sform_code', -1) # sform = header.get('sform_code', -1)
# #
# TODO Change this in fslpy 2.0.0
#
if isinstance(header, nib.nifti1.Nifti1Header): if isinstance(header, nib.nifti1.Nifti1Header):
intent = header['intent_code'] intent = header['intent_code']
qform = header['qform_code'] qform = header['qform_code']
...@@ -309,8 +311,8 @@ class Nifti(notifier.Notifier): ...@@ -309,8 +311,8 @@ class Nifti(notifier.Notifier):
val = self.header[key] val = self.header[key]
try: val = bytes(val).partition(b'\0')[0] try: val = bytes(val).partition(b'\0')[0]
except: val = bytes(val) except Exception: val = bytes(val)
val = val.decode('ascii') val = val.decode('ascii')
...@@ -611,12 +613,12 @@ class Nifti(notifier.Notifier): ...@@ -611,12 +613,12 @@ class Nifti(notifier.Notifier):
:class:`Nifti` instance) has the same dimensions and is in the :class:`Nifti` instance) has the same dimensions and is in the
same space as this image. same space as this image.
""" """
return np.all(np.isclose(self .__shape[:3], return np.all(np.isclose(self .shape[:3],
other.__shape[:3])) and \ other.shape[:3])) and \
np.all(np.isclose(self .__pixdim[:3], np.all(np.isclose(self .pixdim[:3],
other.__pixdim[:3])) and \ other.pixdim[:3])) and \
np.all(np.isclose(self .__voxToWorldMat, np.all(np.isclose(self .voxToWorldMat,
other.__voxToWorldMat)) other.voxToWorldMat))
def getOrientation(self, axis, xform): def getOrientation(self, axis, xform):
...@@ -1426,7 +1428,7 @@ def read_segments(fileobj, segments, n_bytes): ...@@ -1426,7 +1428,7 @@ def read_segments(fileobj, segments, n_bytes):
# actual file is available via the fobj attribute # actual file is available via the fobj attribute
lock = getattr(fileobj.fobj, '_arrayproxy_lock') lock = getattr(fileobj.fobj, '_arrayproxy_lock')
except: except AttributeError:
return fileslice.orig_read_segments(fileobj, segments, n_bytes) return fileslice.orig_read_segments(fileobj, segments, n_bytes)
if len(segments) == 0: if len(segments) == 0:
......
...@@ -231,7 +231,7 @@ class ImageWrapper(notifier.Notifier): ...@@ -231,7 +231,7 @@ class ImageWrapper(notifier.Notifier):
self.__image = None self.__image = None
if self.__taskThread is not None: if self.__taskThread is not None:
self.__taskThread.stop() self.__taskThread.stop()
self.__taskThraed = None self.__taskThread = None
def getTaskThread(self): def getTaskThread(self):
...@@ -459,7 +459,7 @@ class ImageWrapper(notifier.Notifier): ...@@ -459,7 +459,7 @@ class ImageWrapper(notifier.Notifier):
# the min/max per volume/expansion, and # the min/max per volume/expansion, and
# iteratively update the stored per-volume # iteratively update the stored per-volume
# coverage and data range. # coverage and data range.
for i, exp in enumerate(expansions): for exp in expansions:
data = self.__getData(exp, isTuple=True) data = self.__getData(exp, isTuple=True)
data = data.squeeze(squeezeDims) data = data.squeeze(squeezeDims)
...@@ -750,7 +750,7 @@ def naninfrange(data): ...@@ -750,7 +750,7 @@ def naninfrange(data):
# finite values in the array # finite values in the array
try: try:
return data[finite].min(), data[finite].max() return data[finite].min(), data[finite].max()
except: except Exception:
return np.nan, np.nan return np.nan, np.nan
...@@ -1097,7 +1097,7 @@ def calcExpansion(slices, coverage): ...@@ -1097,7 +1097,7 @@ def calcExpansion(slices, coverage):
# 'padding' dimensions of size 1. # 'padding' dimensions of size 1.
def finishExpansion(exp, vol): def finishExpansion(exp, vol):
exp.append((vol, vol + 1)) exp.append((vol, vol + 1))
for i in range(padDims): for _ in range(padDims):
exp.append((0, 1)) exp.append((0, 1))
return exp return exp
......
...@@ -49,7 +49,7 @@ def isMelodicImage(path): ...@@ -49,7 +49,7 @@ def isMelodicImage(path):
try: try:
path = fslimage.addExt(path, mustExist=True) path = fslimage.addExt(path, mustExist=True)
except: except fslimage.PathError:
return False return False
dirname = op.dirname( path) dirname = op.dirname( path)
......
...@@ -380,7 +380,7 @@ def findReferenceImage(modelfile): ...@@ -380,7 +380,7 @@ def findReferenceImage(modelfile):
dirname = op.dirname(modelfile) dirname = op.dirname(modelfile)
prefixes = [getFIRSTPrefix(modelfile)] prefixes = [getFIRSTPrefix(modelfile)]
except: except ValueError:
return None return None
if prefixes[0].endswith('_first'): if prefixes[0].endswith('_first'):
...@@ -389,7 +389,7 @@ def findReferenceImage(modelfile): ...@@ -389,7 +389,7 @@ def findReferenceImage(modelfile):
for p in prefixes: for p in prefixes:
try: try:
return fslimage.addExt(op.join(dirname, p), mustExist=True) return fslimage.addExt(op.join(dirname, p), mustExist=True)
except: except fslimage.PathError:
continue continue
return None return None
...@@ -87,8 +87,8 @@ import functools ...@@ -87,8 +87,8 @@ import functools
import threading import threading
import collections import collections
try: import queue try: import queue
except: import Queue as queue except ImportError: import Queue as queue
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -142,7 +142,7 @@ def run(task, onFinish=None, onError=None, name=None): ...@@ -142,7 +142,7 @@ def run(task, onFinish=None, onError=None, name=None):
except Exception as e: except Exception as e:
log.warn('Task "{}" crashed'.format(name), exc_info=True) log.warning('Task "{}" crashed'.format(name), exc_info=True)
callback(onError, e) callback(onError, e)
# If WX, run on a thread # If WX, run on a thread
...@@ -759,7 +759,7 @@ class TaskThread(threading.Thread): ...@@ -759,7 +759,7 @@ class TaskThread(threading.Thread):
# Any other error typically indicates # Any other error typically indicates
# that this is a daemon thread, and # that this is a daemon thread, and
# the TaskThread object has been GC'd # the TaskThread object has been GC'd
except: except Exception:
break break
finally: finally:
......
...@@ -146,6 +146,7 @@ class Platform(notifier.Notifier): ...@@ -146,6 +146,7 @@ class Platform(notifier.Notifier):
self.__glRenderer = None self.__glRenderer = None
self.__glIsSoftware = None self.__glIsSoftware = None
self.__fslVersion = None self.__fslVersion = None
self.__fsldir = None
self.fsldir = os.environ.get('FSLDIR', None) self.fsldir = os.environ.get('FSLDIR', None)
# Determine if a display is available. We do # Determine if a display is available. We do
...@@ -239,18 +240,16 @@ class Platform(notifier.Notifier): ...@@ -239,18 +240,16 @@ class Platform(notifier.Notifier):
pi = [t.lower() for t in wx.PlatformInfo] pi = [t.lower() for t in wx.PlatformInfo]
for tag in pi: if any(['cocoa' in p for p in pi]): plat = WX_MAC_COCOA
elif any(['carbon' in p for p in pi]): plat = WX_MAC_CARBON
if any(['cocoa' in p for p in pi]): platform = WX_MAC_COCOA elif any(['gtk' in p for p in pi]): plat = WX_GTK
elif any(['carbon' in p for p in pi]): platform = WX_MAC_CARBON else: plat = WX_UNKNOWN
elif any(['gtk' in p for p in pi]): platform = WX_GTK
else: platform = WX_UNKNOWN
if platform is WX_UNKNOWN: if platform is WX_UNKNOWN:
log.warning('Could not determine wx platform from ' log.warning('Could not determine wx platform from '
'information: {}'.format(pi)) 'information: {}'.format(pi))
return platform return plat
@property @property
......
...@@ -341,7 +341,7 @@ class Settings(object): ...@@ -341,7 +341,7 @@ class Settings(object):
if not op.exists(cfgdir): if not op.exists(cfgdir):
try: try:
os.makedirs(cfgdir) os.makedirs(cfgdir)
except: except OSError:
log.warning( log.warning(
'Unable to create {} configuration ' 'Unable to create {} configuration '
'directory: {}'.format(cid, cfgdir), 'directory: {}'.format(cid, cfgdir),
...@@ -372,7 +372,7 @@ class Settings(object): ...@@ -372,7 +372,7 @@ class Settings(object):
try: try:
with open(configFile, 'rb') as f: with open(configFile, 'rb') as f:
return pickle.load(f) return pickle.load(f)
except: except (IOError, pickle.UnpicklingError):
log.debug('Unable to load stored {} configuration file ' log.debug('Unable to load stored {} configuration file '
'{}'.format(self.__configID, configFile), '{}'.format(self.__configID, configFile),
exc_info=True) exc_info=True)
...@@ -391,7 +391,7 @@ class Settings(object): ...@@ -391,7 +391,7 @@ class Settings(object):
try: try:
with open(configFile, 'wb') as f: with open(configFile, 'wb') as f:
pickle.dump(config, f) pickle.dump(config, f)
except: except (IOError, pickle.PicklingError):
log.warning('Unable to save {} configuration file ' log.warning('Unable to save {} configuration file '
'{}'.format(self.__configID, configFile), '{}'.format(self.__configID, configFile),
exc_info=True) exc_info=True)
...@@ -148,9 +148,9 @@ class WeakFunctionRef(object): ...@@ -148,9 +148,9 @@ class WeakFunctionRef(object):
obj = self.obj() obj = self.obj()
# Return the bound method object # Return the bound method object
try: return getattr(obj, self.funcName) try: return getattr(obj, self.funcName)
# If the function is a bound private method, # If the function is a bound private method,
# its name on the instance will have been # its name on the instance will have been
# mangled, so we need to search for it # mangled, so we need to search for it
except: return self.__findPrivateMethod() except AttributeError: return self.__findPrivateMethod()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment