giwon 0.1.1__tar.gz → 0.1.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: giwon
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Observe provenance around one experiment execution.
5
5
  Requires-Dist: tyro>=1.0.16
6
6
  Requires-Dist: pyyaml
@@ -2,7 +2,7 @@
2
2
  # pins development dependencies; running an experiment never installs packages.
3
3
  [project]
4
4
  name = "giwon"
5
- version = "0.1.1"
5
+ version = "0.1.2"
6
6
  description = "Observe provenance around one experiment execution."
7
7
  requires-python = ">=3.11"
8
8
  dependencies = ["tyro>=1.0.16", "PyYAML", "xxhash", "GitPython"]
@@ -1,4 +1,4 @@
1
- """Parse Giwon options and launch the experiment command."""
1
+ """Run experiments, register outputs, and hash artifacts from the command line."""
2
2
 
3
3
  import os
4
4
  import signal
@@ -11,7 +11,7 @@ import tyro
11
11
 
12
12
 
13
13
  @dataclass
14
- class Options:
14
+ class Run:
15
15
  """Launch an experiment."""
16
16
 
17
17
  purpose: str | None = None
@@ -32,39 +32,48 @@ class Options:
32
32
 
33
33
 
34
34
  @dataclass
35
- class Registration:
35
+ class RegisterOutput:
36
36
  """Register output paths and URLs in the selected run."""
37
37
 
38
38
  path: Annotated[list[str], tyro.conf.UseAppendAction] = field(default_factory=list)
39
39
  url: Annotated[list[str], tyro.conf.UseAppendAction] = field(default_factory=list)
40
40
 
41
41
 
42
- def parse(argv: list[str]) -> tuple[Options | Registration, list[str]]:
42
+ @dataclass
43
+ class Hash:
44
+ """Print the full XXH3-128 output hash of a file or directory."""
45
+
46
+ path: Annotated[Path, tyro.conf.Positional]
47
+
48
+
49
+ def parse(argv: list[str]) -> tuple[Run | RegisterOutput | Hash, list[str]]:
43
50
  def usage_error(message: str) -> None:
44
51
  print(f"giwon: {message}", file=sys.stderr)
45
52
  raise SystemExit(2)
46
53
 
47
54
  split = argv.index("--") if "--" in argv else len(argv)
48
55
  options = tyro.cli(
49
- Annotated[Options, tyro.conf.subcommand(name="run")]
50
- | Annotated[Registration, tyro.conf.subcommand(name="register-output")],
56
+ Run | RegisterOutput | Hash,
51
57
  args=argv[:split],
52
58
  prog="giwon",
53
59
  config=(tyro.conf.DisallowNone,),
54
60
  )
55
61
  command = argv[split + 1 :]
56
- if isinstance(options, Registration):
62
+ if isinstance(options, RegisterOutput):
57
63
  if command:
58
64
  usage_error("register-output does not accept a command")
59
65
  if not options.path and not options.url:
60
66
  usage_error("register-output needs at least one path or url")
67
+ elif isinstance(options, Hash):
68
+ if split != len(argv):
69
+ usage_error("hash does not accept --")
61
70
  elif not command:
62
71
  usage_error("expected a command after --")
63
72
 
64
73
  return options, command
65
74
 
66
75
 
67
- def _register(options: Registration) -> None:
76
+ def _register(options: RegisterOutput) -> None:
68
77
  from giwon import register_output
69
78
 
70
79
  try:
@@ -74,7 +83,18 @@ def _register(options: Registration) -> None:
74
83
  raise SystemExit(1) from None
75
84
 
76
85
 
77
- def _run(options: Options, command: list[str]) -> None:
86
+ def _hash(options: Hash) -> None:
87
+ from giwon import hashing
88
+
89
+ try:
90
+ result = hashing.fingerprint(options.path)
91
+ except (OSError, ValueError) as error:
92
+ print(f"giwon: cannot hash {options.path}: {error}", file=sys.stderr)
93
+ raise SystemExit(1) from None
94
+ print(result)
95
+
96
+
97
+ def _run(options: Run, command: list[str]) -> None:
78
98
  """Run the experiment from command-line arguments and reproduce its exit status.
79
99
 
80
100
  A numeric exit code does not tell the parent shell that a process died
@@ -101,7 +121,9 @@ def _run(options: Options, command: list[str]) -> None:
101
121
 
102
122
  def main() -> None:
103
123
  options, command = parse(sys.argv[1:])
104
- if isinstance(options, Registration):
124
+ if isinstance(options, RegisterOutput):
105
125
  _register(options)
126
+ elif isinstance(options, Hash):
127
+ _hash(options)
106
128
  else:
107
129
  _run(options, command)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes