From 389493bb1e1d8b46b9afcb4c9f613d1363c85ba3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 9 Sep 2021 13:12:58 +0200 Subject: [PATCH 1/2] 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 --- utils/general.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 06bf088582dc..88e841d5a542 100755 --- a/utils/general.py +++ b/utils/general.py @@ -105,13 +105,20 @@ def get_latest_run(search_dir='.'): def user_config_dir(dir='Ultralytics'): # Return path of user configuration directory (make if necessary) - settings = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} - path = Path.home() / settings.get(platform.system(), '') / dir + cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} + path = Path.home() / cfg.get(platform.system(), '') / dir + if not is_writeable(path): # GCP functions and AWS lambda solution, only /tmp is writeable + path = Path('/tmp') / dir if not path.is_dir(): path.mkdir() # make dir if required return path +def is_writeable(path): + # Return True if path has write permissions + return os.access(path, os.R_OK) + + def is_docker(): # Is environment a Docker container? return Path('/workspace').exists() # or Path('/.dockerenv').exists() From b6dfca74290743b56eab39c058f75a42bf8837d3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 9 Sep 2021 13:40:19 +0200 Subject: [PATCH 2/2] Windows skip check --- utils/general.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/general.py b/utils/general.py index 88e841d5a542..e3fc31e0bd81 100755 --- a/utils/general.py +++ b/utils/general.py @@ -105,9 +105,10 @@ def get_latest_run(search_dir='.'): def user_config_dir(dir='Ultralytics'): # Return path of user configuration directory (make if necessary) + system = platform.system() cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} - path = Path.home() / cfg.get(platform.system(), '') / dir - if not is_writeable(path): # GCP functions and AWS lambda solution, only /tmp is writeable + 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(): path.mkdir() # make dir if required @@ -115,7 +116,7 @@ def user_config_dir(dir='Ultralytics'): def is_writeable(path): - # Return True if path has write permissions + # Return True if path has write permissions (Warning: known issue on Windows) return os.access(path, os.R_OK)