Commit 95b43c48 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

MNT: Remove use of six

parent 9a2f4904
...@@ -9,13 +9,13 @@ files. Pillow is required to use the ``Bitmap`` class. ...@@ -9,13 +9,13 @@ files. Pillow is required to use the ``Bitmap`` class.
""" """
import os.path as op import os.path as op
import logging import pathlib
import six import logging
import numpy as np import numpy as np
from . import image as fslimage import fsl.data.image as fslimage
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -51,7 +51,7 @@ class Bitmap(object): ...@@ -51,7 +51,7 @@ class Bitmap(object):
data. data.
""" """
if isinstance(bmp, six.string_types): if isinstance(bmp, (pathlib.Path, str)):
try: try:
# Allow big images # Allow big images
...@@ -61,7 +61,7 @@ class Bitmap(object): ...@@ -61,7 +61,7 @@ class Bitmap(object):
except ImportError: except ImportError:
raise RuntimeError('Install Pillow to use the Bitmap class') raise RuntimeError('Install Pillow to use the Bitmap class')
src = bmp src = str(bmp)
img = Image.open(src) img = Image.open(src)
# If this is a palette/LUT # If this is a palette/LUT
......
...@@ -10,8 +10,8 @@ Freesurfer ``mgh``/``mgz`` image files. ...@@ -10,8 +10,8 @@ Freesurfer ``mgh``/``mgz`` image files.
import os.path as op import os.path as op
import pathlib
import six
import numpy as np import numpy as np
import nibabel as nib import nibabel as nib
...@@ -47,7 +47,7 @@ class MGHImage(fslimage.Image): ...@@ -47,7 +47,7 @@ class MGHImage(fslimage.Image):
All other arguments are passed through to :meth:`Image.__init__` All other arguments are passed through to :meth:`Image.__init__`
""" """
if isinstance(image, six.string_types): if isinstance(image, (str, pathlib.Path)):
filename = op.abspath(image) filename = op.abspath(image)
name = op.basename(filename) name = op.basename(filename)
image = nib.load(image) image = nib.load(image)
......
...@@ -14,8 +14,6 @@ that some condition is met. ...@@ -14,8 +14,6 @@ that some condition is met.
""" """
import six
import nibabel as nib import nibabel as nib
import fsl.data.image as fslimage import fsl.data.image as fslimage
...@@ -24,7 +22,7 @@ import fsl.data.image as fslimage ...@@ -24,7 +22,7 @@ import fsl.data.image as fslimage
def ensureIsImage(img): def ensureIsImage(img):
"""Ensures that the given ``img`` is an in-memory ``nibabel`` object. """Ensures that the given ``img`` is an in-memory ``nibabel`` object.
""" """
if isinstance(img, six.string_types): if isinstance(img, str):
img = fslimage.addExt(img) img = fslimage.addExt(img)
img = nib.load(img) img = nib.load(img)
return img return img
...@@ -37,7 +37,7 @@ Example usage, building a short pipeline:: ...@@ -37,7 +37,7 @@ Example usage, building a short pipeline::
""" """
from six import BytesIO from io import BytesIO
import os.path as op import os.path as op
import glob import glob
import time import time
...@@ -439,9 +439,9 @@ _external_job = ("""#!{} ...@@ -439,9 +439,9 @@ _external_job = ("""#!{}
# This is a temporary file designed to run the python function {}, # This is a temporary file designed to run the python function {},
# so that it can be submitted to the cluster # so that it can be submitted to the cluster
import pickle import pickle
from six import BytesIO from io import BytesIO
from importlib import import_module from importlib import import_module
{} {}
pickle_bytes = BytesIO({}) pickle_bytes = BytesIO({})
name_type, name, func_name, args, kwargs = pickle.load(pickle_bytes) name_type, name, func_name, args, kwargs = pickle.load(pickle_bytes)
...@@ -455,7 +455,7 @@ elif name_type == 'script': ...@@ -455,7 +455,7 @@ elif name_type == 'script':
func = local_execute[func_name] func = local_execute[func_name]
else: else:
raise ValueError('Unknown name_type: %r' % name_type) raise ValueError('Unknown name_type: %r' % name_type)
{} {}
""") """)
......
...@@ -21,7 +21,6 @@ a function: ...@@ -21,7 +21,6 @@ a function:
import logging import logging
import hashlib import hashlib
import functools import functools
import six
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -171,7 +170,7 @@ def memoizeMD5(func): ...@@ -171,7 +170,7 @@ def memoizeMD5(func):
# compatible) bytes , and take # compatible) bytes , and take
# the hash of those bytes. # the hash of those bytes.
for arg in args: for arg in args:
if not isinstance(arg, six.string_types): if not isinstance(arg, str):
arg = str(arg) arg = str(arg)
arg = arg.encode('utf-8') arg = arg.encode('utf-8')
hashobj.update(arg) hashobj.update(arg)
......
...@@ -14,9 +14,6 @@ import inspect ...@@ -14,9 +14,6 @@ import inspect
import contextlib import contextlib
import collections import collections
import six
import fsl.utils.idle as idle import fsl.utils.idle as idle
import fsl.utils.weakfuncref as weakfuncref import fsl.utils.weakfuncref as weakfuncref
...@@ -297,7 +294,7 @@ class Notifier(object): ...@@ -297,7 +294,7 @@ class Notifier(object):
:arg topic: Topic or topics that the listener is registered on. :arg topic: Topic or topics that the listener is registered on.
""" """
if topic is None or isinstance(topic, six.string_types): if topic is None or isinstance(topic, str):
topic = [topic] topic = [topic]
topics = topic topics = topic
......
...@@ -30,8 +30,6 @@ import subprocess as sp ...@@ -30,8 +30,6 @@ import subprocess as sp
import os.path as op import os.path as op
import os import os
import six
from fsl.utils.platform import platform as fslplatform from fsl.utils.platform import platform as fslplatform
import fsl.utils.fslsub as fslsub import fsl.utils.fslsub as fslsub
import fsl.utils.tempdir as tempdir import fsl.utils.tempdir as tempdir
...@@ -83,7 +81,7 @@ def prepareArgs(args): ...@@ -83,7 +81,7 @@ def prepareArgs(args):
if len(args) == 1: if len(args) == 1:
# Argument was a command string # Argument was a command string
if isinstance(args[0], six.string_types): if isinstance(args[0], str):
args = shlex.split(args[0]) args = shlex.split(args[0])
# Argument was an unpacked sequence # Argument was an unpacked sequence
......
...@@ -7,13 +7,12 @@ ...@@ -7,13 +7,12 @@
"""This module provides the :class:`WeakFunctionRef` class. """ """This module provides the :class:`WeakFunctionRef` class. """
import six
import types import types
import weakref import weakref
import inspect import inspect
class WeakFunctionRef(object): class WeakFunctionRef:
"""Class which encapsulates a :mod:`weakref` to a function or method. """Class which encapsulates a :mod:`weakref` to a function or method.
This class is used by :class:`.Notifier` instances to reference This class is used by :class:`.Notifier` instances to reference
...@@ -28,10 +27,10 @@ class WeakFunctionRef(object): ...@@ -28,10 +27,10 @@ class WeakFunctionRef(object):
""" """
# Bound method # Bound method
if self.__isMethod(func): if inspect.ismethod(func):
boundMeth = six.get_method_function(func) boundMeth = func.__func__
boundSelf = six.get_method_self( func) boundSelf = func.__self__
# We can't take a weakref of the method # We can't take a weakref of the method
# object, so we have to weakref the object # object, so we have to weakref the object
...@@ -73,35 +72,6 @@ class WeakFunctionRef(object): ...@@ -73,35 +72,6 @@ class WeakFunctionRef(object):
return self.__str__() return self.__str__()
def __isMethod(self, func):
"""Returns ``True`` if the given function is a bound method,
``False`` otherwise.
This seems to be one of the few areas where python 2 and 3 are
irreconcilably incompatible (or just where :mod:`six` does not have a
function to help us).
In Python 3 there is no difference between an unbound method and a
function. But in Python 2, an unbound method is still a method (and
inspect.ismethod returns True).
"""
ismethod = False
# Therefore, in python2 we need to test
# whether the function is a method, and
# also test whether it is bound.
if six.PY2:
ismethod = (inspect.ismethod(func) and
six.get_method_self(func) is not None)
# But in python3, if the function is a
# method it is, by definition, bound.
elif six.PY3:
ismethod = inspect.ismethod(func)
return ismethod
def __findPrivateMethod(self): def __findPrivateMethod(self):
"""Finds and returns the bound method associated with the encapsulated """Finds and returns the bound method associated with the encapsulated
...@@ -125,8 +95,7 @@ class WeakFunctionRef(object): ...@@ -125,8 +95,7 @@ class WeakFunctionRef(object):
att = getattr(obj, name) att = getattr(obj, name)
if isinstance(att, types.MethodType) and \ if isinstance(att, types.MethodType) and att.__func__ is func:
six.get_method_function(att) is func:
return att return att
return None return None
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
""" """
import six
import fsl.utils.assertions as asrt import fsl.utils.assertions as asrt
from . import wrapperutils as wutils from . import wrapperutils as wutils
...@@ -28,7 +26,7 @@ def fast(imgs, out='fast', **kwargs): ...@@ -28,7 +26,7 @@ def fast(imgs, out='fast', **kwargs):
command line option) command line option)
""" """
if isinstance(imgs, six.string_types): if isinstance(imgs, str):
imgs = [imgs] imgs = [imgs]
asrt.assertIsNifti(*imgs) asrt.assertIsNifti(*imgs)
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
`FSL_ANAT <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat>`_ command. `FSL_ANAT <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat>`_ command.
""" """
import six
import fsl.utils.assertions as asrt import fsl.utils.assertions as asrt
from . import wrapperutils as wutils from . import wrapperutils as wutils
......
...@@ -103,8 +103,6 @@ import tempfile ...@@ -103,8 +103,6 @@ import tempfile
import warnings import warnings
import functools import functools
import six
import nibabel as nib import nibabel as nib
import numpy as np import numpy as np
...@@ -346,8 +344,7 @@ def applyArgStyle(style, ...@@ -346,8 +344,7 @@ def applyArgStyle(style,
# always returns a sequence # always returns a sequence
def fmtval(val): def fmtval(val):
if isinstance(val, abc.Sequence) and \ if isinstance(val, abc.Sequence) and (not isinstance(val, str)):
not isinstance(val, six.string_types):
val = [str(v) for v in val] val = [str(v) for v in val]
if valsep == ' ': return val if valsep == ' ': return val
...@@ -711,8 +708,7 @@ class FileOrThing(object): ...@@ -711,8 +708,7 @@ class FileOrThing(object):
kwargs.get('cmdonly', False): kwargs.get('cmdonly', False):
allargs = {**dict(zip(argnames, args)), **kwargs} allargs = {**dict(zip(argnames, args)), **kwargs}
for name, val in allargs.items(): for name, val in allargs.items():
if (name in self.__things) and \ if (name in self.__things) and (not isinstance(val, str)):
(not isinstance(val, six.string_types)):
raise ValueError('Cannot use in-memory objects ' raise ValueError('Cannot use in-memory objects '
'or LOAD with submit=True!') 'or LOAD with submit=True!')
return func(*args, **kwargs) return func(*args, **kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment