run_dir accepts strings now

This commit is contained in:
JJJHolscher 2024-03-30 10:30:46 +01:00
parent b52d72d087
commit 85cc1373cb
2 changed files with 10 additions and 7 deletions

View File

@ -1,7 +1,7 @@
[project] [project]
name = "jo3util" name = "jo3util"
version = "0.0.16" version = "0.0.17"
description = "" description = ""
dependencies = [] dependencies = []
dynamic = ["readme"] dynamic = ["readme"]

View File

@ -5,7 +5,7 @@ import os
import json import json
from importlib.resources import files, as_file from importlib.resources import files, as_file
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional, Union
import __main__ import __main__
from .string import hash_string from .string import hash_string
@ -81,10 +81,13 @@ def root_file():
raise NotImplementedError raise NotImplementedError
def run_dir(obj, root=Path(os.path.abspath("./run")), name_len=8): def run_dir(
run_id: str = json.dumps( obj,
root: Union[Path, str] = root_dir() / "run",
name_len=8
):
obj_hash: str = hash_string(json.dumps(
obj, obj,
default=lambda x: vars(x) if hasattr(x, "__dict__") else str(x) default=lambda x: vars(x) if hasattr(x, "__dict__") else str(x)
) ))[:name_len]
run_id: str = hash_string(run_id)[:name_len] return root / Path(obj_hash)
return root / run_id