mirror of
https://github.com/clearml/clearml
synced 2025-02-07 21:33:25 +00:00
Fix always store session cache in ~/.clearml (regardless of the cache folder)
This commit is contained in:
parent
977d68169b
commit
e4df21ea52
@ -1,8 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
|
from os.path import expanduser
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from pathlib2 import Path
|
||||||
|
|
||||||
from . import get_cache_dir, running_remotely
|
from . import running_remotely
|
||||||
from .defs import SESSION_CACHE_FILE
|
from .defs import SESSION_CACHE_FILE
|
||||||
|
|
||||||
|
|
||||||
@ -12,21 +14,26 @@ class SessionCache(object):
|
|||||||
TODO: Improve error handling to something like "except (FileNotFoundError, PermissionError, JSONDecodeError)"
|
TODO: Improve error handling to something like "except (FileNotFoundError, PermissionError, JSONDecodeError)"
|
||||||
TODO: that's both six-compatible and tested
|
TODO: that's both six-compatible and tested
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
SESSION_CACHE_FOLDER = "~/.clearml"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load_cache(cls):
|
def _load_cache(cls):
|
||||||
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
flag = 'rb' if six.PY2 else 'rt'
|
flag = 'rb' if six.PY2 else 'rt'
|
||||||
with (get_cache_dir() / SESSION_CACHE_FILE).open(flag) as fp:
|
with (Path(expanduser(cls.SESSION_CACHE_FOLDER)) / SESSION_CACHE_FILE).open(flag) as fp:
|
||||||
return json.load(fp)
|
return json.load(fp)
|
||||||
except Exception:
|
except Exception:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _store_cache(cls, cache):
|
def _store_cache(cls, cache):
|
||||||
|
# noinspection PyBroadException
|
||||||
try:
|
try:
|
||||||
get_cache_dir().mkdir(parents=True, exist_ok=True)
|
Path(expanduser(cls.SESSION_CACHE_FOLDER)).mkdir(parents=True, exist_ok=True)
|
||||||
flag = 'wb' if six.PY2 else 'wt'
|
flag = 'wb' if six.PY2 else 'wt'
|
||||||
with (get_cache_dir() / SESSION_CACHE_FILE).open(flag) as fp:
|
with (Path(expanduser(cls.SESSION_CACHE_FOLDER)) / SESSION_CACHE_FILE).open(flag) as fp:
|
||||||
json.dump(cache, fp)
|
json.dump(cache, fp)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user