From 40af5b0fa7efdb723a043e0224c8cfd0cac73981 Mon Sep 17 00:00:00 2001 From: valfrom Date: Mon, 31 Jul 2023 16:56:19 +0200 Subject: [PATCH] Fix issue when config dir is created even if YOLO_CONFIG_DIR is set (#4054) Co-authored-by: Glenn Jocher --- ultralytics/utils/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ultralytics/utils/__init__.py b/ultralytics/utils/__init__.py index 9a63d431..aae007cb 100644 --- a/ultralytics/utils/__init__.py +++ b/ultralytics/utils/__init__.py @@ -568,9 +568,10 @@ def get_user_config_dir(sub_dir='Ultralytics'): raise ValueError(f'Unsupported operating system: {platform.system()}') # GCP and AWS lambda fix, only /tmp is writeable - if not is_dir_writeable(str(path.parent)): - path = Path('/tmp') / sub_dir - LOGGER.warning(f"WARNING ⚠️ user config directory is not writeable, defaulting to '{path}'.") + if not is_dir_writeable(path.parent): + LOGGER.warning(f"WARNING ⚠️ user config directory '{path}' is not writeable, defaulting to '/tmp' or CWD." + 'Alternatively you can define a YOLO_CONFIG_DIR environment variable for this path.') + path = Path('/tmp') / sub_dir if is_dir_writeable('/tmp') else Path().cwd() / sub_dir # Create the subdirectory if it does not exist path.mkdir(parents=True, exist_ok=True) @@ -578,7 +579,7 @@ def get_user_config_dir(sub_dir='Ultralytics'): return path -USER_CONFIG_DIR = Path(os.getenv('YOLO_CONFIG_DIR', get_user_config_dir())) # Ultralytics settings dir +USER_CONFIG_DIR = Path(os.getenv('YOLO_CONFIG_DIR') or get_user_config_dir()) # Ultralytics settings dir SETTINGS_YAML = USER_CONFIG_DIR / 'settings.yaml'