Fix `user_config_dir()` for GCP/AWS functions (#4726)
* Fix `user_config_dir()` for GCP/AWS functions Compatability fix for GCP functions and AWS lambda for user config directory in https://github.com/ultralytics/yolov5/pull/4628 * Windows skip check
This commit is contained in:
parent
2d9411dbb8
commit
4a025ae97f
|
|
@ -105,13 +105,21 @@ def get_latest_run(search_dir='.'):
|
||||||
|
|
||||||
def user_config_dir(dir='Ultralytics'):
|
def user_config_dir(dir='Ultralytics'):
|
||||||
# Return path of user configuration directory (make if necessary)
|
# Return path of user configuration directory (make if necessary)
|
||||||
settings = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'}
|
system = platform.system()
|
||||||
path = Path.home() / settings.get(platform.system(), '') / dir
|
cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'}
|
||||||
|
path = Path.home() / cfg.get(system, '') / dir
|
||||||
|
if system == 'Linux' and not is_writeable(path): # GCP functions and AWS lambda solution, only /tmp is writeable
|
||||||
|
path = Path('/tmp') / dir
|
||||||
if not path.is_dir():
|
if not path.is_dir():
|
||||||
path.mkdir() # make dir if required
|
path.mkdir() # make dir if required
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def is_writeable(path):
|
||||||
|
# Return True if path has write permissions (Warning: known issue on Windows)
|
||||||
|
return os.access(path, os.R_OK)
|
||||||
|
|
||||||
|
|
||||||
def is_docker():
|
def is_docker():
|
||||||
# Is environment a Docker container?
|
# Is environment a Docker container?
|
||||||
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue