Skip to content
Snippets Groups Projects
Commit 5f8fd553 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'amohammadi-master-patch-38592' into 'master'

create_directories_safe: use the new exist_ok flag in os.makedirs.

See merge request !29
parents 8c178351 7015b0dd
No related branches found
No related tags found
1 merge request!29create_directories_safe: use the new exist_ok flag in os.makedirs.
Pipeline #38384 passed
......@@ -83,6 +83,7 @@ def _is_string(s):
isinstance(s, (bytes, str))
@numpy.deprecate(new_name="os.makedirs(directory, exist_ok=True)")
def create_directories_safe(directory, dryrun=False):
"""Creates a directory if it does not exists, with concurrent access support.
This function will also create any parent directories that might be required.
......@@ -97,17 +98,10 @@ def create_directories_safe(directory, dryrun=False):
``dryrun`` : bool
Only ``print`` the command to console, but do not execute it.
"""
try:
if dryrun:
print("[dry-run] mkdir -p '%s'" % directory)
else:
if directory and not os.path.exists(directory):
os.makedirs(directory)
except OSError as exc: # Python >2.5
import errno
if exc.errno != errno.EEXIST:
raise
if dryrun:
print("[dry-run] mkdir -p '%s'" % directory)
else:
os.makedirs(directory, exist_ok=True)
def load(inputs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment