From e8879c10c1400a45aca4f36b9d9f8f7e7be3f5fe Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:57:31 -0700 Subject: [PATCH] Create export path if not present (#3331) Co-authored-by: Ankith Gunapal --- model-archiver/model_archiver/model_packaging_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/model-archiver/model_archiver/model_packaging_utils.py b/model-archiver/model_archiver/model_packaging_utils.py index 8b81af9f73..465582dd6d 100644 --- a/model-archiver/model_archiver/model_packaging_utils.py +++ b/model-archiver/model_archiver/model_packaging_utils.py @@ -43,6 +43,8 @@ MANIFEST_FILE_NAME = "MANIFEST.json" MAR_INF = "MAR-INF" +logger = logging.getLogger(__file__) + class ModelExportUtils(object): """ @@ -366,7 +368,12 @@ def check_model_name_regex_or_exit(model_name): @staticmethod def validate_inputs(model_name, export_path): ModelExportUtils.check_model_name_regex_or_exit(model_name) - if not os.path.isdir(os.path.abspath(export_path)): + if not os.path.exists(os.path.abspath(export_path)): + logger.warning( + f"Export directory ({export_path}) does not exist. Creating..." + ) + os.makedirs(os.path.abspath(export_path)) + elif not os.path.isdir(os.path.abspath(export_path)): raise ModelArchiverError( "Given export-path {} is not a directory. " "Point to a valid export-path directory.".format(export_path)