cache from toml must be used with a title
This commit is contained in:
@@ -65,9 +65,12 @@ class Cache:
|
||||
return cls(group)
|
||||
|
||||
@classmethod
|
||||
def from_toml(cls, s: str, /, create: bool = True) -> Self:
|
||||
hashed = hashlib.md5(pickle.dumps(sort_dict(tomllib.loads(s)))).hexdigest()
|
||||
group = f"TOML-{hashed}"
|
||||
def from_toml(cls, name: str, toml_str: str, /, create: bool = True) -> Self:
|
||||
hashed = hashlib.md5(pickle.dumps(sort_dict(tomllib.loads(toml_str)))).hexdigest()
|
||||
if len(name) > 50:
|
||||
warnings.warn(f"name {name!r} is longer than 30 characters")
|
||||
name = name[:50]
|
||||
group = f"TOML-{name}-{hashed}"
|
||||
if create:
|
||||
os.makedirs(CACHE_DIR / group, exist_ok=True)
|
||||
return cls(group)
|
||||
|
||||
@@ -51,9 +51,9 @@ def test_toml():
|
||||
rin_measurement='./DualComb1GHz_updated_corrected_extrapolated_1GHz_noqn.csv'
|
||||
"""
|
||||
|
||||
cache1 = Cache.from_toml(s1)
|
||||
cache3 = Cache.from_toml(s3, create=False)
|
||||
assert cache1.dir == Cache.from_toml(s2).dir
|
||||
cache1 = Cache.from_toml("test", s1)
|
||||
cache3 = Cache.from_toml("test", s3, create=False)
|
||||
assert cache1.dir == Cache.from_toml("test", s2).dir
|
||||
assert cache1.dir != cache3.dir
|
||||
assert cache1.dir.exists()
|
||||
cache1.delete()
|
||||
|
||||
Reference in New Issue
Block a user