Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christoph Arthofer
fslpy
Commits
95b43c48
Commit
95b43c48
authored
Apr 16, 2021
by
Paul McCarthy
🚵
Browse files
MNT: Remove use of six
parent
9a2f4904
Changes
11
Hide whitespace changes
Inline
Side-by-side
fsl/data/bitmap.py
View file @
95b43c48
...
...
@@ -9,13 +9,13 @@ files. Pillow is required to use the ``Bitmap`` class.
"""
import
os.path
as
op
import
logging
import
six
import
os.path
as
op
import
pathlib
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__
)
...
...
@@ -51,7 +51,7 @@ class Bitmap(object):
data.
"""
if
isinstance
(
bmp
,
six
.
string_types
):
if
isinstance
(
bmp
,
(
pathlib
.
Path
,
str
)
):
try
:
# Allow big images
...
...
@@ -61,7 +61,7 @@ class Bitmap(object):
except
ImportError
:
raise
RuntimeError
(
'Install Pillow to use the Bitmap class'
)
src
=
bmp
src
=
str
(
bmp
)
img
=
Image
.
open
(
src
)
# If this is a palette/LUT
...
...
fsl/data/mghimage.py
View file @
95b43c48
...
...
@@ -10,8 +10,8 @@ Freesurfer ``mgh``/``mgz`` image files.
import
os.path
as
op
import
pathlib
import
six
import
numpy
as
np
import
nibabel
as
nib
...
...
@@ -47,7 +47,7 @@ class MGHImage(fslimage.Image):
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
)
name
=
op
.
basename
(
filename
)
image
=
nib
.
load
(
image
)
...
...
fsl/utils/ensure.py
View file @
95b43c48
...
...
@@ -14,8 +14,6 @@ that some condition is met.
"""
import
six
import
nibabel
as
nib
import
fsl.data.image
as
fslimage
...
...
@@ -24,7 +22,7 @@ import fsl.data.image as fslimage
def
ensureIsImage
(
img
):
"""Ensures that the given ``img`` is an in-memory ``nibabel`` object.
"""
if
isinstance
(
img
,
s
ix
.
string_types
):
if
isinstance
(
img
,
s
tr
):
img
=
fslimage
.
addExt
(
img
)
img
=
nib
.
load
(
img
)
return
img
fsl/utils/fslsub.py
View file @
95b43c48
...
...
@@ -37,7 +37,7 @@ Example usage, building a short pipeline::
"""
from
six
import
BytesIO
from
io
import
BytesIO
import
os.path
as
op
import
glob
import
time
...
...
@@ -439,9 +439,9 @@ _external_job = ("""#!{}
# This is a temporary file designed to run the python function {},
# so that it can be submitted to the cluster
import pickle
from
six
import BytesIO
from
io
import BytesIO
from importlib import import_module
{}
{}
pickle_bytes = BytesIO({})
name_type, name, func_name, args, kwargs = pickle.load(pickle_bytes)
...
...
@@ -455,7 +455,7 @@ elif name_type == 'script':
func = local_execute[func_name]
else:
raise ValueError('Unknown name_type: %r' % name_type)
{}
"""
)
...
...
fsl/utils/memoize.py
View file @
95b43c48
...
...
@@ -21,7 +21,6 @@ a function:
import
logging
import
hashlib
import
functools
import
six
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -171,7 +170,7 @@ def memoizeMD5(func):
# compatible) bytes , and take
# the hash of those bytes.
for
arg
in
args
:
if
not
isinstance
(
arg
,
s
ix
.
string_types
):
if
not
isinstance
(
arg
,
s
tr
):
arg
=
str
(
arg
)
arg
=
arg
.
encode
(
'utf-8'
)
hashobj
.
update
(
arg
)
...
...
fsl/utils/notifier.py
View file @
95b43c48
...
...
@@ -14,9 +14,6 @@ import inspect
import
contextlib
import
collections
import
six
import
fsl.utils.idle
as
idle
import
fsl.utils.weakfuncref
as
weakfuncref
...
...
@@ -297,7 +294,7 @@ class Notifier(object):
:arg topic: Topic or topics that the listener is registered on.
"""
if
topic
is
None
or
isinstance
(
topic
,
s
ix
.
string_types
):
if
topic
is
None
or
isinstance
(
topic
,
s
tr
):
topic
=
[
topic
]
topics
=
topic
...
...
fsl/utils/run.py
View file @
95b43c48
...
...
@@ -30,8 +30,6 @@ import subprocess as sp
import
os.path
as
op
import
os
import
six
from
fsl.utils.platform
import
platform
as
fslplatform
import
fsl.utils.fslsub
as
fslsub
import
fsl.utils.tempdir
as
tempdir
...
...
@@ -83,7 +81,7 @@ def prepareArgs(args):
if
len
(
args
)
==
1
:
# Argument was a command string
if
isinstance
(
args
[
0
],
s
ix
.
string_types
):
if
isinstance
(
args
[
0
],
s
tr
):
args
=
shlex
.
split
(
args
[
0
])
# Argument was an unpacked sequence
...
...
fsl/utils/weakfuncref.py
View file @
95b43c48
...
...
@@ -7,13 +7,12 @@
"""This module provides the :class:`WeakFunctionRef` class. """
import
six
import
types
import
weakref
import
inspect
class
WeakFunctionRef
(
object
)
:
class
WeakFunctionRef
:
"""Class which encapsulates a :mod:`weakref` to a function or method.
This class is used by :class:`.Notifier` instances to reference
...
...
@@ -28,10 +27,10 @@ class WeakFunctionRef(object):
"""
# Bound method
if
self
.
__
is
M
ethod
(
func
):
if
inspect
.
is
m
ethod
(
func
):
boundMeth
=
six
.
get_method_function
(
func
)
boundSelf
=
six
.
get_method_self
(
func
)
boundMeth
=
func
.
__
func
__
boundSelf
=
func
.
__self__
# We can't take a weakref of the method
# object, so we have to weakref the object
...
...
@@ -73,35 +72,6 @@ class WeakFunctionRef(object):
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
):
"""Finds and returns the bound method associated with the encapsulated
...
...
@@ -125,8 +95,7 @@ class WeakFunctionRef(object):
att
=
getattr
(
obj
,
name
)
if
isinstance
(
att
,
types
.
MethodType
)
and
\
six
.
get_method_function
(
att
)
is
func
:
if
isinstance
(
att
,
types
.
MethodType
)
and
att
.
__func__
is
func
:
return
att
return
None
...
...
fsl/wrappers/fast.py
View file @
95b43c48
...
...
@@ -10,8 +10,6 @@
"""
import
six
import
fsl.utils.assertions
as
asrt
from
.
import
wrapperutils
as
wutils
...
...
@@ -28,7 +26,7 @@ def fast(imgs, out='fast', **kwargs):
command line option)
"""
if
isinstance
(
imgs
,
s
ix
.
string_types
):
if
isinstance
(
imgs
,
s
tr
):
imgs
=
[
imgs
]
asrt
.
assertIsNifti
(
*
imgs
)
...
...
fsl/wrappers/fsl_anat.py
View file @
95b43c48
...
...
@@ -8,8 +8,6 @@
`FSL_ANAT <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat>`_ command.
"""
import
six
import
fsl.utils.assertions
as
asrt
from
.
import
wrapperutils
as
wutils
...
...
fsl/wrappers/wrapperutils.py
View file @
95b43c48
...
...
@@ -103,8 +103,6 @@ import tempfile
import
warnings
import
functools
import
six
import
nibabel
as
nib
import
numpy
as
np
...
...
@@ -346,8 +344,7 @@ def applyArgStyle(style,
# always returns a sequence
def
fmtval
(
val
):
if
isinstance
(
val
,
abc
.
Sequence
)
and
\
not
isinstance
(
val
,
six
.
string_types
):
if
isinstance
(
val
,
abc
.
Sequence
)
and
(
not
isinstance
(
val
,
str
)):
val
=
[
str
(
v
)
for
v
in
val
]
if
valsep
==
' '
:
return
val
...
...
@@ -711,8 +708,7 @@ class FileOrThing(object):
kwargs
.
get
(
'cmdonly'
,
False
):
allargs
=
{
**
dict
(
zip
(
argnames
,
args
)),
**
kwargs
}
for
name
,
val
in
allargs
.
items
():
if
(
name
in
self
.
__things
)
and
\
(
not
isinstance
(
val
,
six
.
string_types
)):
if
(
name
in
self
.
__things
)
and
(
not
isinstance
(
val
,
str
)):
raise
ValueError
(
'Cannot use in-memory objects '
'or LOAD with submit=True!'
)
return
func
(
*
args
,
**
kwargs
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment