Skip to content

Commit c7735db

Browse files
committed
fix: address @effigies' review comments
1 parent a62a369 commit c7735db

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

nipype/utils/filemanip.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, path):
6060
try:
6161
Path('/invented/file/path').resolve(strict=True)
6262
except TypeError:
63-
from tempfile import gettempdir
63+
from tempfile import TemporaryDirectory
6464

6565
def _patch_resolve(self, strict=False):
6666
"""Add the argument strict to signature in Python>3,<3.6."""
@@ -80,15 +80,15 @@ def _write_text(self, text):
8080
Path.write_text = _write_text
8181

8282
try:
83-
with tempfile.TemporaryDirectory() as tmpdir:
83+
with TemporaryDirectory() as tmpdir:
8484
(Path(tmpdir) / 'exist_ok_test').mkdir(exist_ok=True)
8585
except TypeError:
8686
def _mkdir(self, mode=0o777, parents=False, exist_ok=False):
87-
if not exist_ok and self.exists():
88-
raise FileExistsError(str(self))
89-
if not parents and not Path(str(self.parents)).exists():
90-
raise FileNotFoundError(str(self.parents))
91-
os.makedirs(str(self), mode=mode, exist_ok=exist_ok)
87+
if parents:
88+
os.makedirs(str(self), mode=mode, exist_ok=exist_ok)
89+
elif not exist_ok or not self.exists():
90+
os.mkdir(str(self), mode=mode)
91+
9292
Path.mkdir = _mkdir
9393

9494
except FileNotFoundError:

nipype/utils/tests/test_filemanip.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,6 @@ def test_pickle(tmp_path, save_versioning):
601601
def test_Path(tmpdir):
602602
tmp_path = Path(tmpdir.strpath)
603603

604-
assert hasattr(tmp_path, 'write_text')
605-
606604
(tmp_path / 'textfile').write_text('some text')
607605

608606
with pytest.raises(OSError):

0 commit comments

Comments
 (0)