Skip to content

Commit 7958c0a

Browse files
authored
Merge pull request #917 from jond01/remove-py2
MNT: Fix configparser + python 2 deprecations
2 parents 3d692e3 + c37d52f commit 7958c0a

File tree

9 files changed

+24
-36
lines changed

9 files changed

+24
-36
lines changed

doc/source/devel/register_me.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from os.path import join as pjoin, expanduser, abspath, dirname
22
import sys
3-
# Python 3 compatibility
4-
try:
5-
import configparser as cfp
6-
except ImportError:
7-
import ConfigParser as cfp
3+
import configparser as cfp
4+
85

96
if sys.platform == 'win32':
107
HOME_INI = pjoin(expanduser('~'), '_dpkg', 'local.dsource')
@@ -15,6 +12,7 @@
1512
OUR_META = pjoin(OUR_PATH, 'meta.ini')
1613
DISCOVER_INIS = {'user': HOME_INI, 'system': SYS_INI}
1714

15+
1816
def main():
1917
# Get ini file to which to write
2018
try:
@@ -23,7 +21,7 @@ def main():
2321
reg_to = 'user'
2422
if reg_to in ('user', 'system'):
2523
ini_fname = DISCOVER_INIS[reg_to]
26-
else: # it is an ini file name
24+
else: # it is an ini file name
2725
ini_fname = reg_to
2826

2927
# Read parameters for our distribution
@@ -42,7 +40,7 @@ def main():
4240
dsource.set(name, version, OUR_PATH)
4341
dsource.write(file(ini_fname, 'wt'))
4442

45-
print 'Registered package %s, %s to %s' % (name, version, ini_fname)
43+
print('Registered package %s, %s to %s' % (name, version, ini_fname))
4644

4745

4846
if __name__ == '__main__':

nibabel/arrayproxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ArrayProxy(object):
7979
* get_slope_inter
8080
8181
A header should also have a 'copy' method. This requirement will go away
82-
when the deprecated 'header' propoerty goes away.
82+
when the deprecated 'header' property goes away.
8383
8484
This implementation allows us to deal with Analyze and its variants,
8585
including Nifti1, and with the MGH format.

nibabel/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(self, base_path, config_filename=None):
124124
Datasource.__init__(self, base_path)
125125
if config_filename is None:
126126
config_filename = 'config.ini'
127-
self.config = configparser.SafeConfigParser()
127+
self.config = configparser.ConfigParser()
128128
cfg_file = self.get_filename(config_filename)
129129
readfiles = self.config.read(cfg_file)
130130
if not readfiles:

nibabel/ecat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def get_shape(self, frame=0):
543543
x = subhdr['x_dimension'].item()
544544
y = subhdr['y_dimension'].item()
545545
z = subhdr['z_dimension'].item()
546-
return (x, y, z)
546+
return x, y, z
547547

548548
def get_nframes(self):
549549
"""returns number of frames"""

nibabel/tests/test_round_trip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def check_arr(test_id, V_in, in_type, out_type, scaling_type):
138138
rel_err = np.abs(top / arr)
139139
abs_err = np.abs(top)
140140
if slope == 1: # integers output, offset only scaling
141-
if set((in_type, out_type)) == set((np.int64, np.uint64)):
141+
if {in_type, out_type} == {np.int64, np.uint64}:
142142
# Scaling to or from 64 bit ints can go outside range of continuous
143143
# integers for float64 and thus lose precision; take this into
144144
# account
@@ -181,14 +181,14 @@ def check_arr(test_id, V_in, in_type, out_type, scaling_type):
181181
rel_mx_e = rel_err[abs_fails].max()
182182
else:
183183
rel_mx_e = None
184-
print (test_id,
184+
print((test_id,
185185
np.dtype(in_type).str,
186186
np.dtype(out_type).str,
187187
exp_abs_mx_e,
188188
abs_mx_e,
189189
rel_thresh,
190190
rel_mx_e,
191-
slope, inter)
191+
slope, inter))
192192
# To help debugging failures with --pdb-failure
193193
np.nonzero(all_fails)
194194
assert this_test

nisext/sexts.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22

33
import os
44
from os.path import join as pjoin, split as psplit, splitext
5-
import sys
6-
PY3 = sys.version_info[0] >= 3
7-
if PY3:
8-
string_types = str,
9-
else:
10-
string_types = basestring,
11-
try:
12-
from ConfigParser import ConfigParser
13-
except ImportError:
14-
from configparser import ConfigParser
5+
6+
from configparser import ConfigParser
157

168
from distutils.version import LooseVersion
179
from distutils.command.build_py import build_py
1810
from distutils.command.install_scripts import install_scripts
1911

2012
from distutils import log
2113

14+
2215
def get_comrec_build(pkg_dir, build_cmd=build_py):
2316
""" Return extended build command class for recording commit
2417
@@ -82,7 +75,7 @@ def _add_append_key(in_dict, key, value):
8275
# Append value to in_dict[key] list
8376
if key not in in_dict:
8477
in_dict[key] = []
85-
elif isinstance(in_dict[key], string_types):
78+
elif isinstance(in_dict[key], str):
8679
in_dict[key] = [in_dict[key]]
8780
in_dict[key].append(value)
8881

@@ -179,7 +172,7 @@ def version_getter(pkg_name):
179172
+ msgs['opt suffix'])
180173
return
181174
# setuptools mode
182-
if optional_tf and not isinstance(optional, string_types):
175+
if optional_tf and not isinstance(optional, str):
183176
raise RuntimeError('Not-False optional arg should be string')
184177
dependency = pkg_name
185178
if version:

tools/bisect_nose.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
GOOD = 0
5555
BAD = 1
5656

57+
5758
def call_or_untestable(cmd):
5859
try:
5960
caller(cmd)
@@ -77,16 +78,16 @@ def main():
7778
args = parser.parse_args()
7879
path = os.path.abspath(args.test_path)
7980
if args.clean:
80-
print "Cleaning"
81+
print("Cleaning")
8182
call_or_untestable('git clean -fxd')
8283
if args.build:
83-
print "Building"
84+
print("Building")
8485
call_or_untestable('python setup.py build_ext -i')
8586
cwd = os.getcwd()
8687
tmpdir = tempfile.mkdtemp()
8788
try:
8889
os.chdir(tmpdir)
89-
print "Testing"
90+
print("Testing")
9091
proc = popener('nosetests ' + path)
9192
stdout, stderr = proc.communicate()
9293
finally:

tools/gitwash_dumper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def copy_replace(replace_pairs,
7979
for rep_glob in rep_globs:
8080
fnames += fnmatch.filter(out_fnames, rep_glob)
8181
if verbose:
82-
print '\n'.join(fnames)
82+
print('\n'.join(fnames))
8383
for fname in fnames:
8484
filename_search_replace(replace_pairs, fname, False)
8585
for in_exp, out_exp in renames:

versioneer.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,7 @@
276276
277277
"""
278278

279-
from __future__ import print_function
280-
try:
281-
import configparser
282-
except ImportError:
283-
import ConfigParser as configparser
279+
import configparser
284280
import errno
285281
import json
286282
import os
@@ -340,9 +336,9 @@ def get_config_from_root(root):
340336
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at
341337
# the top of versioneer.py for instructions on writing your setup.cfg .
342338
setup_cfg = os.path.join(root, "setup.cfg")
343-
parser = configparser.SafeConfigParser()
339+
parser = configparser.ConfigParser()
344340
with open(setup_cfg, "r") as f:
345-
parser.readfp(f)
341+
parser.read_file(f)
346342
VCS = parser.get("versioneer", "VCS") # mandatory
347343

348344
def get(parser, name):

0 commit comments

Comments
 (0)