run_dir accepts strings now
This commit is contained in:
parent
b52d72d087
commit
85cc1373cb
|
@ -1,7 +1,7 @@
|
|||
|
||||
[project]
|
||||
name = "jo3util"
|
||||
version = "0.0.16"
|
||||
version = "0.0.17"
|
||||
description = ""
|
||||
dependencies = []
|
||||
dynamic = ["readme"]
|
||||
|
|
15
src/root.py
15
src/root.py
|
@ -5,7 +5,7 @@ import os
|
|||
import json
|
||||
from importlib.resources import files, as_file
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
import __main__
|
||||
from .string import hash_string
|
||||
|
@ -81,10 +81,13 @@ def root_file():
|
|||
raise NotImplementedError
|
||||
|
||||
|
||||
def run_dir(obj, root=Path(os.path.abspath("./run")), name_len=8):
|
||||
run_id: str = json.dumps(
|
||||
def run_dir(
|
||||
obj,
|
||||
root: Union[Path, str] = root_dir() / "run",
|
||||
name_len=8
|
||||
):
|
||||
obj_hash: str = hash_string(json.dumps(
|
||||
obj,
|
||||
default=lambda x: vars(x) if hasattr(x, "__dict__") else str(x)
|
||||
)
|
||||
run_id: str = hash_string(run_id)[:name_len]
|
||||
return root / run_id
|
||||
))[:name_len]
|
||||
return root / Path(obj_hash)
|
||||
|
|
Loading…
Reference in New Issue
Block a user