From 85cc1373cb267ad9c9e72dfd6fbea081d8a1984d Mon Sep 17 00:00:00 2001 From: JJJHolscher Date: Sat, 30 Mar 2024 10:30:46 +0100 Subject: [PATCH] run_dir accepts strings now --- pyproject.toml | 2 +- src/root.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9fb4811..3cf94dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "jo3util" -version = "0.0.16" +version = "0.0.17" description = "" dependencies = [] dynamic = ["readme"] diff --git a/src/root.py b/src/root.py index cc748cb..91bae52 100644 --- a/src/root.py +++ b/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)