From 227f56d034defb6d6ff218f61cddbc46c6364706 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Wed, 25 Jan 2017 11:50:23 -0800 Subject: [PATCH 1/3] RF: refactor setup.py to use info variable reader Use function to read variables from `info.py` file into object, making namespace clearer. --- nisext/sexts.py | 29 +++++++++++++++++++++++++++++ setup.py | 43 ++++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/nisext/sexts.py b/nisext/sexts.py index da1c056418..b0d34348e5 100644 --- a/nisext/sexts.py +++ b/nisext/sexts.py @@ -265,3 +265,32 @@ def run(self): continue with open(bat_file, 'wt') as fobj: fobj.write(bat_contents) + + +class Bunch(object): + def __init__(self, vars): + for key, name in vars.items(): + if key.startswith('__'): + continue + self.__dict__[key] = name + + +def read_vars_from(ver_file): + """ Read variables from Python text file + + Parameters + ---------- + ver_file : str + Filename of file to read + + Returns + ------- + info_vars : Bunch instance + Bunch object where variables read from `ver_file` appear as + attributes + """ + # Use exec for compabibility with Python 3 + ns = {} + with open(ver_file, 'rt') as fobj: + exec(fobj.read(), ns) + return Bunch(ns) diff --git a/setup.py b/setup.py index 5e9bf51c29..4d3c088fb4 100755 --- a/setup.py +++ b/setup.py @@ -29,13 +29,13 @@ from distutils.core import setup # Commit hash writing, and dependency checking -from nisext.sexts import get_comrec_build, package_check, install_scripts_bat +from nisext.sexts import (get_comrec_build, package_check, install_scripts_bat, + read_vars_from) cmdclass = {'build_py': get_comrec_build('nibabel'), 'install_scripts': install_scripts_bat} -# Get version and release info, which is all stored in nibabel/info.py -ver_file = os.path.join('nibabel', 'info.py') -exec(open(ver_file).read()) +# Get project related strings. +INFO = read_vars_from(pjoin('nibabel', 'info.py')) # Prepare setuptools args if 'setuptools' in sys.modules: @@ -53,31 +53,32 @@ pkg_chk = package_check # Do dependency checking -pkg_chk('numpy', NUMPY_MIN_VERSION) +pkg_chk('numpy', INFO.NUMPY_MIN_VERSION) +pkg_chk('six', INFO.SIX_MIN_VERSION) custom_pydicom_messages = {'missing opt': 'Missing optional package "%s"' ' provided by package "pydicom"' } pkg_chk('dicom', - PYDICOM_MIN_VERSION, + INFO.PYDICOM_MIN_VERSION, optional='dicom', messages = custom_pydicom_messages) def main(**extra_args): - setup(name=NAME, - maintainer=MAINTAINER, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - long_description=LONG_DESCRIPTION, - url=URL, - download_url=DOWNLOAD_URL, - license=LICENSE, - classifiers=CLASSIFIERS, - author=AUTHOR, - author_email=AUTHOR_EMAIL, - platforms=PLATFORMS, - version=VERSION, - requires=REQUIRES, - provides=PROVIDES, + setup(name=INFO.NAME, + maintainer=INFO.MAINTAINER, + maintainer_email=INFO.MAINTAINER_EMAIL, + description=INFO.DESCRIPTION, + long_description=INFO.LONG_DESCRIPTION, + url=INFO.URL, + download_url=INFO.DOWNLOAD_URL, + license=INFO.LICENSE, + classifiers=INFO.CLASSIFIERS, + author=INFO.AUTHOR, + author_email=INFO.AUTHOR_EMAIL, + platforms=INFO.PLATFORMS, + version=INFO.VERSION, + requires=INFO.REQUIRES, + provides=INFO.PROVIDES, packages = ['nibabel', 'nibabel.externals', 'nibabel.externals.tests', From 78c9b6154192ae5f7fb56b9b965d6cb516c9bf98 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Wed, 25 Jan 2017 11:51:16 -0800 Subject: [PATCH 2/3] RF: make six dependency, remove OrderedDict module Depend on six, use six directly, test deprecated nibabel.externals.six import. Remove implementation of OrderedDict for Python 2.6, but leave shim in place, presumably it will die a natural death. Note that, we can't test six==1.3 as a dependency, because setuptools needs something later already. --- .travis.yml | 4 +- bin/nib-ls | 2 - doc/source/installation.rst | 1 + nibabel/affines.py | 2 +- nibabel/benchmarks/bench_load_save.py | 2 +- nibabel/benchmarks/bench_streamlines.py | 2 +- nibabel/data.py | 2 +- nibabel/dft.py | 2 +- nibabel/eulerangles.py | 2 +- nibabel/externals/__init__.py | 8 +- nibabel/externals/netcdf.py | 4 +- nibabel/externals/ordereddict.py | 132 ------ nibabel/externals/six.py | 411 +----------------- nibabel/externals/tests/test_ordereddict.py | 21 - nibabel/externals/tests/test_six.py | 33 ++ nibabel/filebasedimages.py | 2 +- nibabel/fileslice.py | 2 +- nibabel/freesurfer/io.py | 4 +- nibabel/freesurfer/tests/test_mghformat.py | 2 +- nibabel/gifti/parse_gifti_fast.py | 2 +- nibabel/gifti/tests/test_gifti.py | 2 +- nibabel/info.py | 1 + nibabel/optpkg.py | 2 +- nibabel/parrec.py | 2 +- nibabel/py3k.py | 4 +- nibabel/spm99analyze.py | 2 +- nibabel/streamlines/__init__.py | 2 +- nibabel/streamlines/tests/test_streamlines.py | 2 +- nibabel/streamlines/tests/test_tractogram.py | 2 +- nibabel/streamlines/tests/test_trk.py | 2 +- nibabel/streamlines/tractogram_file.py | 2 +- nibabel/testing/__init__.py | 2 +- nibabel/tests/test_analyze.py | 2 +- nibabel/tests/test_api_validators.py | 2 +- nibabel/tests/test_arrayproxy.py | 2 +- nibabel/tests/test_arraywriters.py | 2 +- nibabel/tests/test_batteryrunners.py | 2 +- nibabel/tests/test_dft.py | 2 +- nibabel/tests/test_fileholders.py | 2 +- nibabel/tests/test_files_interface.py | 2 +- nibabel/tests/test_image_api.py | 2 +- nibabel/tests/test_image_load_save.py | 2 +- nibabel/tests/test_nifti1.py | 2 +- nibabel/tests/test_proxy_api.py | 2 +- nibabel/tests/test_round_trip.py | 2 +- nibabel/tests/test_scaling.py | 2 +- nibabel/tests/test_spatialimages.py | 2 +- nibabel/tests/test_spm99analyze.py | 2 +- nibabel/tests/test_trackvis.py | 2 +- nibabel/tests/test_utils.py | 2 +- nibabel/tests/test_wrapstruct.py | 2 +- requirements.txt | 3 +- 52 files changed, 97 insertions(+), 609 deletions(-) delete mode 100644 nibabel/externals/ordereddict.py delete mode 100644 nibabel/externals/tests/test_ordereddict.py create mode 100644 nibabel/externals/tests/test_six.py diff --git a/.travis.yml b/.travis.yml index 3545a5f573..b4c0cf5ee8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ addons: - libatlas-base-dev env: global: - - DEPENDS="numpy scipy matplotlib h5py pillow" + - DEPENDS="six numpy scipy matplotlib h5py pillow" - PYDICOM=1 - INSTALL_TYPE="setup" - EXTRA_WHEELS="https://5cf40426d9f06eb7461d-6fe47d9331aba7cd62fc36c7196769e4.ssl.cf2.rackcdn.com" @@ -37,7 +37,7 @@ matrix: # Absolute minimum dependencies - python: 2.7 env: - - DEPENDS=numpy==1.6.0 PYDICOM=0 + - DEPENDS="numpy==1.6.0" PYDICOM=0 # Absolute minimum dependencies plus oldest MPL # Check these against: # nibabel/info.py diff --git a/bin/nib-ls b/bin/nib-ls index 1a687c25ad..fe8007d917 100755 --- a/bin/nib-ls +++ b/bin/nib-ls @@ -19,11 +19,9 @@ import numpy as np import nibabel as nib from math import ceil -from collections import defaultdict from optparse import OptionParser, Option from io import StringIO from nibabel.py3k import asunicode -from nibabel.externals.six.moves import xrange __author__ = 'Yaroslav Halchenko' __copyright__ = 'Copyright (c) 2011-2016 Yaroslav Halchenko ' \ diff --git a/doc/source/installation.rst b/doc/source/installation.rst index 6b53841c05..9c18dfe3ee 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -88,6 +88,7 @@ Requirements * Python_ 2.7, or >= 3.4 * NumPy_ 1.6 or greater +* Six_ 1.3 or greater * SciPy_ (optional, for full SPM-ANALYZE support) * PyDICOM_ 0.9.7 or greater (optional, for DICOM support) * `Python Imaging Library`_ (optional, for PNG conversion in DICOMFS) diff --git a/nibabel/affines.py b/nibabel/affines.py index 3a41bce972..6deab93ad3 100644 --- a/nibabel/affines.py +++ b/nibabel/affines.py @@ -5,7 +5,7 @@ import numpy as np -from .externals.six.moves import reduce +from six.moves import reduce class AffineError(ValueError): diff --git a/nibabel/benchmarks/bench_load_save.py b/nibabel/benchmarks/bench_load_save.py index 95efa22294..3198955674 100644 --- a/nibabel/benchmarks/bench_load_save.py +++ b/nibabel/benchmarks/bench_load_save.py @@ -19,7 +19,7 @@ import numpy as np -from ..externals.six import BytesIO +from six import BytesIO from .. import Nifti1Image diff --git a/nibabel/benchmarks/bench_streamlines.py b/nibabel/benchmarks/bench_streamlines.py index 3928fcfd4d..c076657d27 100644 --- a/nibabel/benchmarks/bench_streamlines.py +++ b/nibabel/benchmarks/bench_streamlines.py @@ -17,7 +17,7 @@ import numpy as np -from nibabel.externals.six.moves import zip +from six.moves import zip from nibabel.tmpdirs import InTemporaryDirectory from numpy.testing import assert_array_equal diff --git a/nibabel/data.py b/nibabel/data.py index e6e191901b..2a53f15f64 100644 --- a/nibabel/data.py +++ b/nibabel/data.py @@ -8,7 +8,7 @@ from os.path import join as pjoin import glob import sys -from .externals.six.moves import configparser +from six.moves import configparser from distutils.version import LooseVersion from .environment import get_nipy_user_dir, get_nipy_system_dir diff --git a/nibabel/dft.py b/nibabel/dft.py index 1efbca06b8..fc9e7fccd6 100644 --- a/nibabel/dft.py +++ b/nibabel/dft.py @@ -22,7 +22,7 @@ import numpy -from .externals.six import BytesIO +from six import BytesIO from .nifti1 import Nifti1Header diff --git a/nibabel/eulerangles.py b/nibabel/eulerangles.py index e633a6a22c..eac1c046ed 100644 --- a/nibabel/eulerangles.py +++ b/nibabel/eulerangles.py @@ -85,7 +85,7 @@ import math -from .externals.six.moves import reduce +from six.moves import reduce import numpy as np diff --git a/nibabel/externals/__init__.py b/nibabel/externals/__init__.py index 7eebe865dc..4c31772bb5 100644 --- a/nibabel/externals/__init__.py +++ b/nibabel/externals/__init__.py @@ -1,5 +1,5 @@ # init for externals package -try: - from collections import OrderedDict -except ImportError: # < Python 2.7 - from .ordereddict import OrderedDict +from collections import OrderedDict + +from ..deprecated import ModuleProxy as _ModuleProxy +six = _ModuleProxy('nibabel.externals.six') diff --git a/nibabel/externals/netcdf.py b/nibabel/externals/netcdf.py index 06375f8bdd..24b17706b8 100644 --- a/nibabel/externals/netcdf.py +++ b/nibabel/externals/netcdf.py @@ -35,13 +35,13 @@ from operator import mul from mmap import mmap, ACCESS_READ -import numpy as np +import numpy as np # noqa from ..py3k import asbytes, asstr from numpy import fromstring, ndarray, dtype, empty, array, asarray from numpy import little_endian as LITTLE_ENDIAN from functools import reduce -from .six import integer_types +from six import integer_types ABSENT = b'\x00\x00\x00\x00\x00\x00\x00\x00' diff --git a/nibabel/externals/ordereddict.py b/nibabel/externals/ordereddict.py deleted file mode 100644 index 66086c09b4..0000000000 --- a/nibabel/externals/ordereddict.py +++ /dev/null @@ -1,132 +0,0 @@ -# Copyright (c) 2009 Raymond Hettinger -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation files -# (the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, -# publish, distribute, sublicense, and/or sell copies of the Software, -# and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. - -# Allow Python3 to import module even though broken -# The following import checks are a modification from the original ordereddict -try: - from UserDict import DictMixin -except ImportError: - pass -else: - class OrderedDict(dict, DictMixin): - - def __init__(self, *args, **kwds): - if len(args) > 1: - raise TypeError('expected at most 1 arguments, got %d' % len(args)) - try: - self.__end - except AttributeError: - self.clear() - self.update(*args, **kwds) - - def clear(self): - self.__end = end = [] - end += [None, end, end] # sentinel node for doubly linked list - self.__map = {} # key --> [key, prev, next] - dict.clear(self) - - def __setitem__(self, key, value): - if key not in self: - end = self.__end - curr = end[1] - curr[2] = end[1] = self.__map[key] = [key, curr, end] - dict.__setitem__(self, key, value) - - def __delitem__(self, key): - dict.__delitem__(self, key) - key, prev, next = self.__map.pop(key) - prev[2] = next - next[1] = prev - - def __iter__(self): - end = self.__end - curr = end[2] - while curr is not end: - yield curr[0] - curr = curr[2] - - def __reversed__(self): - end = self.__end - curr = end[1] - while curr is not end: - yield curr[0] - curr = curr[1] - - def popitem(self, last=True): - if not self: - raise KeyError('dictionary is empty') - if last: - key = reversed(self).next() - else: - key = iter(self).next() - value = self.pop(key) - return key, value - - def __reduce__(self): - items = [[k, self[k]] for k in self] - tmp = self.__map, self.__end - del self.__map, self.__end - inst_dict = vars(self).copy() - self.__map, self.__end = tmp - if inst_dict: - return (self.__class__, (items,), inst_dict) - return self.__class__, (items,) - - def keys(self): - return list(self) - - setdefault = DictMixin.setdefault - update = DictMixin.update - pop = DictMixin.pop - values = DictMixin.values - items = DictMixin.items - iterkeys = DictMixin.iterkeys - itervalues = DictMixin.itervalues - iteritems = DictMixin.iteritems - - def __repr__(self): - if not self: - return '%s()' % (self.__class__.__name__,) - return '%s(%r)' % (self.__class__.__name__, self.items()) - - def copy(self): - return self.__class__(self) - - @classmethod - def fromkeys(cls, iterable, value=None): - d = cls() - for key in iterable: - d[key] = value - return d - - def __eq__(self, other): - if isinstance(other, OrderedDict): - if len(self) != len(other): - return False - for p, q in zip(self.items(), other.items()): - if p != q: - return False - return True - return dict.__eq__(self, other) - - def __ne__(self, other): - return not self == other diff --git a/nibabel/externals/six.py b/nibabel/externals/six.py index b23166effd..77e656cd67 100644 --- a/nibabel/externals/six.py +++ b/nibabel/externals/six.py @@ -1,405 +1,12 @@ -"""Utilities for writing code that runs on Python 2 and 3""" +""" Shim allowing some grace time for removal of six.py copy """ +# Remove around version 4.0 +from __future__ import absolute_import -# Copyright (c) 2010-2013 Benjamin Peterson -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import warnings -import operator -import sys -import types +warnings.warn("We no longer carry a copy of the 'six' package in nibabel; " + "Please import the 'six' package directly", + FutureWarning, + stacklevel=2) -__author__ = "Benjamin Peterson " -__version__ = "1.3.0" - - -# True if we are running on Python 3. -PY3 = sys.version_info[0] == 3 - -if PY3: - string_types = str, - integer_types = int, - class_types = type, - text_type = str - binary_type = bytes - - MAXSIZE = sys.maxsize -else: - string_types = basestring, - integer_types = (int, long) - class_types = (type, types.ClassType) - text_type = unicode - binary_type = str - - if sys.platform.startswith("java"): - # Jython always uses 32 bits. - MAXSIZE = int((1 << 31) - 1) - else: - # It's possible to have sizeof(long) != sizeof(Py_ssize_t). - class X(object): - def __len__(self): - return 1 << 31 - try: - len(X()) - except OverflowError: - # 32-bit - MAXSIZE = int((1 << 31) - 1) - else: - # 64-bit - MAXSIZE = int((1 << 63) - 1) - del X - - -def _add_doc(func, doc): - """Add documentation to a function.""" - func.__doc__ = doc - - -def _import_module(name): - """Import module, returning the module after the last dot.""" - __import__(name) - return sys.modules[name] - - -class _LazyDescr(object): - - def __init__(self, name): - self.name = name - - def __get__(self, obj, tp): - result = self._resolve() - setattr(obj, self.name, result) - # This is a bit ugly, but it avoids running this again. - delattr(tp, self.name) - return result - - -class MovedModule(_LazyDescr): - - def __init__(self, name, old, new=None): - super(MovedModule, self).__init__(name) - if PY3: - if new is None: - new = name - self.mod = new - else: - self.mod = old - - def _resolve(self): - return _import_module(self.mod) - - -class MovedAttribute(_LazyDescr): - - def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): - super(MovedAttribute, self).__init__(name) - if PY3: - if new_mod is None: - new_mod = name - self.mod = new_mod - if new_attr is None: - if old_attr is None: - new_attr = name - else: - new_attr = old_attr - self.attr = new_attr - else: - self.mod = old_mod - if old_attr is None: - old_attr = name - self.attr = old_attr - - def _resolve(self): - module = _import_module(self.mod) - return getattr(module, self.attr) - - - -class _MovedItems(types.ModuleType): - """Lazy loading of moved objects""" - - -_moved_attributes = [ - MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), - MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), - MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), - MovedAttribute("map", "itertools", "builtins", "imap", "map"), - MovedAttribute("reload_module", "__builtin__", "imp", "reload"), - MovedAttribute("reduce", "__builtin__", "functools"), - MovedAttribute("StringIO", "StringIO", "io"), - MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), - MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), - MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"), - - MovedModule("builtins", "__builtin__"), - MovedModule("configparser", "ConfigParser"), - MovedModule("copyreg", "copy_reg"), - MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), - MovedModule("http_cookies", "Cookie", "http.cookies"), - MovedModule("html_entities", "htmlentitydefs", "html.entities"), - MovedModule("html_parser", "HTMLParser", "html.parser"), - MovedModule("http_client", "httplib", "http.client"), - MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"), - MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"), - MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"), - MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), - MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"), - MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"), - MovedModule("cPickle", "cPickle", "pickle"), - MovedModule("queue", "Queue"), - MovedModule("reprlib", "repr"), - MovedModule("socketserver", "SocketServer"), - MovedModule("tkinter", "Tkinter"), - MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"), - MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"), - MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"), - MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"), - MovedModule("tkinter_tix", "Tix", "tkinter.tix"), - MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), - MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), - MovedModule("tkinter_colorchooser", "tkColorChooser", - "tkinter.colorchooser"), - MovedModule("tkinter_commondialog", "tkCommonDialog", - "tkinter.commondialog"), - MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), - MovedModule("tkinter_font", "tkFont", "tkinter.font"), - MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), - MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", - "tkinter.simpledialog"), - MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), - MovedModule("winreg", "_winreg"), -] -for attr in _moved_attributes: - setattr(_MovedItems, attr.name, attr) -del attr - -moves = sys.modules[__name__ + ".moves"] = _MovedItems("moves") - - -def add_move(move): - """Add an item to six.moves.""" - setattr(_MovedItems, move.name, move) - - -def remove_move(name): - """Remove item from six.moves.""" - try: - delattr(_MovedItems, name) - except AttributeError: - try: - del moves.__dict__[name] - except KeyError: - raise AttributeError("no such move, %r" % (name,)) - - -if PY3: - _meth_func = "__func__" - _meth_self = "__self__" - - _func_closure = "__closure__" - _func_code = "__code__" - _func_defaults = "__defaults__" - _func_globals = "__globals__" - - _iterkeys = "keys" - _itervalues = "values" - _iteritems = "items" - _iterlists = "lists" -else: - _meth_func = "im_func" - _meth_self = "im_self" - - _func_closure = "func_closure" - _func_code = "func_code" - _func_defaults = "func_defaults" - _func_globals = "func_globals" - - _iterkeys = "iterkeys" - _itervalues = "itervalues" - _iteritems = "iteritems" - _iterlists = "iterlists" - - -try: - advance_iterator = next -except NameError: - def advance_iterator(it): - return it.next() -next = advance_iterator - - -try: - callable = callable -except NameError: - def callable(obj): - return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) - - -if PY3: - def get_unbound_function(unbound): - return unbound - - Iterator = object -else: - def get_unbound_function(unbound): - return unbound.im_func - - class Iterator(object): - - def next(self): - return type(self).__next__(self) - - callable = callable -_add_doc(get_unbound_function, - """Get the function out of a possibly unbound function""") - - -get_method_function = operator.attrgetter(_meth_func) -get_method_self = operator.attrgetter(_meth_self) -get_function_closure = operator.attrgetter(_func_closure) -get_function_code = operator.attrgetter(_func_code) -get_function_defaults = operator.attrgetter(_func_defaults) -get_function_globals = operator.attrgetter(_func_globals) - - -def iterkeys(d, **kw): - """Return an iterator over the keys of a dictionary.""" - return iter(getattr(d, _iterkeys)(**kw)) - -def itervalues(d, **kw): - """Return an iterator over the values of a dictionary.""" - return iter(getattr(d, _itervalues)(**kw)) - -def iteritems(d, **kw): - """Return an iterator over the (key, value) pairs of a dictionary.""" - return iter(getattr(d, _iteritems)(**kw)) - -def iterlists(d, **kw): - """Return an iterator over the (key, [values]) pairs of a dictionary.""" - return iter(getattr(d, _iterlists)(**kw)) - - -if PY3: - def b(s): - return s.encode("latin-1") - def u(s): - return s - if sys.version_info[1] <= 1: - def int2byte(i): - return bytes((i,)) - else: - # This is about 2x faster than the implementation above on 3.2+ - int2byte = operator.methodcaller("to_bytes", 1, "big") - import io - StringIO = io.StringIO - BytesIO = io.BytesIO -else: - def b(s): - return s - def u(s): - return unicode(s, "unicode_escape") - int2byte = chr - import StringIO - StringIO = BytesIO = StringIO.StringIO -_add_doc(b, """Byte literal""") -_add_doc(u, """Text literal""") - - -if PY3: - import builtins - exec_ = getattr(builtins, "exec") - - - def reraise(tp, value, tb=None): - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value - - - print_ = getattr(builtins, "print") - del builtins - -else: - def exec_(_code_, _globs_=None, _locs_=None): - """Execute code in a namespace.""" - if _globs_ is None: - frame = sys._getframe(1) - _globs_ = frame.f_globals - if _locs_ is None: - _locs_ = frame.f_locals - del frame - elif _locs_ is None: - _locs_ = _globs_ - exec("""exec _code_ in _globs_, _locs_""") - - - exec_("""def reraise(tp, value, tb=None): - raise tp, value, tb -""") - - - def print_(*args, **kwargs): - """The new-style print function.""" - fp = kwargs.pop("file", sys.stdout) - if fp is None: - return - def write(data): - if not isinstance(data, basestring): - data = str(data) - fp.write(data) - want_unicode = False - sep = kwargs.pop("sep", None) - if sep is not None: - if isinstance(sep, unicode): - want_unicode = True - elif not isinstance(sep, str): - raise TypeError("sep must be None or a string") - end = kwargs.pop("end", None) - if end is not None: - if isinstance(end, unicode): - want_unicode = True - elif not isinstance(end, str): - raise TypeError("end must be None or a string") - if kwargs: - raise TypeError("invalid keyword arguments to print()") - if not want_unicode: - for arg in args: - if isinstance(arg, unicode): - want_unicode = True - break - if want_unicode: - newline = unicode("\n") - space = unicode(" ") - else: - newline = "\n" - space = " " - if sep is None: - sep = space - if end is None: - end = newline - for i, arg in enumerate(args): - if i: - write(sep) - write(arg) - write(end) - -_add_doc(reraise, """Reraise an exception.""") - - -def with_metaclass(meta, base=object): - """Create a base class with a metaclass.""" - return meta("NewBase", (base,), {}) +from six import * # noqa diff --git a/nibabel/externals/tests/test_ordereddict.py b/nibabel/externals/tests/test_ordereddict.py deleted file mode 100644 index df77b3aeb2..0000000000 --- a/nibabel/externals/tests/test_ordereddict.py +++ /dev/null @@ -1,21 +0,0 @@ -# Test ordered dict loading - -from os.path import dirname, relpath, realpath -import sys -import inspect - -from .. import OrderedDict - -from nose.tools import assert_equal, assert_true - -MY_PATH = dirname(realpath(__file__)) - -def test_right_version(): - # If Python < 2.7, use our own copy, else use system copy - if sys.version_info[:2] < (2, 7): - class_path = realpath(inspect.getfile(OrderedDict)) - rel_dir = dirname(relpath(class_path, MY_PATH)) - assert_equal(rel_dir, '..') - else: - import collections - assert_true(collections.OrderedDict is OrderedDict) diff --git a/nibabel/externals/tests/test_six.py b/nibabel/externals/tests/test_six.py new file mode 100644 index 0000000000..35db2ca851 --- /dev/null +++ b/nibabel/externals/tests/test_six.py @@ -0,0 +1,33 @@ +""" Test we are deprecating externals.six import +""" + +import warnings +import types + +from nose.tools import assert_true, assert_equal + +from nibabel.deprecated import ModuleProxy + + +def test_old_namespace(): + with warnings.catch_warnings(record=True) as warns: + # Top level import. + # This import does not trigger an import of the six.py module, because + # it's the proxy object. + from nibabel.externals import six + assert_equal(warns, []) + # If there was a previous import it will be module, otherwise it will be + # a proxy. + previous_import = isinstance(six, types.ModuleType) + if not previous_import: + assert_true(isinstance(six, ModuleProxy)) + shim_BytesIO = six.BytesIO # just to check it works + # There may or may not be a warning raised on accessing the proxy, + # depending on whether the externals.six.py module is already imported + # in this test run. + if not previous_import: + assert_equal(warns.pop(0).category, FutureWarning) + from six import BytesIO + assert_equal(warns, []) + # The import from old module is the same as that from new + assert_true(shim_BytesIO is BytesIO) diff --git a/nibabel/filebasedimages.py b/nibabel/filebasedimages.py index 5e5d22fee7..3517845137 100644 --- a/nibabel/filebasedimages.py +++ b/nibabel/filebasedimages.py @@ -8,7 +8,7 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## ''' Common interface for any image format--volume or surface, binary or xml.''' -from .externals.six import string_types +from six import string_types from .fileholders import FileHolder from .filename_parser import (types_filenames, TypesFilenamesError, splitext_addext) diff --git a/nibabel/fileslice.py b/nibabel/fileslice.py index a0c28b68bd..ee72b83c99 100644 --- a/nibabel/fileslice.py +++ b/nibabel/fileslice.py @@ -6,7 +6,7 @@ from numbers import Integral from mmap import mmap -from .externals.six.moves import reduce +from six.moves import reduce import numpy as np diff --git a/nibabel/freesurfer/io.py b/nibabel/freesurfer/io.py index 127a4acf8b..970d7adc6e 100644 --- a/nibabel/freesurfer/io.py +++ b/nibabel/freesurfer/io.py @@ -7,8 +7,8 @@ import getpass import time -from ..externals import OrderedDict -from ..externals.six.moves import xrange +from collections import OrderedDict +from six.moves import xrange from ..openers import Opener diff --git a/nibabel/freesurfer/tests/test_mghformat.py b/nibabel/freesurfer/tests/test_mghformat.py index 9683148e5f..2fb9ecf0d4 100644 --- a/nibabel/freesurfer/tests/test_mghformat.py +++ b/nibabel/freesurfer/tests/test_mghformat.py @@ -13,7 +13,7 @@ import numpy as np -from ...externals.six import BytesIO +from six import BytesIO from .. import load, save from ...openers import ImageOpener from ..mghformat import MGHHeader, MGHError, MGHImage diff --git a/nibabel/gifti/parse_gifti_fast.py b/nibabel/gifti/parse_gifti_fast.py index 234c8dc0a1..e69b6b204f 100644 --- a/nibabel/gifti/parse_gifti_fast.py +++ b/nibabel/gifti/parse_gifti_fast.py @@ -12,7 +12,7 @@ import sys import warnings import zlib -from ..externals.six import StringIO +from six import StringIO from xml.parsers.expat import ExpatError import numpy as np diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index 3c7bcdaca0..f1285d441d 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -7,7 +7,7 @@ import numpy as np import nibabel as nib -from nibabel.externals.six import string_types +from six import string_types from nibabel.gifti import (GiftiImage, GiftiDataArray, GiftiLabel, GiftiLabelTable, GiftiMetaData, GiftiNVPairs, GiftiCoordSystem) diff --git a/nibabel/info.py b/nibabel/info.py index 5a55e12fec..956361f13d 100644 --- a/nibabel/info.py +++ b/nibabel/info.py @@ -188,6 +188,7 @@ def cmp_pkg_version(version_str, pkg_version_str=__version__): # .travis.yml NUMPY_MIN_VERSION = '1.6.0' PYDICOM_MIN_VERSION = '0.9.7' +SIX_MIN_VERSION = '1.3' # Main setup parameters NAME = 'nibabel' diff --git a/nibabel/optpkg.py b/nibabel/optpkg.py index f0b6988d7c..51e2f84624 100644 --- a/nibabel/optpkg.py +++ b/nibabel/optpkg.py @@ -1,7 +1,7 @@ """ Routines to support optional packages """ from distutils.version import LooseVersion -from .externals.six import string_types, callable +from six import string_types, callable try: import nose diff --git a/nibabel/parrec.py b/nibabel/parrec.py index c9c1568941..1819b257ef 100644 --- a/nibabel/parrec.py +++ b/nibabel/parrec.py @@ -129,7 +129,7 @@ import re from io import StringIO from locale import getpreferredencoding -from nibabel.externals import OrderedDict +from collections import OrderedDict from .keywordonly import kw_only_meth from .spatialimages import SpatialHeader, SpatialImage diff --git a/nibabel/py3k.py b/nibabel/py3k.py index f896368fa9..1c3300ac91 100644 --- a/nibabel/py3k.py +++ b/nibabel/py3k.py @@ -1,9 +1,9 @@ """ Python 3 compatibility tools. -Copied from numpy/compat/py3k +Copied from numpy/compat/py3k. -Please prefer the routines in externals/six.py when possible +Please prefer the routines in the six module when possible. BSD license """ diff --git a/nibabel/spm99analyze.py b/nibabel/spm99analyze.py index bb92305d18..b0df20f553 100644 --- a/nibabel/spm99analyze.py +++ b/nibabel/spm99analyze.py @@ -10,7 +10,7 @@ import warnings import numpy as np -from .externals.six import BytesIO +from six import BytesIO from .spatialimages import HeaderDataError, HeaderTypeError diff --git a/nibabel/streamlines/__init__.py b/nibabel/streamlines/__init__.py index 8ba95a41af..b0a6b744bb 100644 --- a/nibabel/streamlines/__init__.py +++ b/nibabel/streamlines/__init__.py @@ -2,7 +2,7 @@ """ import os import warnings -from ..externals.six import string_types +from six import string_types from .header import Field from .array_sequence import ArraySequence diff --git a/nibabel/streamlines/tests/test_streamlines.py b/nibabel/streamlines/tests/test_streamlines.py index c2f1c066d3..5f38e3979a 100644 --- a/nibabel/streamlines/tests/test_streamlines.py +++ b/nibabel/streamlines/tests/test_streamlines.py @@ -6,7 +6,7 @@ from os.path import join as pjoin import nibabel as nib -from nibabel.externals.six import BytesIO +from six import BytesIO from nibabel.tmpdirs import InTemporaryDirectory from nibabel.testing import data_path diff --git a/nibabel/streamlines/tests/test_tractogram.py b/nibabel/streamlines/tests/test_tractogram.py index fef38c513e..e970dd1d11 100644 --- a/nibabel/streamlines/tests/test_tractogram.py +++ b/nibabel/streamlines/tests/test_tractogram.py @@ -10,7 +10,7 @@ from nibabel.testing import clear_and_catch_warnings from nose.tools import assert_equal, assert_raises, assert_true from numpy.testing import assert_array_equal, assert_array_almost_equal -from nibabel.externals.six.moves import zip +from six.moves import zip from .. import tractogram as module_tractogram from ..tractogram import TractogramItem, Tractogram, LazyTractogram diff --git a/nibabel/streamlines/tests/test_trk.py b/nibabel/streamlines/tests/test_trk.py index f890021689..eeed4cf505 100644 --- a/nibabel/streamlines/tests/test_trk.py +++ b/nibabel/streamlines/tests/test_trk.py @@ -4,7 +4,7 @@ import numpy as np from os.path import join as pjoin -from nibabel.externals.six import BytesIO +from six import BytesIO from nibabel.testing import data_path from nibabel.testing import clear_and_catch_warnings, assert_arr_dict_equal diff --git a/nibabel/streamlines/tractogram_file.py b/nibabel/streamlines/tractogram_file.py index a1dc4e83fb..037d25f1ff 100644 --- a/nibabel/streamlines/tractogram_file.py +++ b/nibabel/streamlines/tractogram_file.py @@ -1,7 +1,7 @@ """ Define abstract interface for Tractogram file classes """ from abc import ABCMeta, abstractmethod -from nibabel.externals.six import with_metaclass +from six import with_metaclass from .header import Field diff --git a/nibabel/testing/__init__.py b/nibabel/testing/__init__.py index 2200b25182..2c6574da97 100644 --- a/nibabel/testing/__init__.py +++ b/nibabel/testing/__init__.py @@ -26,7 +26,7 @@ except ImportError: pass -from nibabel.externals.six.moves import zip_longest +from six.moves import zip_longest # set path to example data data_path = abspath(pjoin(dirname(__file__), '..', 'tests', 'data')) diff --git a/nibabel/tests/test_analyze.py b/nibabel/tests/test_analyze.py index 17e7b07719..da89808e4f 100644 --- a/nibabel/tests/test_analyze.py +++ b/nibabel/tests/test_analyze.py @@ -20,7 +20,7 @@ import numpy as np -from ..externals.six import BytesIO, StringIO +from six import BytesIO, StringIO from ..spatialimages import (HeaderDataError, HeaderTypeError, supported_np_types) from ..analyze import AnalyzeHeader, AnalyzeImage diff --git a/nibabel/tests/test_api_validators.py b/nibabel/tests/test_api_validators.py index f2dcaa3623..affa89d3e3 100644 --- a/nibabel/tests/test_api_validators.py +++ b/nibabel/tests/test_api_validators.py @@ -2,7 +2,7 @@ """ from __future__ import division, print_function, absolute_import -from ..externals.six import with_metaclass +from six import with_metaclass from nose.tools import assert_equal diff --git a/nibabel/tests/test_arrayproxy.py b/nibabel/tests/test_arrayproxy.py index abc7856623..86f7c7f9b5 100644 --- a/nibabel/tests/test_arrayproxy.py +++ b/nibabel/tests/test_arrayproxy.py @@ -12,7 +12,7 @@ import warnings -from ..externals.six import BytesIO +from six import BytesIO from ..tmpdirs import InTemporaryDirectory import numpy as np diff --git a/nibabel/tests/test_arraywriters.py b/nibabel/tests/test_arraywriters.py index 2f06f3a682..79c3a86088 100644 --- a/nibabel/tests/test_arraywriters.py +++ b/nibabel/tests/test_arraywriters.py @@ -10,7 +10,7 @@ import itertools import numpy as np -from ..externals.six import BytesIO +from six import BytesIO from ..arraywriters import (SlopeInterArrayWriter, SlopeArrayWriter, WriterError, ScalingError, ArrayWriter, make_array_writer, get_slope_inter) diff --git a/nibabel/tests/test_batteryrunners.py b/nibabel/tests/test_batteryrunners.py index 8f1710f779..71cbbba072 100644 --- a/nibabel/tests/test_batteryrunners.py +++ b/nibabel/tests/test_batteryrunners.py @@ -9,7 +9,7 @@ ''' Tests for BatteryRunner and Report objects ''' -from ..externals.six import StringIO +from six import StringIO import logging diff --git a/nibabel/tests/test_dft.py b/nibabel/tests/test_dft.py index 9a164549a9..b350d6bdc9 100644 --- a/nibabel/tests/test_dft.py +++ b/nibabel/tests/test_dft.py @@ -3,7 +3,7 @@ import os from os.path import join as pjoin, dirname -from ..externals.six import BytesIO +from six import BytesIO from ..testing import suppress_warnings import numpy as np diff --git a/nibabel/tests/test_fileholders.py b/nibabel/tests/test_fileholders.py index 0069eef36a..47b6072a80 100644 --- a/nibabel/tests/test_fileholders.py +++ b/nibabel/tests/test_fileholders.py @@ -1,7 +1,7 @@ """ Testing fileholders """ -from ..externals.six import BytesIO +from six import BytesIO from ..fileholders import FileHolder diff --git a/nibabel/tests/test_files_interface.py b/nibabel/tests/test_files_interface.py index 788be6a31a..765e4410f2 100644 --- a/nibabel/tests/test_files_interface.py +++ b/nibabel/tests/test_files_interface.py @@ -13,7 +13,7 @@ import numpy as np from .. import Nifti1Image, Nifti1Pair, MGHImage, all_image_classes -from ..externals.six import BytesIO +from six import BytesIO from ..fileholders import FileHolderError from ..spatialimages import SpatialImage diff --git a/nibabel/tests/test_image_api.py b/nibabel/tests/test_image_api.py index e86b8c8ea7..a76cb2737b 100644 --- a/nibabel/tests/test_image_api.py +++ b/nibabel/tests/test_image_api.py @@ -24,7 +24,7 @@ import warnings from functools import partial -from ..externals.six import string_types +from six import string_types import numpy as np diff --git a/nibabel/tests/test_image_load_save.py b/nibabel/tests/test_image_load_save.py index d43d1ee581..6960bb9c81 100644 --- a/nibabel/tests/test_image_load_save.py +++ b/nibabel/tests/test_image_load_save.py @@ -8,7 +8,7 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## ''' Tests for loader function ''' from __future__ import division, print_function, absolute_import -from ..externals.six import BytesIO +from six import BytesIO import shutil from os.path import dirname, join as pjoin diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index 6aab35aff0..a4b5ab98ab 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -18,7 +18,7 @@ from nibabel.affines import from_matvec from nibabel.casting import type_info, have_binary128 from nibabel.eulerangles import euler2mat -from nibabel.externals.six import BytesIO +from six import BytesIO from nibabel.nifti1 import (load, Nifti1Header, Nifti1PairHeader, Nifti1Image, Nifti1Pair, Nifti1Extension, Nifti1DicomExtension, Nifti1Extensions, data_type_codes, extension_codes, diff --git a/nibabel/tests/test_proxy_api.py b/nibabel/tests/test_proxy_api.py index 7825f7faff..b6fd1a004c 100644 --- a/nibabel/tests/test_proxy_api.py +++ b/nibabel/tests/test_proxy_api.py @@ -35,7 +35,7 @@ import numpy as np -from ..externals.six import string_types +from six import string_types from ..volumeutils import apply_read_scaling from ..analyze import AnalyzeHeader from ..spm99analyze import Spm99AnalyzeHeader diff --git a/nibabel/tests/test_round_trip.py b/nibabel/tests/test_round_trip.py index f60c9e9362..c6ba5ead96 100644 --- a/nibabel/tests/test_round_trip.py +++ b/nibabel/tests/test_round_trip.py @@ -5,7 +5,7 @@ import numpy as np -from ..externals.six import BytesIO +from six import BytesIO from .. import Nifti1Image, Nifti1Header from ..spatialimages import HeaderDataError, supported_np_types from ..arraywriters import ScalingError diff --git a/nibabel/tests/test_scaling.py b/nibabel/tests/test_scaling.py index 0d7395fb88..3a201db699 100644 --- a/nibabel/tests/test_scaling.py +++ b/nibabel/tests/test_scaling.py @@ -11,7 +11,7 @@ import numpy as np -from ..externals.six import BytesIO +from six import BytesIO from ..volumeutils import (calculate_scale, scale_min_max, finite_range, apply_read_scaling, array_to_file, array_from_file) from ..casting import type_info diff --git a/nibabel/tests/test_spatialimages.py b/nibabel/tests/test_spatialimages.py index 75c4f6e535..80b79c5318 100644 --- a/nibabel/tests/test_spatialimages.py +++ b/nibabel/tests/test_spatialimages.py @@ -14,7 +14,7 @@ import numpy as np -from ..externals.six import BytesIO +from six import BytesIO from ..spatialimages import (SpatialHeader, SpatialImage, HeaderDataError, Header, ImageDataError) diff --git a/nibabel/tests/test_spm99analyze.py b/nibabel/tests/test_spm99analyze.py index f810fb659e..e1be6200fb 100644 --- a/nibabel/tests/test_spm99analyze.py +++ b/nibabel/tests/test_spm99analyze.py @@ -10,7 +10,7 @@ import numpy as np import itertools -from ..externals.six import BytesIO +from six import BytesIO from numpy.testing import assert_array_equal, assert_array_almost_equal, dec diff --git a/nibabel/tests/test_trackvis.py b/nibabel/tests/test_trackvis.py index 1a240957ab..2e3f0a8adb 100644 --- a/nibabel/tests/test_trackvis.py +++ b/nibabel/tests/test_trackvis.py @@ -5,7 +5,7 @@ import numpy as np -from ..externals.six import BytesIO +from six import BytesIO from .. import trackvis as tv from ..orientations import aff2axcodes from ..volumeutils import native_code, swapped_code diff --git a/nibabel/tests/test_utils.py b/nibabel/tests/test_utils.py index f9b7fda632..cf14239f8e 100644 --- a/nibabel/tests/test_utils.py +++ b/nibabel/tests/test_utils.py @@ -12,7 +12,7 @@ import os from os.path import exists -from ..externals.six import BytesIO +from six import BytesIO import tempfile import warnings import functools diff --git a/nibabel/tests/test_wrapstruct.py b/nibabel/tests/test_wrapstruct.py index a2f1d6c2de..5ea346dab9 100644 --- a/nibabel/tests/test_wrapstruct.py +++ b/nibabel/tests/test_wrapstruct.py @@ -26,7 +26,7 @@ import logging import numpy as np -from ..externals.six import BytesIO, StringIO +from six import BytesIO, StringIO from ..wrapstruct import WrapStructError, WrapStruct, LabeledWrapStruct from ..batteryrunners import Report diff --git a/requirements.txt b/requirements.txt index 28c0ee779a..4faf1a105c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ # .travis.yml # doc/source/installation.rst -numpy>=1.5.1 +six>=1.3 +numpy>=1.6 From 38d8235ba32eed1c1d3793f404d7bc9faa8ecdca Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Sat, 11 Feb 2017 22:44:47 +0000 Subject: [PATCH 3/3] RF: use native versions of callable, io classes Use native versions rather using using versions from 'six'. --- nibabel/benchmarks/bench_load_save.py | 2 +- nibabel/gifti/parse_gifti_fast.py | 2 +- nibabel/optpkg.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nibabel/benchmarks/bench_load_save.py b/nibabel/benchmarks/bench_load_save.py index 3198955674..c2ee68578a 100644 --- a/nibabel/benchmarks/bench_load_save.py +++ b/nibabel/benchmarks/bench_load_save.py @@ -19,7 +19,7 @@ import numpy as np -from six import BytesIO +from io import BytesIO from .. import Nifti1Image diff --git a/nibabel/gifti/parse_gifti_fast.py b/nibabel/gifti/parse_gifti_fast.py index e69b6b204f..4cdbd3d768 100644 --- a/nibabel/gifti/parse_gifti_fast.py +++ b/nibabel/gifti/parse_gifti_fast.py @@ -12,7 +12,7 @@ import sys import warnings import zlib -from six import StringIO +from io import StringIO from xml.parsers.expat import ExpatError import numpy as np diff --git a/nibabel/optpkg.py b/nibabel/optpkg.py index 51e2f84624..794960ddc3 100644 --- a/nibabel/optpkg.py +++ b/nibabel/optpkg.py @@ -1,7 +1,7 @@ """ Routines to support optional packages """ from distutils.version import LooseVersion -from six import string_types, callable +from six import string_types try: import nose