From c82bdd6dff119be0d14e7655c0a5dfb543932dcc Mon Sep 17 00:00:00 2001 From: changzherui Date: Tue, 18 Jan 2022 22:38:13 +0800 Subject: [PATCH] modify context make dir --- mindspore/python/mindspore/context.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/mindspore/python/mindspore/context.py b/mindspore/python/mindspore/context.py index 8e622f2c14f..ec2c20dae7d 100644 --- a/mindspore/python/mindspore/context.py +++ b/mindspore/python/mindspore/context.py @@ -44,28 +44,23 @@ _k_context = None def _make_directory(path): """Make directory.""" - real_path = None if path is None or not isinstance(path, str) or path.strip() == "": raise ValueError(f"For 'context.set_context', the 'save_graphs_path' or the 'print_file_path' is invalid " f"type, it should be Non-empty string, but got '{path}'.") - # convert the relative paths path = os.path.realpath(path) logger.debug("The absolute path is %r", path) - # check whether the path is already existed and has written permissions - if os.path.exists(path): - real_path = path - else: - # All exceptions need to be caught because create directory maybe have some limit(permissions) + if not os.path.exists(path): logger.debug("The directory(%s) doesn't exist, will create it", path) try: os.makedirs(path) - real_path = path + except FileExistsError: + logger.debug("The directory(%s) already exist.", path) except PermissionError as e: logger.critical(f"No write permission on the directory '{path}'', error = {e}") raise ValueError(e.__str__() + f"\nNo write permission on the directory '{path}'.") - return real_path + return path def _get_print_file_name(file_name):