Skip to content

Commit

Permalink
Fix user_config_dir() for GCP/AWS functions
Browse files Browse the repository at this point in the history
Compatability fix for GCP functions and AWS lambda for user config directory in #4628
  • Loading branch information
glenn-jocher authored Sep 9, 2021
1 parent 0d8a184 commit 2df8c8a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2df8c8a

Please sign in to comment.