From 98a172e83e1a9257ec1295c891e82c50746daa31 Mon Sep 17 00:00:00 2001 From: Nitin Rai Date: Mon, 24 May 2021 13:51:37 +0530 Subject: [PATCH 1/2] Fail safe makedirs A more pythonic way to create directories if doens't exists. --- imagine/imagine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imagine/imagine.py b/imagine/imagine.py index 53fc35c..e060349 100755 --- a/imagine/imagine.py +++ b/imagine/imagine.py @@ -119,8 +119,8 @@ def _try_create_directory(directory: str) -> NoReturn: directory : string A ``string`` of a path pointing to a directory to attempt to create. """ - if not os.path.exists(directory): - os.mkdir(directory) + + os.makedirs(directory, exist_ok=True) def _check_directory_exists(directory: str) -> NoReturn: From 0116316ce7ef91ecf9e5d8f636236ac8c6d277d3 Mon Sep 17 00:00:00 2001 From: nitin Date: Wed, 26 May 2021 09:40:01 +0530 Subject: [PATCH 2/2] Removed extra line Signed-Off-By: Nitin Rai mneonizer@gmail.com --- imagine/imagine.py | 1 - 1 file changed, 1 deletion(-) diff --git a/imagine/imagine.py b/imagine/imagine.py index e060349..6c1fcb6 100755 --- a/imagine/imagine.py +++ b/imagine/imagine.py @@ -119,7 +119,6 @@ def _try_create_directory(directory: str) -> NoReturn: directory : string A ``string`` of a path pointing to a directory to attempt to create. """ - os.makedirs(directory, exist_ok=True)