Skip to content

Commit 06ba99f

Browse files
committed
fix(py2/34): address compatibility issues
1 parent e993a7f commit 06ba99f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

nipype/interfaces/base/traits_extension.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333

3434
from traits.api import Unicode
3535
from future import standard_library
36+
from ...utils.filemanip import Path, USING_PATHLIB2
3637

37-
from ...utils.filemanip import Path
38-
38+
if USING_PATHLIB2:
39+
from future.types.newstr import newstr
3940

4041
if traits_version < '3.7.0':
4142
raise ImportError('Traits version 3.7.0 or higher must be installed')
@@ -127,7 +128,9 @@ def __init__(self, value=Undefined,
127128
def validate(self, objekt, name, value, return_pathlike=False):
128129
"""Validate a value change."""
129130
try:
130-
value = Path('%s' % value) # Use pathlib's validation
131+
if USING_PATHLIB2 and isinstance(value, newstr):
132+
value = '%s' % value # pathlib2 doesn't like newstr
133+
value = Path(value) # Use pathlib's validation
131134
except Exception:
132135
self.error(objekt, name, str(value))
133136

nipype/utils/filemanip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242

4343
class FileNotFoundError(OSError):
44-
"""Defines the expception for Python 2."""
44+
"""Defines the exception for Python 2."""
4545

4646
def __init__(self, path):
4747
"""Initialize the exception."""
@@ -75,7 +75,7 @@ def _patch_resolve(self, strict=False):
7575
pass
7676
except OSError:
7777
def _patch_resolve(self, strict=False):
78-
"""Add the argument strict to signature for pathlib2."""
78+
"""Raise FileNotFoundError instead of OSError with pathlib2."""
7979
try:
8080
resolved = self.old_resolve(strict=strict)
8181
except OSError:

nipype/utils/tests/test_filemanip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,5 +585,5 @@ def test_Path_strict_resolve(tmpdir):
585585
testfile.resolve(strict=True)
586586

587587
# If the file is created, it should not raise
588-
testfile.write_text('')
588+
open('somefile.txt', 'w').close()
589589
assert '%s/somefile.txt' % tmpdir == '%s' % testfile.resolve(strict=True)

0 commit comments

Comments
 (0)