From e2ba58be5e98d236d7f7a86801779ad8b9db0a47 Mon Sep 17 00:00:00 2001 From: Jan Meyer <20856376+jan-meyer-1986@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:54:24 +0200 Subject: [PATCH 1/2] check ordered project directories candidates for project folders --- mlflow/getml/__init__.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mlflow/getml/__init__.py b/mlflow/getml/__init__.py index 49f598adffe7b..83b538a670921 100644 --- a/mlflow/getml/__init__.py +++ b/mlflow/getml/__init__.py @@ -100,6 +100,7 @@ def save_model( metadata=None, ): import getml + import sys _validate_env_arguments(conda_env, pip_requirements, extra_pip_requirements) path = os.path.abspath(path) @@ -107,24 +108,29 @@ def save_model( _validate_and_prepare_target_save_path(path) code_dir_subpath = _validate_and_copy_code_paths(code_paths, path) + getml_working_dir_candidates = [] current_user_home_dir = pathlib.Path.home() - getml_project_name = settings.get("project_name", getml.project.name) if settings else getml.project.name # type: ignore + if settings and (wd := settings.get("working_dir")): if not pathlib.Path(wd).exists(): raise Exception(f"{wd} Working directory does not exists") - getml_working_dir = pathlib.Path(wd) - elif (wd := current_user_home_dir / ".getML").exists(): - getml_working_dir = wd + getml_working_dir_candidates.append(pathlib.Path(wd)) + if (wd := current_user_home_dir / ".getML").exists(): + getml_working_dir_candidates.append(pathlib.Path(wd)) + if site_package_inst:= [f for f in pathlib.Path(sys.executable).parents[1].rglob('.getML')]: + getml_working_dir_candidates.append(pathlib.Path(site_package_inst[0])) + if getml_working_dir_candidates: + for candidate in getml_working_dir_candidates: + if ( + getml_project_folder := candidate / "projects" / getml_project_name + ).exists(): + break + else: + raise Exception(f"No project folder in any of these getml project directories exist: {getml_working_dir_candidates}") else: raise Exception("No default getML project directory") - assert getml_project_name - if not ( - getml_project_folder := getml_working_dir / "projects" / getml_project_name - ).exists(): - raise Exception(f"{getml_project_folder} does not exists") - if mlflow_model is None: mlflow_model = Model() From b5a7378b6d85e4aee69b63c66ec74714ca7c4326 Mon Sep 17 00:00:00 2001 From: Jan Meyer <20856376+jan-meyer-1986@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:12:54 +0200 Subject: [PATCH 2/2] print chosen path --- mlflow/getml/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mlflow/getml/__init__.py b/mlflow/getml/__init__.py index 83b538a670921..61e26ed5c2638 100644 --- a/mlflow/getml/__init__.py +++ b/mlflow/getml/__init__.py @@ -111,7 +111,7 @@ def save_model( getml_working_dir_candidates = [] current_user_home_dir = pathlib.Path.home() getml_project_name = settings.get("project_name", getml.project.name) if settings else getml.project.name # type: ignore - + if settings and (wd := settings.get("working_dir")): if not pathlib.Path(wd).exists(): raise Exception(f"{wd} Working directory does not exists") @@ -120,11 +120,13 @@ def save_model( getml_working_dir_candidates.append(pathlib.Path(wd)) if site_package_inst:= [f for f in pathlib.Path(sys.executable).parents[1].rglob('.getML')]: getml_working_dir_candidates.append(pathlib.Path(site_package_inst[0])) + if getml_working_dir_candidates: for candidate in getml_working_dir_candidates: if ( getml_project_folder := candidate / "projects" / getml_project_name ).exists(): + print(f'getml working directory chosen: {getml_project_folder}') break else: raise Exception(f"No project folder in any of these getml project directories exist: {getml_working_dir_candidates}")