Skip to content

Commit f25cfc0

Browse files
committed
RF: Purge PY2/PY3 indicators
1 parent fa347ae commit f25cfc0

File tree

7 files changed

+10
-47
lines changed

7 files changed

+10
-47
lines changed

nipype/interfaces/base/core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343

4444
iflogger = logging.getLogger('nipype.interface')
4545

46-
PY35 = sys.version_info >= (3, 5)
47-
PY3 = sys.version_info[0] > 2
4846
VALID_TERMINAL_OUTPUT = [
4947
'stream', 'allatonce', 'file', 'file_split', 'file_stdout', 'file_stderr',
5048
'none'
@@ -644,7 +642,7 @@ def save_inputs_to_json(self, json_file):
644642
"""
645643
inputs = self.inputs.get_traitsfree()
646644
iflogger.debug('saving inputs {}', inputs)
647-
with open(json_file, 'w' if PY3 else 'wb') as fhandle:
645+
with open(json_file, 'w') as fhandle:
648646
json.dump(inputs, fhandle, indent=4, ensure_ascii=False)
649647

650648
def _pre_run_hook(self, runtime):

nipype/pipeline/engine/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
from funcsigs import signature
4848

4949
logger = logging.getLogger('nipype.workflow')
50-
PY3 = sys.version_info[0] > 2
5150

5251
try:
5352
dfs_preorder = nx.dfs_preorder
@@ -1595,7 +1594,7 @@ def write_workflow_resources(graph, filename=None, append=None):
15951594
# If we append different runs, then we will see different
15961595
# "bursts" of timestamps corresponding to those executions.
15971596
if append and os.path.isfile(filename):
1598-
with open(filename, 'r' if PY3 else 'rb') as rsf:
1597+
with open(filename, 'r') as rsf:
15991598
big_dict = json.load(rsf)
16001599

16011600
for _, node in enumerate(graph.nodes()):
@@ -1633,7 +1632,7 @@ def write_workflow_resources(graph, filename=None, append=None):
16331632
big_dict['mapnode'] += [subidx] * nsamples
16341633
big_dict['params'] += [params] * nsamples
16351634

1636-
with open(filename, 'w' if PY3 else 'wb') as rsf:
1635+
with open(filename, 'w') as rsf:
16371636
json.dump(big_dict, rsf, ensure_ascii=False)
16381637

16391638
return filename

nipype/pkg_info.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import subprocess
77

88
COMMIT_INFO_FNAME = 'COMMIT_INFO.txt'
9-
PY3 = sys.version_info[0] >= 3
109

1110

1211
def pkg_commit_hash(pkg_path):
@@ -61,9 +60,7 @@ def pkg_commit_hash(pkg_path):
6160
shell=True)
6261
repo_commit, _ = proc.communicate()
6362
if repo_commit:
64-
if PY3:
65-
repo_commit = repo_commit.decode()
66-
return 'repository', repo_commit.strip()
63+
return 'repository', repo_commit.decode().strip()
6764
return '(none found)', '<not found>'
6865

6966

@@ -82,8 +79,6 @@ def get_pkg_info(pkg_path):
8279
'''
8380
src, hsh = pkg_commit_hash(pkg_path)
8481
from .info import VERSION
85-
if not PY3:
86-
src, hsh, VERSION = src.encode(), hsh.encode(), VERSION.encode()
8782
import networkx
8883
import nibabel
8984
import numpy

nipype/sphinxext/plot_workflow.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ def format_template(template, **kw):
144144

145145

146146

147-
PY2 = sys.version_info[0] == 2
148-
PY3 = sys.version_info[0] == 3
149-
150-
151147
def _mkdirp(folder):
152148
"""
153149
Equivalent to bash's mkdir -p
@@ -274,8 +270,7 @@ def setup(app):
274270
app.add_config_value('wf_working_directory', None, True)
275271
app.add_config_value('wf_template', None, True)
276272

277-
app.connect('doctree-read'.encode()
278-
if PY2 else 'doctree-read', mark_wf_labels)
273+
app.connect('doctree-read', mark_wf_labels)
279274

280275
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
281276
return metadata
@@ -456,11 +451,7 @@ def run_code(code, code_path, ns=None, function_name=None):
456451

457452
# Redirect stdout
458453
stdout = sys.stdout
459-
if PY3:
460-
sys.stdout = io.StringIO()
461-
else:
462-
from cStringIO import StringIO
463-
sys.stdout = StringIO()
454+
sys.stdout = io.StringIO()
464455

465456
# Assign a do-nothing print function to the namespace. There
466457
# doesn't seem to be any other way to provide a way to (not) print

nipype/utils/draw_gantt_chart.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
'install the pandas package')
2222
pass
2323

24-
PY3 = sys.version_info[0] > 2
25-
2624

2725
def create_event_dict(start_time, nodes_list):
2826
'''
@@ -316,10 +314,7 @@ def draw_resource_bar(start_time, finish_time, time_series,
316314
space_between_minutes = space_between_minutes / scale
317315

318316
# Iterate through time series
319-
if PY3:
320-
ts_items = time_series.items()
321-
else:
322-
ts_items = time_series.iteritems()
317+
ts_items = time_series.items()
323318

324319
ts_len = len(time_series)
325320
for idx, (ts_start, amount) in enumerate(ts_items):
@@ -555,5 +550,5 @@ def generate_gantt_chart(logfile,
555550
</body>'''
556551

557552
# save file
558-
with open(logfile + '.html', 'w' if PY3 else 'wb') as html_file:
553+
with open(logfile + '.html', 'w') as html_file:
559554
html_file.write(html_string)

nipype/utils/tests/test_cmd.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from io import StringIO
77
from ...utils import nipype_cmd
88

9-
PY2 = sys.version_info[0] < 3
10-
119

1210
@contextmanager
1311
def capture_sys_output():
@@ -35,10 +33,6 @@ def test_main_returns_2_on_empty(self):
3533
nipype_cmd: error: the following arguments are required: module, interface
3634
"""
3735

38-
if PY2:
39-
msg = """usage: nipype_cmd [-h] module interface
40-
nipype_cmd: error: too few arguments
41-
"""
4236
assert stderr.getvalue() == msg
4337
assert stdout.getvalue() == ''
4438

setup.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
from setuptools.command.build_py import build_py
2323

2424

25-
PY3 = sys.version_info[0] >= 3
26-
27-
2825
class BuildWithCommitInfoCommand(build_py):
2926
""" Return extended build command class for recording commit
3027
@@ -70,20 +67,14 @@ def run(self):
7067
stdout=subprocess.PIPE,
7168
stderr=subprocess.PIPE,
7269
shell=True)
73-
repo_commit, _ = proc.communicate()
74-
# Fix for python 3
75-
if PY3:
76-
repo_commit = repo_commit.decode()
70+
repo_commit, _ = proc.communicate().decode()
7771

7872
# We write the installation commit even if it's empty
7973
cfg_parser = configparser.RawConfigParser()
8074
cfg_parser.read(pjoin('nipype', 'COMMIT_INFO.txt'))
8175
cfg_parser.set('commit hash', 'install_hash', repo_commit.strip())
8276
out_pth = pjoin(self.build_lib, 'nipype', 'COMMIT_INFO.txt')
83-
if PY3:
84-
cfg_parser.write(open(out_pth, 'wt'))
85-
else:
86-
cfg_parser.write(open(out_pth, 'wb'))
77+
cfg_parser.write(open(out_pth, 'wt'))
8778

8879

8980
def main():

0 commit comments

Comments
 (0)