Skip to content

RF: Drop various remaining compatibilities for Python < 3.5 #2831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions nipype/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
settings in setup.py, the nipy top-level docstring, and for building the
docs. In setup.py in particular, we exec this file, so it cannot import nipy
"""
import sys

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

if sys.version_info <= (3, 4):
REQUIRES.append('configparser')

TESTS_REQUIRES = ['pytest-cov', 'codecov', 'pytest-env', 'coverage<5']

EXTRA_REQUIRES = {
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from warnings import warn
from packaging.version import Version

from ...utils.filemanip import md5, hash_infile, hash_timestamp, to_str
from ...utils.filemanip import md5, hash_infile, hash_timestamp
from .traits_extension import (
traits,
Undefined,
Expand Down Expand Up @@ -251,7 +251,7 @@ def get_hashval(self, hash_method=None):
True,
hash_method=hash_method,
hash_files=hash_files)))
return list_withhash, md5(to_str(list_nofilename).encode()).hexdigest()
return list_withhash, md5(str(list_nofilename).encode()).hexdigest()

def _get_sorteddict(self,
objekt,
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/base/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ... import logging
from ...utils.misc import is_container
from ...utils.filemanip import md5, to_str, hash_infile
from ...utils.filemanip import md5, hash_infile
iflogger = logging.getLogger('nipype.interface')

HELP_LINEWIDTH = 70
Expand Down Expand Up @@ -161,7 +161,7 @@ def _get_bunch_hash(self):
# Sort the items of the dictionary, before hashing the string
# representation so we get a predictable order of the
# dictionary.
sorted_dict = to_str(sorted(dict_nofilename.items()))
sorted_dict = str(sorted(dict_nofilename.items()))
return dict_withhash, md5(sorted_dict.encode()).hexdigest()

def _repr_pretty_(self, p, cycle):
Expand Down
8 changes: 0 additions & 8 deletions nipype/interfaces/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import copy
import simplejson
import glob
import shutil
import os.path as op
import sys
from subprocess import Popen
import hashlib
from collections import namedtuple
Expand Down Expand Up @@ -577,8 +575,6 @@ def test_jsonsink(tmpdir, inputs_attributes):
# There are three reasons these tests will be skipped:
@pytest.mark.skipif(not have_pybids,
reason="Pybids is not installed")
@pytest.mark.skipif(sys.version_info < (3, 0),
reason="Pybids no longer supports Python 2")
@pytest.mark.skipif(not dist_is_editable('pybids'),
reason="Pybids is not installed in editable mode")
def test_bids_grabber(tmpdir):
Expand All @@ -594,8 +590,6 @@ def test_bids_grabber(tmpdir):

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

@pytest.mark.skipif(not have_pybids,
reason="Pybids is not installed")
@pytest.mark.skipif(sys.version_info < (3, 0),
reason="Pybids no longer supports Python 2")
@pytest.mark.skipif(not dist_is_editable('pybids'),
reason="Pybids is not installed in editable mode")
def test_bids_infields_outfields(tmpdir):
Expand Down
18 changes: 9 additions & 9 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from ...utils.misc import flatten, unflatten, str2bool, dict_diff
from ...utils.filemanip import (md5, FileNotFoundError, ensure_list,
simplify_list, copyfiles, fnames_presuffix,
loadpkl, split_filename, load_json, makedirs,
emptydirs, savepkl, to_str, indirectory)
loadpkl, split_filename, load_json,
emptydirs, savepkl, indirectory)

from ...interfaces.base import (traits, InputMultiPath, CommandLine, Undefined,
DynamicTraitedSpec, Bunch, InterfaceResult,
Expand Down Expand Up @@ -267,7 +267,7 @@ def output_dir(self):
def set_input(self, parameter, val):
"""Set interface input value"""
logger.debug('[Node] %s - setting input %s = %s', self.name, parameter,
to_str(val))
str(val))
setattr(self.inputs, parameter, deepcopy(val))

def get_output(self, parameter):
Expand Down Expand Up @@ -453,7 +453,7 @@ def run(self, updatehash=False):
os.remove(filename)

# Make sure outdir is created
makedirs(outdir, exist_ok=True)
os.makedirs(outdir, exist_ok=True)

# Store runtime-hashfile, pre-execution report, the node and the inputs set.
_save_hashfile(hashfile_unfinished, self._hashed_inputs)
Expand Down Expand Up @@ -663,7 +663,7 @@ def _copyfiles_to_wd(self, execute=True, linksonly=False):
if execute and linksonly:
olddir = outdir
outdir = op.join(outdir, '_tempinput')
makedirs(outdir, exist_ok=True)
os.makedirs(outdir, exist_ok=True)

for info in filecopy_info:
files = self.inputs.trait_get().get(info['key'])
Expand Down Expand Up @@ -1019,13 +1019,13 @@ def set_input(self, parameter, val):
Set interface input value or nodewrapper attribute
Priority goes to interface.
"""
logger.debug('setting nodelevel(%s) input %s = %s', to_str(self),
parameter, to_str(val))
logger.debug('setting nodelevel(%s) input %s = %s', str(self),
parameter, str(val))
self._set_mapnode_input(parameter, deepcopy(val))

def _set_mapnode_input(self, name, newvalue):
logger.debug('setting mapnode(%s) input: %s -> %s', to_str(self), name,
to_str(newvalue))
logger.debug('setting mapnode(%s) input: %s -> %s', str(self), name,
str(newvalue))
if name in self.iterfield:
setattr(self._inputs, name, newvalue)
else:
Expand Down
7 changes: 0 additions & 7 deletions nipype/pipeline/engine/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""Tests for the engine utils module
"""
import os
import sys
from copy import deepcopy
import pytest

Expand Down Expand Up @@ -159,8 +158,6 @@ def dummy_func(value):
return value + 1


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


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


@pytest.mark.skipif(
sys.version_info < (3, 0), reason="the famous segfault #1788")
def test_mapnode_crash3(tmpdir):
"""Test mapnode crash when mapnode is embedded in a workflow"""
tmpdir.chdir()
Expand Down
8 changes: 3 additions & 5 deletions nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
from ... import logging, config, LooseVersion
from ...utils.filemanip import (
relpath,
makedirs,
fname_presuffix,
to_str,
ensure_list,
get_related_files,
FileNotFoundError,
Expand Down Expand Up @@ -117,7 +115,7 @@ def write_report(node, report_type=None, is_mapnode=False):
cwd = node.output_dir()
report_dir = os.path.join(cwd, '_report')
report_file = os.path.join(report_dir, 'report.rst')
makedirs(report_dir, exist_ok=True)
os.makedirs(report_dir, exist_ok=True)

logger.debug('[Node] Writing %s-exec report to "%s"', report_type[:-4],
report_file)
Expand Down Expand Up @@ -627,7 +625,7 @@ def _get_valid_pathstr(pathstr):
Replaces: ',' -> '.'
"""
if not isinstance(pathstr, (str, bytes)):
pathstr = to_str(pathstr)
pathstr = str(pathstr)
pathstr = pathstr.replace(os.sep, '..')
pathstr = re.sub(r'''[][ (){}?:<>#!|"';]''', '', pathstr)
pathstr = pathstr.replace(',', '.')
Expand Down Expand Up @@ -1355,7 +1353,7 @@ def export_graph(graph_in,
if base_dir is None:
base_dir = os.getcwd()

makedirs(base_dir, exist_ok=True)
os.makedirs(base_dir, exist_ok=True)
out_dot = fname_presuffix(
dotfilename, suffix='_detailed.dot', use_ext=False, newpath=base_dir)
_write_detailed_dot(graph, out_dot)
Expand Down
30 changes: 15 additions & 15 deletions nipype/pipeline/engine/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ...interfaces.base import (traits, TraitedSpec, TraitDictObject,
TraitListObject)
from ...utils.filemanip import save_json, makedirs, to_str
from ...utils.filemanip import save_json
from .utils import (generate_expanded_graph, export_graph, write_workflow_prov,
write_workflow_resources, format_dot, topological_sort,
get_print_name, merge_dict, format_node)
Expand Down Expand Up @@ -218,12 +218,12 @@ def connect(self, *args, **kwargs):
edge_data = self._graph.get_edge_data(srcnode, destnode, None)
if edge_data:
logger.debug('(%s, %s): Edge data exists: %s', srcnode,
destnode, to_str(edge_data))
destnode, str(edge_data))
for data in connects:
if data not in edge_data['connect']:
edge_data['connect'].append(data)
if disconnect:
logger.debug('Removing connection: %s', to_str(data))
logger.debug('Removing connection: %s', str(data))
edge_data['connect'].remove(data)
if edge_data['connect']:
self._graph.add_edges_from([(srcnode, destnode,
Expand All @@ -240,7 +240,7 @@ def connect(self, *args, **kwargs):
})])
edge_data = self._graph.get_edge_data(srcnode, destnode)
logger.debug('(%s, %s): new edge data: %s', srcnode, destnode,
to_str(edge_data))
str(edge_data))

def disconnect(self, *args):
"""Disconnect nodes
Expand All @@ -256,7 +256,7 @@ def disconnect(self, *args):

for srcnode, dstnode, conn in connection_list:
logger.debug('disconnect(): %s->%s %s', srcnode, dstnode,
to_str(conn))
str(conn))
if self in [srcnode, dstnode]:
raise IOError(
'Workflow connect cannot contain itself as node: src[%s] '
Expand All @@ -277,10 +277,10 @@ def disconnect(self, *args):
# idx = ed_conns.index(edge)
remove.append((edge[0], edge[1]))

logger.debug('disconnect(): remove list %s', to_str(remove))
logger.debug('disconnect(): remove list %s', str(remove))
for el in remove:
edge_data['connect'].remove(el)
logger.debug('disconnect(): removed connection %s', to_str(el))
logger.debug('disconnect(): removed connection %s', str(el))

if not edge_data['connect']:
self._graph.remove_edge(srcnode, dstnode)
Expand Down Expand Up @@ -410,7 +410,7 @@ def write_graph(self,
base_dir = op.join(base_dir, self.name)
else:
base_dir = os.getcwd()
base_dir = makedirs(base_dir, exist_ok=True)
os.makedirs(base_dir, exist_ok=True)
if graph2use in ['hierarchical', 'colored']:
if self.name[:1].isdigit(): # these graphs break if int
raise ValueError('{} graph failed, workflow name cannot begin '
Expand Down Expand Up @@ -576,7 +576,7 @@ def run(self, plugin=None, plugin_args=None, updatehash=False):
flatgraph = self._create_flat_graph()
self.config = merge_dict(deepcopy(config._sections), self.config)
logger.info('Workflow %s settings: %s', self.name,
to_str(sorted(self.config)))
str(sorted(self.config)))
self._set_needed_outputs(flatgraph)
execgraph = generate_expanded_graph(deepcopy(flatgraph))
for index, node in enumerate(execgraph.nodes()):
Expand Down Expand Up @@ -609,7 +609,7 @@ def _write_report_info(self, workingdir, name, graph):
if workingdir is None:
workingdir = os.getcwd()
report_dir = op.join(workingdir, name)
makedirs(report_dir, exist_ok=True)
os.makedirs(report_dir, exist_ok=True)
shutil.copyfile(
op.join(op.dirname(__file__), 'report_template.html'),
op.join(report_dir, 'index.html'))
Expand Down Expand Up @@ -821,7 +821,7 @@ def _set_node_input(self, node, param, source, sourceinfo):
newval = dict(val)
if isinstance(val, TraitListObject):
newval = val[:]
logger.debug('setting node input: %s->%s', param, to_str(newval))
logger.debug('setting node input: %s->%s', param, str(newval))
node.set_input(param, deepcopy(newval))

def _get_all_nodes(self):
Expand Down Expand Up @@ -881,9 +881,9 @@ def _generate_flatgraph(self):
# dj: added list() for networkx ver.2
for u, _, d in list(
self._graph.in_edges(nbunch=node, data=True)):
logger.debug('in: connections-> %s', to_str(d['connect']))
logger.debug('in: connections-> %s', str(d['connect']))
for cd in deepcopy(d['connect']):
logger.debug("in: %s", to_str(cd))
logger.debug("in: %s", str(cd))
dstnode = node._get_parameter_node(cd[1], subtype='in')
srcnode = u
srcout = cd[0]
Expand All @@ -896,9 +896,9 @@ def _generate_flatgraph(self):
# dj: for ver 2 use list(out_edges)
for _, v, d in list(
self._graph.out_edges(nbunch=node, data=True)):
logger.debug('out: connections-> %s', to_str(d['connect']))
logger.debug('out: connections-> %s', str(d['connect']))
for cd in deepcopy(d['connect']):
logger.debug("out: %s", to_str(cd))
logger.debug("out: %s", str(cd))
dstnode = v
if isinstance(cd[0], tuple):
parameter = cd[0][0]
Expand Down
7 changes: 3 additions & 4 deletions nipype/pipeline/plugins/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from traceback import format_exception

from ... import logging
from ...utils.filemanip import savepkl, crash2txt, makedirs
from ...utils.filemanip import savepkl, crash2txt

logger = logging.getLogger('nipype.workflow')

Expand Down Expand Up @@ -42,7 +42,7 @@ def report_crash(node, traceback=None, hostname=None):
str(uuid.uuid4()))
crashdir = node.config['execution'].get('crashdump_dir', os.getcwd())

makedirs(crashdir, exist_ok=True)
os.makedirs(crashdir, exist_ok=True)
crashfile = os.path.join(crashdir, crashfile)

if node.config['execution']['crashfile_format'].lower() in ['text', 'txt']:
Expand Down Expand Up @@ -115,8 +115,7 @@ def create_pyscript(node, updatehash=False, store_exception=True):
batchdir = '%s'
from nipype.utils.filemanip import loadpkl, savepkl
try:
if not sys.version_info < (2, 7):
from collections import OrderedDict
from collections import OrderedDict
config_dict=%s
config.update_config(config_dict)
## Only configure matplotlib if it was successfully imported,
Expand Down
19 changes: 1 addition & 18 deletions nipype/sphinxext/plot_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,6 @@ def format_template(template, **kw):



def _mkdirp(folder):
"""
Equivalent to bash's mkdir -p
"""
if sys.version_info > (3, 4, 1):
os.makedirs(folder, exist_ok=True)
return folder

try:
os.makedirs(folder)
except OSError as exc:
if exc.errno != EEXIST or not os.path.isdir(folder):
raise

return folder


def wf_directive(name, arguments, options, content, lineno, content_offset,
block_text, state, state_machine):
if len(missing_imports) == 0:
Expand Down Expand Up @@ -737,7 +720,7 @@ def run(arguments, content, options, state_machine, state, lineno):
state_machine.insert_input(total_lines, source=source_file_name)

# copy image files to builder's output directory, if necessary
_mkdirp(dest_dir)
os.makedirs(dest_dir, exist_ok=True)
for code_piece, images in results:
for img in images:
for fn in img.filenames():
Expand Down
Loading