Skip to content

Commit 57d3a3b

Browse files
committed
Merge branch 'enh/FSLstd2imgcoords' of github.com:oesteban/nipype into enh/FSLstd2imgcoords
2 parents 4d9a080 + 4540fd2 commit 57d3a3b

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Next release
22
============
33

44
* ENH: Simple interface to FSL std2imgcoords (https://github.com/nipy/nipype/pull/1398)
5+
* FIX: Clean up byte/unicode issues using subprocess (https://github.com/nipy/nipype/pull/1394)
56
* FIX: Prevent crash when tvtk is loaded - ETS_TOOLKIT=null (https://github.com/nipy/nipype/pull/973)
67
* ENH: New interfaces in dipy: RESTORE, EstimateResponseSH, CSD and StreamlineTractography
78
(https://github.com/nipy/nipype/pull/1090)
@@ -22,6 +23,7 @@ Next release
2223
* API: Default model level for the bedpostx workflow has been set to "2" following FSL 5.0.9 lead
2324
* ENH: New interfaces for interacting with AWS S3: S3DataSink and S3DataGrabber (https://github.com/nipy/nipype/pull/1201)
2425
* ENH: Interfaces for MINC tools (https://github.com/nipy/nipype/pull/1304)
26+
* FIX: Use realpath to determine hard link source (https://github.com/nipy/nipype/pull/1388)
2527

2628
Release 0.11.0 (September 15, 2015)
2729
============

nipype/interfaces/base.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from copy import deepcopy
2020
import datetime
2121
import errno
22+
import locale
2223
import os
2324
import re
2425
import platform
@@ -47,7 +48,7 @@
4748
from ..utils.provenance import write_provenance
4849
from .. import config, logging, LooseVersion
4950
from .. import __version__
50-
from ..external.six import string_types
51+
from ..external.six import string_types, text_type
5152

5253
nipype_version = LooseVersion(__version__)
5354

@@ -1205,8 +1206,8 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
12051206
if output == 'file':
12061207
errfile = os.path.join(runtime.cwd, 'stderr.nipype')
12071208
outfile = os.path.join(runtime.cwd, 'stdout.nipype')
1208-
stderr = open(errfile, 'wt') # t=='text'===default
1209-
stdout = open(outfile, 'wt')
1209+
stderr = open(errfile, 'wb') # t=='text'===default
1210+
stdout = open(outfile, 'wb')
12101211

12111212
proc = subprocess.Popen(cmdline,
12121213
stdout=stdout,
@@ -1256,26 +1257,17 @@ def _process(drain=0):
12561257
result['merged'] = [r[1] for r in temp]
12571258
if output == 'allatonce':
12581259
stdout, stderr = proc.communicate()
1259-
if stdout and isinstance(stdout, bytes):
1260-
try:
1261-
stdout = stdout.decode()
1262-
except UnicodeDecodeError:
1263-
stdout = stdout.decode("ISO-8859-1")
1264-
if stderr and isinstance(stderr, bytes):
1265-
try:
1266-
stderr = stderr.decode()
1267-
except UnicodeDecodeError:
1268-
stderr = stderr.decode("ISO-8859-1")
1269-
1270-
result['stdout'] = str(stdout).split('\n')
1271-
result['stderr'] = str(stderr).split('\n')
1260+
stdout = stdout.decode(locale.getdefaultlocale()[1])
1261+
stderr = stderr.decode(locale.getdefaultlocale()[1])
1262+
result['stdout'] = stdout.split('\n')
1263+
result['stderr'] = stderr.split('\n')
12721264
result['merged'] = ''
12731265
if output == 'file':
12741266
ret_code = proc.wait()
12751267
stderr.flush()
12761268
stdout.flush()
1277-
result['stdout'] = [line.strip() for line in open(outfile).readlines()]
1278-
result['stderr'] = [line.strip() for line in open(errfile).readlines()]
1269+
result['stdout'] = [line.decode(locale.getdefaultlocale()[1]).strip() for line in open(outfile, 'rb').readlines()]
1270+
result['stderr'] = [line.decode(locale.getdefaultlocale()[1]).strip() for line in open(errfile, 'rb').readlines()]
12791271
result['merged'] = ''
12801272
if output == 'none':
12811273
proc.communicate()

nipype/interfaces/spm/tests/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from nipype.interfaces.spm import no_spm
1313
import nipype.interfaces.matlab as mlab
1414
from nipype.interfaces.spm.base import SPMCommandInputSpec
15-
from nipype.interfaces.base import traits
15+
from nipype.interfaces.base import traits, text_type
1616

1717
try:
1818
matlab_cmd = os.environ['MATLABCMD']
@@ -57,7 +57,7 @@ def test_scan_for_fnames():
5757
def test_spm_path():
5858
spm_path = spm.Info.version()['path']
5959
if spm_path is not None:
60-
yield assert_equal, type(spm_path), type('')
60+
yield assert_equal, type(spm_path), text_type
6161
yield assert_true, 'spm' in spm_path
6262

6363

nipype/interfaces/tests/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
skipif)
1515
import nipype.interfaces.base as nib
1616
from nipype.utils.filemanip import split_filename
17-
from nipype.interfaces.base import Undefined, config
17+
from nipype.interfaces.base import Undefined, config, text_type
1818
from traits.testing.nose_tools import skip
1919
import traits.api as traits
2020

@@ -661,7 +661,7 @@ def test_CommandLine_output():
661661
ci.inputs.terminal_output = 'file'
662662
res = ci.run()
663663
yield assert_true, 'stdout.nipype' in res.runtime.stdout
664-
yield assert_equal, type(res.runtime.stdout), type('hi')
664+
yield assert_equal, type(res.runtime.stdout), text_type
665665
ci = nib.CommandLine(command='ls -l')
666666
ci.inputs.terminal_output = 'none'
667667
res = ci.run()

nipype/pipeline/plugins/slurmgraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def make_job_name(jobnumber, nodeslist):
135135
if self._sbatch_args.count('-o ') == 0:
136136
stdoutFile = '-o {outFile}'.format(
137137
outFile=batchscriptoutfile)
138-
full_line = '{jobNm}=$(sbatch {outFileOption} {errFileOption} {extraSBatchArgs} {dependantIndex} -J {jobNm} {batchscript} | awk \'{{print $4}}\')\n'.format(
138+
full_line = '{jobNm}=$(sbatch {outFileOption} {errFileOption} {extraSBatchArgs} {dependantIndex} -J {jobNm} {batchscript} | awk \'/^Submitted/ {{print $4}}\')\n'.format(
139139
jobNm=jobname,
140140
outFileOption=stdoutFile,
141141
errFileOption=stderrFile,

nipype/utils/filemanip.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def nipype_hardlink_wrapper(raw_src, raw_dst):
4242
If the hardlink fails, then fall back to using
4343
a standard copy.
4444
"""
45-
src = os.path.normpath(raw_src)
45+
# Use realpath to avoid hardlinking symlinks
46+
src = os.path.realpath(raw_src)
47+
# Use normpath, in case destination is a symlink
4648
dst = os.path.normpath(raw_dst)
4749
del raw_src
4850
del raw_dst
@@ -283,12 +285,15 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
283285
matofile = originalfile[:-4] + ".mat"
284286
if os.path.exists(matofile):
285287
matnfile = newfile[:-4] + ".mat"
286-
copyfile(matofile, matnfile, copy)
287-
copyfile(hdrofile, hdrnfile, copy)
288+
copyfile(matofile, matnfile, copy, create_new, hashmethod,
289+
use_hardlink)
290+
copyfile(hdrofile, hdrnfile, copy, create_new, hashmethod,
291+
use_hardlink)
288292
elif originalfile.endswith(".BRIK"):
289293
hdrofile = originalfile[:-5] + ".HEAD"
290294
hdrnfile = newfile[:-5] + ".HEAD"
291-
copyfile(hdrofile, hdrnfile, copy)
295+
copyfile(hdrofile, hdrnfile, copy, create_new, hashmethod,
296+
use_hardlink)
292297

293298
return newfile
294299

nipype/utils/tests/test_filemanip.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,41 @@ def test_copyfiles():
132132
os.unlink(new_hdr2)
133133

134134

135+
def test_linkchain():
136+
if os.name is not 'posix':
137+
return
138+
orig_img, orig_hdr = _temp_analyze_files()
139+
pth, fname = os.path.split(orig_img)
140+
new_img1 = os.path.join(pth, 'newfile1.img')
141+
new_hdr1 = os.path.join(pth, 'newfile1.hdr')
142+
new_img2 = os.path.join(pth, 'newfile2.img')
143+
new_hdr2 = os.path.join(pth, 'newfile2.hdr')
144+
new_img3 = os.path.join(pth, 'newfile3.img')
145+
new_hdr3 = os.path.join(pth, 'newfile3.hdr')
146+
copyfile(orig_img, new_img1)
147+
yield assert_true, os.path.islink(new_img1)
148+
yield assert_true, os.path.islink(new_hdr1)
149+
copyfile(new_img1, new_img2, copy=True)
150+
yield assert_false, os.path.islink(new_img2)
151+
yield assert_false, os.path.islink(new_hdr2)
152+
yield assert_false, os.path.samefile(orig_img, new_img2)
153+
yield assert_false, os.path.samefile(orig_hdr, new_hdr2)
154+
copyfile(new_img1, new_img3, copy=True, use_hardlink=True)
155+
yield assert_false, os.path.islink(new_img3)
156+
yield assert_false, os.path.islink(new_hdr3)
157+
yield assert_true, os.path.samefile(orig_img, new_img3)
158+
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)
159+
os.unlink(new_img1)
160+
os.unlink(new_hdr1)
161+
os.unlink(new_img2)
162+
os.unlink(new_hdr2)
163+
os.unlink(new_img3)
164+
os.unlink(new_hdr3)
165+
# final cleanup
166+
os.unlink(orig_img)
167+
os.unlink(orig_hdr)
168+
169+
135170
def test_filename_to_list():
136171
x = filename_to_list('foo.nii')
137172
yield assert_equal, x, ['foo.nii']

0 commit comments

Comments
 (0)