Skip to content

Commit

Permalink
Merge pull request #787 from effigies/maint/purge_python2
Browse files Browse the repository at this point in the history
MAINT: Require Python >= 3.5, purge Python 2 compatibility
  • Loading branch information
effigies authored Aug 17, 2019
2 parents 10ad38a + 6c66c6a commit 7c69442
Show file tree
Hide file tree
Showing 118 changed files with 148 additions and 602 deletions.
41 changes: 12 additions & 29 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,76 +22,59 @@ env:
- EXTRA_PIP_FLAGS="--find-links=$EXTRA_WHEELS"
- PRE_PIP_FLAGS="--pre $EXTRA_PIP_FLAGS --find-links $PRE_WHEELS"
python:
- 3.5
- 3.6
- 3.7
matrix:
include:
- python: 3.4
dist: trusty
sudo: false
# Absolute minimum dependencies
- python: 2.7
- python: 3.5
env:
- DEPENDS="numpy==1.8 setuptools==30.3.0"
- DEPENDS="-r min-requirements.txt setuptools==30.3.0"
# Absolute minimum dependencies
- python: 2.7
- python: 3.5
env:
- DEPENDS="numpy==1.8"
- DEPENDS="-r min-requirements.txt"
- CHECK_TYPE="import"
# Absolute minimum dependencies plus oldest MPL
# Check these against:
# nibabel/info.py
# doc/source/installation.rst
# requirements.txt
- python: 2.7
- python: 3.5
env:
- DEPENDS="numpy==1.8 matplotlib==1.3.1"
- DEPENDS="-r min-requirements.txt matplotlib==1.3.1"
# Minimum pydicom dependency
- python: 2.7
- python: 3.5
env:
- DEPENDS="numpy==1.8 pydicom==0.9.9 pillow==2.6"
- DEPENDS="-r min-requirements.txt pydicom==0.9.9 pillow==2.6"
# pydicom master branch
- python: 3.5
env:
- DEPENDS="numpy git+https://github.com/pydicom/pydicom.git@master"
# test 2.7 against pre-release builds of everything
- python: 2.7
env:
- EXTRA_PIP_FLAGS="$PRE_PIP_FLAGS"
# test 3.5 against pre-release builds of everything
- python: 3.5
env:
- EXTRA_PIP_FLAGS="$PRE_PIP_FLAGS"
- python: 2.7
- python: 3.5
env:
- INSTALL_TYPE=sdist
- python: 2.7
- python: 3.5
env:
- INSTALL_TYPE=wheel
- python: 2.7
- python: 3.5
env:
- INSTALL_TYPE=requirements
- python: 2.7
- python: 3.5
env:
- INSTALL_TYPE=archive
- python: 2.7
env:
- CHECK_TYPE="style"
- python: 3.5
env:
- CHECK_TYPE="style"
# Documentation doctests
- python: 2.7
env:
- CHECK_TYPE="doc_doctests"
- python: 3.5
env:
- CHECK_TYPE="doc_doctests"
# Run tests with indexed_gzip present
- python: 2.7
env:
- OPTIONAL_DEPENDS="indexed_gzip"
- python: 3.5
env:
- OPTIONAL_DEPENDS="indexed_gzip"
Expand Down
31 changes: 0 additions & 31 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -218,34 +218,3 @@ the PDDL version 1.0 available at http://opendatacommons.org/licenses/pddl/1.0/

is courtesy of the University of Massachusetts Medical School, also released
under the PDDL.


Six
--------------------

In ``nibabel/externals/six.py``

Copied from: https://pypi.python.org/packages/source/s/six/six-1.3.0.tar.gz#md5=ec47fe6070a8a64c802363d2c2b1e2ee

::

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.


12 changes: 4 additions & 8 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,10 @@ is for you.
Requirements
------------

.. check these against:
nibabel/info.py
requirements.txt
.travis.yml
* Python_ 2.7, or >= 3.4
* NumPy_ 1.8 or greater
* Six_ 1.3 or greater
.. check these against setup.cfg
* Python_ 3.5.1 or greater
* NumPy_ 1.12 or greater
* SciPy_ (optional, for full SPM-ANALYZE support)
* PyDICOM_ 0.9.9 or greater (optional, for DICOM support)
* `Python Imaging Library`_ (optional, for PNG conversion in DICOMFS)
Expand Down
1 change: 0 additions & 1 deletion doc/source/scripts/make_coord_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* someones_epi.nii.gz (pretend single EPI volume)
* someones_anatomy.nii.gz (pretend single subject structural)
"""
from __future__ import division, print_function

import math

Expand Down
1 change: 0 additions & 1 deletion doc/tools/build_modref_templates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
"""Script to auto-generate our API docs.
"""
from __future__ import print_function, division

# stdlib imports
import sys
Expand Down
2 changes: 2 additions & 0 deletions min-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto-generated by tools/update_requirements.py
numpy ==1.12
2 changes: 1 addition & 1 deletion nibabel/affines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np

from six.moves import reduce
from functools import reduce


class AffineError(ValueError):
Expand Down
1 change: 0 additions & 1 deletion nibabel/arraywriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, array, out_dtype=None)
something else to make sense of conversions between float and int, or between
larger ints and smaller.
"""
from __future__ import division, absolute_import

import warnings

Expand Down
1 change: 0 additions & 1 deletion nibabel/benchmarks/bench_array_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
nosetests -s --match '(?:^|[\\b_\\.//-])[Bb]ench' /path/to/bench_load_save.py
"""
from __future__ import division, print_function

import sys
from io import BytesIO # NOQA
Expand Down
1 change: 0 additions & 1 deletion nibabel/benchmarks/bench_fileslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
nosetests -s --match '(?:^|[\\b_\\.//-])[Bb]ench' /path/to/bench_fileslice.py
"""
from __future__ import division, print_function

import sys
from timeit import timeit
Expand Down
1 change: 0 additions & 1 deletion nibabel/benchmarks/bench_finite_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
nosetests -s --match '(?:^|[\\b_\\.//-])[Bb]ench' /path/to/bench_finite_range
"""
from __future__ import division, print_function

import sys

Expand Down
1 change: 0 additions & 1 deletion nibabel/benchmarks/bench_load_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
nosetests -s --match '(?:^|[\\b_\\.//-])[Bb]ench' /path/to/bench_load_save.py
"""
from __future__ import division, print_function

import sys

Expand Down
2 changes: 0 additions & 2 deletions nibabel/benchmarks/bench_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
nosetests -s --match '(?:^|[\\b_\\.//-])[Bb]ench' /path/to/bench_streamlines.py
"""
from __future__ import division, print_function

import numpy as np

from six.moves import zip
from nibabel.tmpdirs import InTemporaryDirectory

from numpy.testing import assert_array_equal
Expand Down
1 change: 0 additions & 1 deletion nibabel/benchmarks/butils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Benchmarking utilities
"""
from __future__ import print_function, division

from .. import get_info

Expand Down
4 changes: 1 addition & 3 deletions nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@
am aware) always be >= 1. This permits sub-brick indexing common in AFNI
programs (e.g., example4d+orig'[0]').
"""
from __future__ import print_function, division

from copy import deepcopy
import os
import re

import numpy as np
from six import string_types

from .arrayproxy import ArrayProxy
from .fileslice import strided_scalar
Expand Down Expand Up @@ -204,7 +202,7 @@ def parse_AFNI_header(fobj):
[1, 1, 1]
"""
# edge case for being fed a filename instead of a file object
if isinstance(fobj, string_types):
if isinstance(fobj, str):
with open(fobj, 'rt') as src:
return parse_AFNI_header(src)
# unpack variables in HEAD file
Expand Down
1 change: 0 additions & 1 deletion nibabel/checkwarns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
''' Contexts for *with* statement allowing checks for warnings
'''
from __future__ import division, print_function

import warnings

Expand Down
7 changes: 1 addition & 6 deletions nibabel/cifti2/cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
http://www.nitrc.org/projects/cifti
'''
from __future__ import division, print_function, absolute_import
import re
try:
from collections.abc import MutableSequence, MutableMapping, Iterable
except ImportError:
# PY2 compatibility
from collections import MutableSequence, MutableMapping, Iterable
from collections.abc import MutableSequence, MutableMapping, Iterable
from collections import OrderedDict
from .. import xmlutils as xml
from ..filebasedimages import FileBasedHeader
Expand Down
26 changes: 12 additions & 14 deletions nibabel/cifti2/cifti2_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
"""
import numpy as np
from . import cifti2
from six import string_types, add_metaclass, integer_types
from operator import xor
import abc

Expand Down Expand Up @@ -173,8 +172,7 @@ def to_header(axes):
return cifti2.Cifti2Header(matrix)


@add_metaclass(abc.ABCMeta)
class Axis(object):
class Axis(abc.ABC):
"""
Abstract class for any object describing the rows or columns of a CIFTI-2 vector/matrix
Expand Down Expand Up @@ -289,7 +287,7 @@ def __init__(self, name, voxel=None, vertex=None, affine=None,
else:
self.vertex = np.asanyarray(vertex, dtype=int)

if isinstance(name, string_types):
if isinstance(name, str):
name = [self.to_cifti_brain_structure_name(name)] * self.vertex.size
self.name = np.asanyarray(name, dtype='U')

Expand Down Expand Up @@ -505,7 +503,7 @@ def to_cifti_brain_structure_name(name):
"""
if name in cifti2.CIFTI_BRAIN_STRUCTURES:
return name
if not isinstance(name, string_types):
if not isinstance(name, str):
if len(name) == 1:
structure = name[0]
orientation = 'both'
Expand Down Expand Up @@ -589,7 +587,7 @@ def volume_shape(self, value):
value = tuple(value)
if len(value) != 3:
raise ValueError("Volume shape should be a tuple of length 3")
if not all(isinstance(v, integer_types) for v in value):
if not all(isinstance(v, int) for v in value):
raise ValueError("All elements of the volume shape should be integers")
self._volume_shape = value

Expand Down Expand Up @@ -679,9 +677,9 @@ def __getitem__(self, item):
Otherwise returns a new BrainModelAxis
"""
if isinstance(item, integer_types):
if isinstance(item, int):
return self.get_element(item)
if isinstance(item, string_types):
if isinstance(item, str):
raise IndexError("Can not index an Axis with a string (except for ParcelsAxis)")
return self.__class__(self.name[item], self.voxel[item], self.vertex[item],
self.affine, self.volume_shape, self.nvertices)
Expand Down Expand Up @@ -914,7 +912,7 @@ def volume_shape(self, value):
value = tuple(value)
if len(value) != 3:
raise ValueError("Volume shape should be a tuple of length 3")
if not all(isinstance(v, integer_types) for v in value):
if not all(isinstance(v, int) for v in value):
raise ValueError("All elements of the volume shape should be integers")
self._volume_shape = value

Expand Down Expand Up @@ -989,14 +987,14 @@ def __getitem__(self, item):
- `string`: 2-element tuple of (parcel voxels, parcel vertices
- other object that can index 1D arrays: new Parcel axis
"""
if isinstance(item, string_types):
if isinstance(item, str):
idx = np.where(self.name == item)[0]
if len(idx) == 0:
raise IndexError("Parcel %s not found" % item)
if len(idx) > 1:
raise IndexError("Multiple parcels with name %s found" % item)
return self.voxels[idx[0]], self.vertices[idx[0]]
if isinstance(item, integer_types):
if isinstance(item, int):
return self.get_element(item)
return self.__class__(self.name[item], self.voxels[item], self.vertices[item],
self.affine, self.volume_shape, self.nvertices)
Expand Down Expand Up @@ -1125,7 +1123,7 @@ def __add__(self, other):
)

def __getitem__(self, item):
if isinstance(item, integer_types):
if isinstance(item, int):
return self.get_element(item)
return self.__class__(self.name[item], self.meta[item])

Expand Down Expand Up @@ -1270,7 +1268,7 @@ def __add__(self, other):
)

def __getitem__(self, item):
if isinstance(item, integer_types):
if isinstance(item, int):
return self.get_element(item)
return self.__class__(self.name[item], self.label[item], self.meta[item])

Expand Down Expand Up @@ -1437,7 +1435,7 @@ def __getitem__(self, item):
nelements = 0
return SeriesAxis(idx_start * self.step + self.start, self.step * step,
nelements, self.unit)
elif isinstance(item, integer_types):
elif isinstance(item, int):
return self.get_element(item)
raise IndexError('SeriesAxis can only be indexed with integers or slices '
'without breaking the regular structure')
Expand Down
1 change: 0 additions & 1 deletion nibabel/cifti2/parse_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
from __future__ import division, print_function, absolute_import

from distutils.version import LooseVersion

Expand Down
Loading

0 comments on commit 7c69442

Please sign in to comment.