Skip to content
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

FIX: Patch Path.mkdir for Python 2 #3037

Merged
merged 1 commit into from
Sep 18, 2019
Merged
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
29 changes: 14 additions & 15 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,18 @@ def _write_text(self, text):
f.write(text)
Path.write_text = _write_text

if PY3:
try: # PY34 - mkdir does not have exist_ok
from tempfile import TemporaryDirectory
with TemporaryDirectory() as tmpdir:
(Path(tmpdir) / 'exist_ok_test').mkdir(exist_ok=True)
except TypeError:
def _mkdir(self, mode=0o777, parents=False, exist_ok=False):
if parents:
os.makedirs(str(self), mode=mode, exist_ok=exist_ok)
elif not exist_ok or not self.exists():
os.mkdir(str(self), mode=mode)
try: # PY27/PY34 - mkdir does not have exist_ok
from .tmpdirs import TemporaryDirectory
with TemporaryDirectory() as tmpdir:
(Path(tmpdir) / 'exist_ok_test').mkdir(exist_ok=True)
except TypeError:
def _mkdir(self, mode=0o777, parents=False, exist_ok=False):
if parents:
makedirs(str(self), mode=mode, exist_ok=exist_ok)
elif not exist_ok or not self.exists():
os.mkdir(str(self), mode=mode)

Path.mkdir = _mkdir
Path.mkdir = _mkdir


def split_filename(fname):
Expand Down Expand Up @@ -828,7 +827,7 @@ def dist_is_editable(dist):
return False


def makedirs(path, exist_ok=False):
def makedirs(path, mode=0o777, exist_ok=False):
mgxd marked this conversation as resolved.
Show resolved Hide resolved
"""
Create path, if it doesn't exist.

Expand All @@ -838,14 +837,14 @@ def makedirs(path, exist_ok=False):

"""
if not exist_ok: # The old makedirs
os.makedirs(path)
os.makedirs(path, mode=mode)
return path

# this odd approach deals with concurrent directory cureation
if not op.exists(op.abspath(path)):
fmlogger.debug("Creating directory %s", path)
try:
os.makedirs(path)
os.makedirs(path, mode=mode)
except OSError:
fmlogger.debug("Problem creating directory %s", path)
if not op.exists(path):
Expand Down