Centralize user_config_dir() decision making (#4755)
This commit is contained in:
1 parent
22ee6fb7c1
commit
cd810c8286
2 files changed
+10
-7
No files matched your search
+9
-5
@@ -103,11 +103,15 @@ def get_latest_run(search_dir='.'):
|
||||
return max(last_list, key=os.path.getctime) if last_list else ''
|
||||
|
||||
|
||||
def user_config_dir(dir='Ultralytics'):
|
||||
# Return path of user configuration directory (make if necessary)
|
||||
cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} # 3 config dirs
|
||||
path = Path.home() / cfg.get(platform.system(), '') # OS-specific config dir
|
||||
path = (path if is_writeable(path) else Path('/tmp')) / dir # GCP and AWS lambda fix, only /tmp is writeable
|
||||
def user_config_dir(dir='Ultralytics', env_var='YOLOV5_CONFIG_DIR'):
|
||||
# Return path of user configuration directory. Prefer environment variable if exists. Make dir if required.
|
||||
env = os.getenv(env_var)
|
||||
if env:
|
||||
path = Path(env) # use environment variable
|
||||
else:
|
||||
cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} # 3 OS dirs
|
||||
path = Path.home() / cfg.get(platform.system(), '') # OS-specific config dir
|
||||
path = (path if is_writeable(path) else Path('/tmp')) / dir # GCP and AWS lambda fix, only /tmp is writeable
|
||||
path.mkdir(exist_ok=True) # make if required
|
||||
return path
|
||||
|
||||
|
||||
Reference in new issue
Block a user