Skip to content

Commit b0d464c

Browse files
committed
RF: Drop various remaining compatibilities for Python < 3.5
1 parent e057971 commit b0d464c

File tree

7 files changed

+8
-115
lines changed

7 files changed

+8
-115
lines changed

nipype/info.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
settings in setup.py, the nipy top-level docstring, and for building the
33
docs. In setup.py in particular, we exec this file, so it cannot import nipy
44
"""
5-
import sys
65

76
# nipype version information. An empty version_extra corresponds to a
87
# full release. '.dev' as a version_extra string means this is a development
@@ -152,9 +151,6 @@ def get_nipype_gitversion():
152151
'futures; python_version == "2.7"',
153152
]
154153

155-
if sys.version_info <= (3, 4):
156-
REQUIRES.append('configparser')
157-
158154
TESTS_REQUIRES = ['pytest-cov', 'codecov', 'pytest-env', 'coverage<5']
159155

160156
EXTRA_REQUIRES = {

nipype/interfaces/tests/test_io.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import copy
66
import simplejson
77
import glob
8-
import shutil
98
import os.path as op
10-
import sys
119
from subprocess import Popen
1210
import hashlib
1311
from collections import namedtuple
@@ -577,8 +575,6 @@ def test_jsonsink(tmpdir, inputs_attributes):
577575
# There are three reasons these tests will be skipped:
578576
@pytest.mark.skipif(not have_pybids,
579577
reason="Pybids is not installed")
580-
@pytest.mark.skipif(sys.version_info < (3, 0),
581-
reason="Pybids no longer supports Python 2")
582578
@pytest.mark.skipif(not dist_is_editable('pybids'),
583579
reason="Pybids is not installed in editable mode")
584580
def test_bids_grabber(tmpdir):
@@ -594,8 +590,6 @@ def test_bids_grabber(tmpdir):
594590

595591
@pytest.mark.skipif(not have_pybids,
596592
reason="Pybids is not installed")
597-
@pytest.mark.skipif(sys.version_info < (3, 0),
598-
reason="Pybids no longer supports Python 2")
599593
@pytest.mark.skipif(not dist_is_editable('pybids'),
600594
reason="Pybids is not installed in editable mode")
601595
def test_bids_fields(tmpdir):
@@ -610,8 +604,6 @@ def test_bids_fields(tmpdir):
610604

611605
@pytest.mark.skipif(not have_pybids,
612606
reason="Pybids is not installed")
613-
@pytest.mark.skipif(sys.version_info < (3, 0),
614-
reason="Pybids no longer supports Python 2")
615607
@pytest.mark.skipif(not dist_is_editable('pybids'),
616608
reason="Pybids is not installed in editable mode")
617609
def test_bids_infields_outfields(tmpdir):

nipype/pipeline/engine/tests/test_utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""Tests for the engine utils module
55
"""
66
import os
7-
import sys
87
from copy import deepcopy
98
import pytest
109

@@ -159,8 +158,6 @@ def dummy_func(value):
159158
return value + 1
160159

161160

162-
@pytest.mark.skipif(
163-
sys.version_info < (3, 0), reason="the famous segfault #1788")
164161
def test_mapnode_crash(tmpdir):
165162
"""Test mapnode crash when stop_on_first_crash is True"""
166163
cwd = os.getcwd()
@@ -180,8 +177,6 @@ def test_mapnode_crash(tmpdir):
180177
os.chdir(cwd)
181178

182179

183-
@pytest.mark.skipif(
184-
sys.version_info < (3, 0), reason="the famous segfault #1788")
185180
def test_mapnode_crash2(tmpdir):
186181
"""Test mapnode crash when stop_on_first_crash is False"""
187182
cwd = os.getcwd()
@@ -200,8 +195,6 @@ def test_mapnode_crash2(tmpdir):
200195
os.chdir(cwd)
201196

202197

203-
@pytest.mark.skipif(
204-
sys.version_info < (3, 0), reason="the famous segfault #1788")
205198
def test_mapnode_crash3(tmpdir):
206199
"""Test mapnode crash when mapnode is embedded in a workflow"""
207200
tmpdir.chdir()

nipype/pipeline/plugins/tools.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def create_pyscript(node, updatehash=False, store_exception=True):
115115
batchdir = '%s'
116116
from nipype.utils.filemanip import loadpkl, savepkl
117117
try:
118-
if not sys.version_info < (2, 7):
119-
from collections import OrderedDict
118+
from collections import OrderedDict
120119
config_dict=%s
121120
config.update_config(config_dict)
122121
## Only configure matplotlib if it was successfully imported,

nipype/sphinxext/plot_workflow.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,6 @@ def format_template(template, **kw):
144144

145145

146146

147-
def _mkdirp(folder):
148-
"""
149-
Equivalent to bash's mkdir -p
150-
"""
151-
if sys.version_info > (3, 4, 1):
152-
os.makedirs(folder, exist_ok=True)
153-
return folder
154-
155-
try:
156-
os.makedirs(folder)
157-
except OSError as exc:
158-
if exc.errno != EEXIST or not os.path.isdir(folder):
159-
raise
160-
161-
return folder
162-
163-
164147
def wf_directive(name, arguments, options, content, lineno, content_offset,
165148
block_text, state, state_machine):
166149
if len(missing_imports) == 0:
@@ -737,7 +720,7 @@ def run(arguments, content, options, state_machine, state, lineno):
737720
state_machine.insert_input(total_lines, source=source_file_name)
738721

739722
# copy image files to builder's output directory, if necessary
740-
_mkdirp(dest_dir)
723+
os.makedirs(dest_dir, exist_ok=True)
741724
for code_piece, images in results:
742725
for img in images:
743726
for fn in img.filenames():

nipype/utils/filemanip.py

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -91,56 +91,7 @@ def to_str(value):
9191
Manipulates ordered dicts before they are hashed (Py2/3 compat.)
9292
9393
"""
94-
if sys.version_info[0] > 2:
95-
retval = str(value)
96-
else:
97-
retval = to_str_py27(value)
98-
return retval
99-
100-
101-
def to_str_py27(value):
102-
"""
103-
Encode dictionary for python 2
104-
"""
105-
106-
if isinstance(value, dict):
107-
entry = '{}: {}'.format
108-
retval = '{'
109-
for key, val in list(value.items()):
110-
if len(retval) > 1:
111-
retval += ', '
112-
kenc = repr(key)
113-
if kenc.startswith(("u'", 'u"')):
114-
kenc = kenc[1:]
115-
venc = to_str_py27(val)
116-
if venc.startswith(("u'", 'u"')):
117-
venc = venc[1:]
118-
retval += entry(kenc, venc)
119-
retval += '}'
120-
return retval
121-
122-
istuple = isinstance(value, tuple)
123-
if isinstance(value, (tuple, list)):
124-
retval = '(' if istuple else '['
125-
nels = len(value)
126-
for i, v in enumerate(value):
127-
venc = to_str_py27(v)
128-
if venc.startswith(("u'", 'u"')):
129-
venc = venc[1:]
130-
retval += venc
131-
132-
if i < nels - 1:
133-
retval += ', '
134-
135-
if istuple and nels == 1:
136-
retval += ','
137-
retval += ')' if istuple else ']'
138-
return retval
139-
140-
retval = repr(value).decode()
141-
if retval.startswith(("u'", 'u"')):
142-
retval = retval[1:]
143-
return retval
94+
return str(value)
14495

14596

14697
def fname_presuffix(fname, prefix='', suffix='', newpath=None, use_ext=True):
@@ -593,8 +544,6 @@ def save_json(filename, data):
593544
594545
"""
595546
mode = 'w'
596-
if sys.version_info[0] < 3:
597-
mode = 'wb'
598547
with open(filename, mode) as fp:
599548
json.dump(data, fp, sort_keys=True, indent=4)
600549

@@ -841,27 +790,10 @@ def which(cmd, env=None, pathext=None):
841790
if env and 'PATH' in env:
842791
path = env.get("PATH")
843792

844-
if sys.version_info >= (3, 3):
845-
for ext in pathext:
846-
filename = shutil.which(cmd + ext, path=path)
847-
if filename:
848-
return filename
849-
return None
850-
851-
def isexec(path):
852-
return os.path.isfile(path) and os.access(path, os.X_OK)
853-
854793
for ext in pathext:
855-
extcmd = cmd + ext
856-
fpath, fname = os.path.split(extcmd)
857-
if fpath:
858-
if isexec(extcmd):
859-
return extcmd
860-
else:
861-
for directory in path.split(os.pathsep):
862-
filename = op.join(directory, extcmd)
863-
if isexec(filename):
864-
return filename
794+
filename = shutil.which(cmd + ext, path=path)
795+
if filename:
796+
return filename
865797
return None
866798

867799

nipype/utils/tests/test_functions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
import sys
32
import pytest
43
from nipype.utils.functions import (getsource, create_function_from_source)
54

@@ -27,7 +26,7 @@ def test_func_to_str_err():
2726

2827
def _print_statement():
2928
try:
30-
exec('print ""')
29+
exec('print("")')
3130
return True
3231
except SyntaxError:
3332
return False
@@ -41,7 +40,6 @@ def is_string():
4140
assert is_string() == wrapped_func()
4241

4342

44-
@pytest.mark.skipif(sys.version_info[0] > 2, reason="breaks python 3")
45-
def test_func_print_py2():
43+
def test_func_print():
4644
wrapped_func = create_function_from_source(getsource(_print_statement))
4745
assert wrapped_func()

0 commit comments

Comments
 (0)