Unverified 提交 cd810c82 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Centralize `user_config_dir()` decision making (#4755)

上级 22ee6fb7
...@@ -103,11 +103,15 @@ def get_latest_run(search_dir='.'): ...@@ -103,11 +103,15 @@ def get_latest_run(search_dir='.'):
return max(last_list, key=os.path.getctime) if last_list else '' return max(last_list, key=os.path.getctime) if last_list else ''
def user_config_dir(dir='Ultralytics'): def user_config_dir(dir='Ultralytics', env_var='YOLOV5_CONFIG_DIR'):
# Return path of user configuration directory (make if necessary) # Return path of user configuration directory. Prefer environment variable if exists. Make dir if required.
cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} # 3 config dirs env = os.getenv(env_var)
path = Path.home() / cfg.get(platform.system(), '') # OS-specific config dir if env:
path = (path if is_writeable(path) else Path('/tmp')) / dir # GCP and AWS lambda fix, only /tmp is writeable 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 path.mkdir(exist_ok=True) # make if required
return path return path
......
...@@ -4,7 +4,6 @@ Plotting utils ...@@ -4,7 +4,6 @@ Plotting utils
""" """
import math import math
import os
from copy import copy from copy import copy
from pathlib import Path from pathlib import Path
...@@ -21,7 +20,7 @@ from utils.general import user_config_dir, is_ascii, xywh2xyxy, xyxy2xywh ...@@ -21,7 +20,7 @@ from utils.general import user_config_dir, is_ascii, xywh2xyxy, xyxy2xywh
from utils.metrics import fitness from utils.metrics import fitness
# Settings # Settings
CONFIG_DIR = Path(os.getenv('YOLOV5_CONFIG_DIR') or user_config_dir()) # Ultralytics settings dir CONFIG_DIR = user_config_dir() # Ultralytics settings dir
matplotlib.rc('font', **{'size': 11}) matplotlib.rc('font', **{'size': 11})
matplotlib.use('Agg') # for writing to files only matplotlib.use('Agg') # for writing to files only
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论