liblaf-cherries 0.0.12__py3-none-any.whl → 0.0.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,13 +8,13 @@ from .pathutils import (
8
8
  config,
9
9
  data,
10
10
  entrypoint,
11
- exp_dir,
12
11
  git_root,
13
12
  git_root_safe,
14
13
  inputs,
15
14
  outputs,
16
15
  params,
17
16
  path,
17
+ run_dir,
18
18
  src,
19
19
  )
20
20
  from .plugin import (
@@ -61,7 +61,6 @@ __all__ = [
61
61
  "data",
62
62
  "end",
63
63
  "entrypoint",
64
- "exp_dir",
65
64
  "git_root",
66
65
  "git_root_safe",
67
66
  "info",
@@ -82,6 +81,7 @@ __all__ = [
82
81
  "plugin",
83
82
  "presets",
84
83
  "run",
84
+ "run_dir",
85
85
  "set_tag",
86
86
  "src",
87
87
  "start",
liblaf/cherries/_run.py CHANGED
@@ -17,9 +17,9 @@ def run[C: pydantic.BaseModel, T](main: Callable[[C], T]) -> T:
17
17
  ret: T = main(cfg)
18
18
  except BaseException as e:
19
19
  if isinstance(e, KeyboardInterrupt):
20
- run.end("KILLED")
20
+ run.end(plugin.RunStatus.KILLED)
21
21
  raise
22
- run.end("FAILED")
22
+ run.end(plugin.RunStatus.FAILED)
23
23
  raise
24
24
  else:
25
25
  run.end()
@@ -31,7 +31,7 @@ def start() -> plugin.Run:
31
31
  run.start()
32
32
  run.log_src(_path.entrypoint(absolute=True))
33
33
  run.set_tag("cherries.entrypoint", _path.entrypoint(absolute=False))
34
- run.set_tag("cherries.exp-dir", _path.exp_dir(absolute=False))
34
+ run.set_tag("cherries.run-dir", _path.run_dir(absolute=False))
35
35
  return plugin.run
36
36
 
37
37
 
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.0.12'
21
- __version_tuple__ = version_tuple = (0, 0, 12)
20
+ __version__ = version = '0.0.14'
21
+ __version_tuple__ = version_tuple = (0, 0, 14)
@@ -1,5 +1,5 @@
1
- from ._exp_name import exp_name
2
1
  from ._git import git_auto_commit, git_branch, git_commit_sha, git_commit_url, git_info
2
+ from ._name import exp_name, run_name
3
3
 
4
4
  __all__ = [
5
5
  "exp_name",
@@ -8,4 +8,5 @@ __all__ = [
8
8
  "git_commit_sha",
9
9
  "git_commit_url",
10
10
  "git_info",
11
+ "run_name",
11
12
  ]
@@ -1,7 +1,10 @@
1
+ from pathlib import Path
2
+
1
3
  import git.exc
2
4
  from environs import env
3
5
 
4
6
  from liblaf import grapes
7
+ from liblaf.cherries import pathutils as _path
5
8
 
6
9
  from ._git import git_info
7
10
 
@@ -17,3 +20,11 @@ def exp_name() -> str:
17
20
  return "Default"
18
21
  else:
19
22
  return info.repo
23
+
24
+
25
+ def run_name() -> str:
26
+ run_dir: Path = _path.run_dir(absolute=False)
27
+ run_name: str = _path.as_posix(run_dir)
28
+ run_name = run_name.removeprefix("exp")
29
+ run_name = run_name.removeprefix("/")
30
+ return run_name
@@ -1,5 +1,5 @@
1
1
  from ._convert import as_os_path, as_path, as_posix
2
- from ._path import entrypoint, exp_dir, git_root, git_root_safe
2
+ from ._path import entrypoint, git_root, git_root_safe, run_dir
3
3
  from ._special import config, data, inputs, outputs, params, path, src
4
4
 
5
5
  __all__ = [
@@ -9,12 +9,12 @@ __all__ = [
9
9
  "config",
10
10
  "data",
11
11
  "entrypoint",
12
- "exp_dir",
13
12
  "git_root",
14
13
  "git_root_safe",
15
14
  "inputs",
16
15
  "outputs",
17
16
  "params",
18
17
  "path",
18
+ "run_dir",
19
19
  "src",
20
20
  ]
@@ -15,13 +15,6 @@ def entrypoint(*, absolute: bool = False) -> Path:
15
15
  return _entrypoint_relative()
16
16
 
17
17
 
18
- @utils.cache
19
- def exp_dir(*, absolute: bool = False) -> Path:
20
- if absolute:
21
- return _exp_dir_absolute()
22
- return _exp_dir_relative()
23
-
24
-
25
18
  @utils.cache
26
19
  def git_root() -> Path:
27
20
  entrypoint: Path = _entrypoint_absolute()
@@ -38,6 +31,13 @@ def git_root_safe() -> Path:
38
31
  return _entrypoint_absolute().parent
39
32
 
40
33
 
34
+ @utils.cache
35
+ def run_dir(*, absolute: bool = False) -> Path:
36
+ if absolute:
37
+ return _run_dir_absolute()
38
+ return _run_dir_relative()
39
+
40
+
41
41
  @utils.cache
42
42
  def _entrypoint_absolute() -> Path:
43
43
  path = Path(sys.argv[0])
@@ -51,7 +51,7 @@ def _entrypoint_relative() -> Path:
51
51
 
52
52
 
53
53
  @utils.cache
54
- def _exp_dir_absolute() -> Path:
54
+ def _run_dir_absolute() -> Path:
55
55
  entrypoint: Path = _entrypoint_absolute()
56
56
  for path in entrypoint.parents:
57
57
  if (path / "exp.cherries.toml").is_file():
@@ -62,7 +62,7 @@ def _exp_dir_absolute() -> Path:
62
62
 
63
63
 
64
64
  @utils.cache
65
- def _exp_dir_relative() -> Path:
66
- absolute: Path = _exp_dir_absolute()
65
+ def _run_dir_relative() -> Path:
66
+ absolute: Path = _run_dir_absolute()
67
67
  root: Path = git_root_safe()
68
68
  return absolute.relative_to(root)
@@ -2,7 +2,7 @@ from pathlib import Path
2
2
 
3
3
  from liblaf.grapes.typed import PathLike
4
4
 
5
- from ._path import exp_dir
5
+ from ._path import run_dir
6
6
 
7
7
 
8
8
  def config(
@@ -44,7 +44,7 @@ def src(path: PathLike = "", *, mkdir: bool = True, prefix: PathLike = "src") ->
44
44
  def _path(path: PathLike = "", *, mkdir: bool = True, prefix: PathLike = "") -> Path:
45
45
  path = Path(path)
46
46
  if not path.is_absolute():
47
- path = exp_dir(absolute=True) / prefix / path
47
+ path = run_dir(absolute=True) / prefix / path
48
48
  if mkdir:
49
49
  path.parent.mkdir(parents=True, exist_ok=True)
50
50
  return path
@@ -3,6 +3,8 @@ from pathlib import Path
3
3
  from typing import override
4
4
 
5
5
  import attrs
6
+ import git
7
+ import git.exc
6
8
 
7
9
  from liblaf.cherries import pathutils as _path
8
10
  from liblaf.cherries.typed import PathLike
@@ -25,7 +27,9 @@ class DvcLogArtifact(LogArtifact):
25
27
  self, local_path: PathLike, artifact_path: PathLike | None = None, **kwargs
26
28
  ) -> Path:
27
29
  local_path: Path = _path.as_path(local_path)
28
- sp.run(["dvc", "add", local_path], check=False)
30
+ if check_ignore(local_path) or tracked_by_git(local_path):
31
+ return local_path
32
+ sp.run(["dvc", "add", local_path], check=True)
29
33
  return local_path
30
34
 
31
35
 
@@ -36,7 +40,9 @@ class DvcLogArtifacts(LogArtifacts):
36
40
  self, local_dir: PathLike, artifact_path: PathLike | None = None, **kwargs
37
41
  ) -> Path:
38
42
  local_dir: Path = _path.as_path(local_dir)
39
- sp.run(["dvc", "add", local_dir], check=False)
43
+ if check_ignore(local_dir) or tracked_by_git(local_dir):
44
+ return local_dir
45
+ sp.run(["dvc", "add", local_dir], check=True)
40
46
  return local_dir
41
47
 
42
48
 
@@ -45,3 +51,13 @@ def check_ignore(local_path: PathLike) -> bool:
45
51
  ["dvc", "check-ignore", local_path], check=False
46
52
  )
47
53
  return proc.returncode == 0
54
+
55
+
56
+ def tracked_by_git(local_path: PathLike) -> bool:
57
+ local_path: Path = _path.as_path(local_path).absolute()
58
+ try:
59
+ repo = git.Repo(search_parent_directories=True)
60
+ repo.git.ls_files(local_path, error_unmatch=True)
61
+ except git.exc.GitCommandError:
62
+ return False
63
+ return True
@@ -25,7 +25,7 @@ class LoggingStart(Start):
25
25
  grapes.init_logging(
26
26
  handlers=[
27
27
  grapes.logging.rich_handler(),
28
- grapes.logging.file_handler(file=run.exp_dir / "run.log"),
29
- grapes.logging.jsonl_handler(run.exp_dir / "run.log.jsonl"),
28
+ grapes.logging.file_handler(sink=run.exp_dir / "run.log"),
29
+ grapes.logging.jsonl_handler(sink=run.exp_dir / "run.log.jsonl"),
30
30
  ]
31
31
  )
@@ -3,7 +3,6 @@ from typing import Any, override
3
3
 
4
4
  import attrs
5
5
  import mlflow
6
- import mlflow.entities
7
6
 
8
7
  from liblaf.cherries import info as _info
9
8
  from liblaf.cherries import pathutils as _path
@@ -34,6 +33,9 @@ class MlflowLogArtifact(LogArtifact):
34
33
  def __call__(
35
34
  self, local_path: PathLike, artifact_path: PathLike | None = None, **kwargs
36
35
  ) -> Path:
36
+ local_path: Path = _path.as_path(local_path)
37
+ if (dvc_file := local_path.with_name(local_path.name + ".dvc")).is_file():
38
+ local_path = dvc_file
37
39
  mlflow.log_artifact(
38
40
  _path.as_os_path(local_path), _path.as_posix(artifact_path), **kwargs
39
41
  )
@@ -46,6 +48,9 @@ class MlflowLogArtifacts(LogArtifacts):
46
48
  def __call__(
47
49
  self, local_dir: PathLike, artifact_path: PathLike | None = None, **kwargs
48
50
  ) -> Path:
51
+ local_dir: Path = _path.as_path(local_dir)
52
+ if (dvc_file := local_dir.with_name(local_dir.name + ".dvc")).is_file():
53
+ local_dir = dvc_file
49
54
  mlflow.log_artifact(
50
55
  _path.as_os_path(local_dir), _path.as_posix(artifact_path), **kwargs
51
56
  )
@@ -80,4 +85,4 @@ class MlflowStart(Start):
80
85
  @override
81
86
  def __call__(self) -> None:
82
87
  mlflow.set_experiment(_info.exp_name())
83
- mlflow.start_run()
88
+ mlflow.start_run(run_name=_info.run_name())
@@ -27,7 +27,7 @@ class Run:
27
27
 
28
28
  @functools.cached_property
29
29
  def exp_dir(self) -> Path:
30
- return _path.exp_dir(absolute=True)
30
+ return _path.run_dir(absolute=True)
31
31
 
32
32
  @property
33
33
  def exp_id(self) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: liblaf-cherries
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: Add your description here
5
5
  Project-URL: Changelog, https://github.com/liblaf/cherries/blob/main/CHANGELOG.md
6
6
  Project-URL: Documentation, https://liblaf.github.io/cherries/
@@ -35,7 +35,7 @@ Requires-Dist: dvc[webdav]<4,>=3.59.2
35
35
  Requires-Dist: environs<15,>=14.1.1
36
36
  Requires-Dist: gitpython<4,>=3.1.44
37
37
  Requires-Dist: lazy-loader<0.5,>=0.4
38
- Requires-Dist: liblaf-grapes<0.2,>=0.1.21
38
+ Requires-Dist: liblaf-grapes<0.2,>=0.1.25
39
39
  Requires-Dist: loguru<0.8,>=0.7.3
40
40
  Requires-Dist: mlflow<3,>=2.22.0
41
41
  Requires-Dist: pydantic-settings<3,>=2.9.1
@@ -1,35 +1,35 @@
1
1
  liblaf/cherries/__init__.py,sha256=OHb6Xou2v6u42swTgjRfzej4CIlRg4OmgOIQXUiRjKA,97
2
- liblaf/cherries/__init__.pyi,sha256=SuZgWY0gRNMTU-rAapdJ5mCHyYqeQmlR9DosaViUx1A,1370
2
+ liblaf/cherries/__init__.pyi,sha256=ShYXNS05TvRjr5XTKurtBiToTR3T1JX2Ub0njjbMsuM,1370
3
3
  liblaf/cherries/_config.py,sha256=rm-Y6roi8hBvQYdH-VQh_ovWCyVsX_7R0x1jokBPCDM,741
4
- liblaf/cherries/_run.py,sha256=aJonztFyqBeg9otqMGwkh2AOEjtFh85sC1riBa1ty38,1055
5
- liblaf/cherries/_version.py,sha256=yXPCLHqHWroxl6PYku74xz7jqX7Xrf288eRJfEDWwBo,513
4
+ liblaf/cherries/_run.py,sha256=vbJ5-Fh8azNhemVf4qyNUc5RaFA8HgFHZOmzdRMPF2k,1085
5
+ liblaf/cherries/_version.py,sha256=JAP571q66KmOqXyFj53ns1X0_trh2aTxt2bW41ljMkc,513
6
6
  liblaf/cherries/_version.pyi,sha256=Pnv4Bxw13LHeuVkPLPsTtnp4N4jOGcAfFJw05uMMgBY,108
7
7
  liblaf/cherries/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  liblaf/cherries/typed.py,sha256=mim8QVtwczTSHyw5mhEdfFcXis9o32n0CZyu8BrEorE,50
9
9
  liblaf/cherries/info/__init__.py,sha256=OHb6Xou2v6u42swTgjRfzej4CIlRg4OmgOIQXUiRjKA,97
10
- liblaf/cherries/info/__init__.pyi,sha256=UsHH6XpE_RRre9sJdwgzOnV9HElnE00ltRKnfXOQso4,252
11
- liblaf/cherries/info/_exp_name.py,sha256=dlC1OIg9RM2oYW7qsWCF6AGV0z6bbQxpJOsdft-KUyk,454
10
+ liblaf/cherries/info/__init__.pyi,sha256=beKfSRY1wVsTPBOkWZ7ukmMZo0NKHzp00Q51cFUArbM,274
12
11
  liblaf/cherries/info/_git.py,sha256=oy1xx23sXWA7RqQuLGc3HxcLCF7zHTSpZvZ9pukJGdI,1232
12
+ liblaf/cherries/info/_name.py,sha256=RhB0tqygzBNTS6ZK9unLu7DeuiQaudAvIyeHj0nf2HA,752
13
13
  liblaf/cherries/pathutils/__init__.py,sha256=OHb6Xou2v6u42swTgjRfzej4CIlRg4OmgOIQXUiRjKA,97
14
- liblaf/cherries/pathutils/__init__.pyi,sha256=mr3Dk8ragpNGXmXJriMt21vc7YmqUD6X587exFe9tCI,413
14
+ liblaf/cherries/pathutils/__init__.pyi,sha256=JEotcjG2QNC3LaVM7aoLd7l0Ny6m0QyQKeePefS22LM,413
15
15
  liblaf/cherries/pathutils/_convert.py,sha256=JTO9vETXvj7f4GTtIbOmAoDNEDc_4hoEHZ7ujbyTgS8,859
16
- liblaf/cherries/pathutils/_path.py,sha256=igdLrCqk6aIX36V8c1LClhrFViDFWx4WbiR67BcbVIY,1548
17
- liblaf/cherries/pathutils/_special.py,sha256=b5D3PtW__u0Zpiv69OYoV7TTYc6Dgs4Bu-P8jwrROV4,1415
16
+ liblaf/cherries/pathutils/_path.py,sha256=35WgGghvXq56mFCqT7jYaPo7mO3rnRyRdBh6--woBxE,1548
17
+ liblaf/cherries/pathutils/_special.py,sha256=UZ9dAPj7EAqlRqzQD_b_Z-uCHjv6W_gtMs1Wfr_nDuc,1415
18
18
  liblaf/cherries/plugin/__init__.py,sha256=OHb6Xou2v6u42swTgjRfzej4CIlRg4OmgOIQXUiRjKA,97
19
19
  liblaf/cherries/plugin/__init__.pyi,sha256=2PPdTp-vfgP34sKGnjCR1oMG5ljTmkZkabr_LV74tXA,1299
20
20
  liblaf/cherries/plugin/_abc.py,sha256=H-NH6Gpv3dTJKjaekuAKSn_H0TJPxF-TLa5UU51NNjg,3748
21
- liblaf/cherries/plugin/_dvc.py,sha256=xmMhgZ8QTT-G15_BfpGzYqHjAa7NvspUkuKJvpIinfs,1277
21
+ liblaf/cherries/plugin/_dvc.py,sha256=1cMcKJmO-9FFWjiQ_V-BqmF9XaKmOiwdE9y3aeFoodY,1800
22
22
  liblaf/cherries/plugin/_git.py,sha256=AY6AugwyqtcCAaX475zDINFHgHG1UKupWplquEPbjWU,1396
23
- liblaf/cherries/plugin/_logging.py,sha256=6ZlPQMSv1QmovjOPL6VMmJJOyufU1KCN1W7lOvkGcZs,779
24
- liblaf/cherries/plugin/_mlflow.py,sha256=1AV_jIUgs2EYZU-7_e0EtkgYN3cBPS2Yjrs5AUu5v1Y,1950
25
- liblaf/cherries/plugin/_run.py,sha256=XqMOEFDqba8xOaUIynJwS1Dg6JGVpqtWsHG_XJenypk,3287
23
+ liblaf/cherries/plugin/_logging.py,sha256=EJ-6VgY8Fyn_o2R68diqT7vwnOnuJBPQU7IjwvjKVco,784
24
+ liblaf/cherries/plugin/_mlflow.py,sha256=JS0oGojDyPTUF-Q8ZUJrO36hUXckNFeViAIjJ6lo3ng,2287
25
+ liblaf/cherries/plugin/_run.py,sha256=ldEzxD-PrAiHBwMGjQKiU9eyc0sriwKXPEU6JbId6kE,3287
26
26
  liblaf/cherries/presets/__init__.py,sha256=OHb6Xou2v6u42swTgjRfzej4CIlRg4OmgOIQXUiRjKA,97
27
27
  liblaf/cherries/presets/__init__.pyi,sha256=ka0zjVDb1kWn1VuDGjAzMX5S9sVKKYcxKelp4EwUBf8,53
28
28
  liblaf/cherries/presets/_default.py,sha256=hhe10JzMui8WJhvoLlOfDCHMRlPmdnzRSduFH7rCtP0,742
29
29
  liblaf/cherries/utils/__init__.py,sha256=OHb6Xou2v6u42swTgjRfzej4CIlRg4OmgOIQXUiRjKA,97
30
30
  liblaf/cherries/utils/__init__.pyi,sha256=F5aTcXpWVmUoctPbLfmQXKyuXYRspAIjaIzfL1_3Lrw,51
31
31
  liblaf/cherries/utils/_functools.py,sha256=0Puwvj1Wq4kp3S--hI-CXwUBZ56AtfkqIzFHllQtuug,181
32
- liblaf_cherries-0.0.12.dist-info/METADATA,sha256=EznK6Za_uBu_9awxVrZzzkpR2DVzMZdpIWry4H5x5RY,1944
33
- liblaf_cherries-0.0.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
34
- liblaf_cherries-0.0.12.dist-info/licenses/LICENSE,sha256=Ph4NzyU3lGVDeYv-mf8aRmImH8v9rVL9F362FV4G6Ow,1063
35
- liblaf_cherries-0.0.12.dist-info/RECORD,,
32
+ liblaf_cherries-0.0.14.dist-info/METADATA,sha256=_s8gjrpYQBGHkxYz_D9ibagwI478PgQujoy1AI2vnD0,1944
33
+ liblaf_cherries-0.0.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
34
+ liblaf_cherries-0.0.14.dist-info/licenses/LICENSE,sha256=Ph4NzyU3lGVDeYv-mf8aRmImH8v9rVL9F362FV4G6Ow,1063
35
+ liblaf_cherries-0.0.14.dist-info/RECORD,,