Skip to content

[FIX] Several fixes related to unicode literals #1656

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
Oct 1, 2016
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
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Upcoming release 0.13
=====================

* FIX: Minor bugfixes related to unicode literals (https://github.com/nipy/nipype/pull/1656)
* ENH: Add a DVARS calculation interface (https://github.com/nipy/nipype/pull/1606)
* ENH: New interface to b0calc of FSL-POSSUM (https://github.com/nipy/nipype/pull/1399)
* ENH: Convenient load/save of interface inputs (https://github.com/nipy/nipype/pull/1591)
Expand Down
2 changes: 1 addition & 1 deletion nipype/algorithms/modelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def _generate_design(self, infolist=None):
out = np.array([])

if out.size > 0:
iflogger.debug('fname=%s, out=%s, nscans=%s', filename, out, repr(sum(nscans[0:i])))
iflogger.debug('fname=%s, out=%s, nscans=%d', filename, out, sum(nscans[0:i]))
sumscans = out.astype(int) + sum(nscans[0:i])

if out.size == 1:
Expand Down
10 changes: 4 additions & 6 deletions nipype/caching/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ def __call__(self, **kwargs):
return out

def __repr__(self):
return '%s(%s.%s, base_dir=%s)' % (self.__class__.__name__,
self.interface.__module__,
self.interface.__name__,
self.base_dir)
return '{}({}.{}}, base_dir={})'.format(
self.__class__.__name__, self.interface.__module__, self.interface.__name__,
self.base_dir)

################################################################################
# Memory manager: provide some tracking about what is computed when, to
Expand Down Expand Up @@ -302,5 +301,4 @@ def _clear_all_but(self, runs, warn=True):
job_names, warn=warn)

def __repr__(self):
return '%s(base_dir=%s)' % (self.__class__.__name__,
self.base_dir)
return '{}(base_dir={})'.format(self.__class__.__name__, self.base_dir)
2 changes: 1 addition & 1 deletion nipype/external/due.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def nondecorating_decorator(func):
cite = load = add = _donothing

def __repr__(self):
return self.__class__.__name__ + '()'
return '{}()'.format(self.__class__.__name__)


def _donothing_func(*args, **kwargs):
Expand Down
15 changes: 9 additions & 6 deletions nipype/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ..utils.provenance import write_provenance
from ..utils.misc import is_container, trim, str2bool
from ..utils.filemanip import (md5, hash_infile, FileNotFoundError, hash_timestamp,
split_filename, encode_dict)
split_filename, to_str)
from .traits_extension import (
traits, Undefined, TraitDictObject, TraitListObject, TraitError, isdefined, File,
Directory, DictStrStr, has_metadata)
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, value):
self.value = value

def __str__(self):
return repr(self.value)
return '{}'.format(self.value)

def _exists_in_path(cmd, environ):
"""
Expand Down Expand Up @@ -271,7 +271,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 = encode_dict(sorted(dict_nofilename.items()))
sorted_dict = to_str(sorted(dict_nofilename.items()))
return dict_withhash, md5(sorted_dict.encode()).hexdigest()

def __pretty__(self, p, cycle):
Expand Down Expand Up @@ -381,7 +381,7 @@ def __repr__(self):
outstr = []
for name, value in sorted(self.trait_get().items()):
outstr.append('%s = %s' % (name, value))
return '\n' + '\n'.join(outstr) + '\n'
return '\n{}\n'.format('\n'.join(outstr))

def _generate_handlers(self):
"""Find all traits with the 'xor' metadata and attach an event
Expand Down Expand Up @@ -581,7 +581,7 @@ def get_hashval(self, hash_method=None):
dict_withhash.append((name,
self._get_sorteddict(val, True, hash_method=hash_method,
hash_files=hash_files)))
return dict_withhash, md5(encode_dict(dict_nofilename).encode()).hexdigest()
return dict_withhash, md5(to_str(dict_nofilename).encode()).hexdigest()


def _get_sorteddict(self, objekt, dictwithhash=False, hash_method=None,
Expand Down Expand Up @@ -808,10 +808,13 @@ def help(cls, returnhelp=False):
def _refs_help(cls):
""" Prints interface references.
"""
if not cls.references_:
return []

helpstr = ['References::']

for r in cls.references_:
helpstr += [repr(r['entry'])]
helpstr += ['{}'.format(r['entry'])]

return helpstr

Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/fsl/dti.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def _list_outputs(self):
cwd, base_name = os.path.split(name)
outputs['out_files'].append(self._gen_fname(
base_name, cwd=cwd,
suffix='_proj_seg_thr_' + repr(self.inputs.threshold)))
suffix='_proj_seg_thr_{}'.format(self.inputs.threshold)))
return outputs


Expand Down
2 changes: 1 addition & 1 deletion nipype/pipeline/engine/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __repr__(self):
if self._hierarchy:
return '.'.join((self._hierarchy, self._id))
else:
return self._id
return '{}'.format(self._id)

def save(self, filename=None):
if filename is None:
Expand Down
Loading