vuer-cli 0.0.3__py3-none-any.whl → 0.0.5__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.
vuer_cli/add.py CHANGED
@@ -1,93 +1,78 @@
1
1
  """Add command - add an environment spec to environment.json then sync."""
2
2
 
3
- from dataclasses import dataclass
3
+ import json
4
4
  from pathlib import Path
5
- from typing import Optional
6
5
 
7
- import json
6
+ from params_proto import proto
8
7
 
9
8
  from .sync import Sync, read_environments_lock
10
- from .utils import print_error, parse_env_spec, normalize_env_spec
11
-
12
-
13
- # Use shared parser from utils; legacy '@' syntax is not supported anymore.
9
+ from .utils import normalize_env_spec, parse_env_spec, print_error
14
10
 
15
11
 
16
- @dataclass
12
+ @proto
17
13
  class Add:
18
- """Add an environment to environment.json and run `vuer sync`.
19
-
20
- Example:
21
- vuer add some-environment/v1.2.3
22
- """
23
-
24
- # NOTE: We keep these fields for params-proto compatibility, but the primary
25
- # way to call this command is positional: `vuer add name@version`.
26
- env: str = "" # Environment spec to add, e.g. "some-environment/v1.2.3"
27
- name: Optional[str] = None # Unused in current workflow
28
- version: str = "latest" # Unused in current workflow
29
-
30
- def __call__(self) -> int:
31
- """Execute add command."""
32
- try:
33
- env_spec = self.env
34
- if not env_spec:
35
- # If env is empty, params-proto likely didn't map the positional arg;
36
- # treat this as a usage error.
37
- raise ValueError(
38
- "Missing environment spec. Usage: vuer add some-environment/v1.2.3"
39
- )
40
-
41
- name, version = parse_env_spec(env_spec)
42
- env_spec_normalized = normalize_env_spec(f"{name}/{version}")
43
-
44
- cwd = Path.cwd()
45
- lock_path = cwd / "environments-lock.yaml"
46
-
47
- # Step 2: Check if already present in environments-lock.yaml
48
- if lock_path.exists():
49
- existing_deps = read_environments_lock(lock_path)
50
- if env_spec_normalized in existing_deps:
51
- print(f"[INFO] Environment {env_spec_normalized} already present in {lock_path}")
52
- return 0
53
-
54
- # Step 3: Ensure environment.json has this dependency, then run sync
55
- env_json_path = cwd / "environment.json"
56
- if env_json_path.exists():
57
- with env_json_path.open("r", encoding="utf-8") as f:
58
- try:
59
- data = json.load(f)
60
- except json.JSONDecodeError as e:
61
- raise ValueError(
62
- f"Invalid environment.json: {e}"
63
- ) from e
64
- else:
65
- data = {}
66
-
67
- deps = data.get("dependencies")
68
- if deps is None:
69
- deps = {}
70
- if not isinstance(deps, dict):
71
- raise ValueError(
72
- "environment.json 'dependencies' field must be an object"
73
- )
74
-
75
- # Add or update the dependency
76
- deps[name] = version
77
- data["dependencies"] = deps
78
-
79
- with env_json_path.open("w", encoding="utf-8") as f:
80
- json.dump(data, f, indent=2, ensure_ascii=False)
81
- f.write("\n")
82
-
83
- print(
84
- f"[INFO] Added {env_spec_normalized} to environment.json dependencies. Running sync..."
85
- )
86
- return Sync()()
87
-
88
- except (FileNotFoundError, ValueError, RuntimeError) as e:
89
- print_error(str(e))
90
- return 1
91
- except Exception as e:
92
- print_error(f"Unexpected error: {e}")
93
- return 1
14
+ """Add an environment to environment.json and run `vuer sync`.
15
+
16
+ Example:
17
+ vuer add some-environment/v1.2.3
18
+ """
19
+
20
+ # Required positional arg: environment spec, e.g. "some-environment/v1.2.3"
21
+ env: str
22
+
23
+ def __call__(self) -> int:
24
+ """Execute add command."""
25
+ try:
26
+ env_spec = self.env
27
+
28
+ name, version = parse_env_spec(env_spec)
29
+ env_spec_normalized = normalize_env_spec(f"{name}/{version}")
30
+
31
+ cwd = Path.cwd()
32
+ lock_path = cwd / "environments-lock.yaml"
33
+
34
+ # Step 2: Check if already present in environments-lock.yaml
35
+ if lock_path.exists():
36
+ existing_deps = read_environments_lock(lock_path)
37
+ if env_spec_normalized in existing_deps:
38
+ print(
39
+ f"[INFO] Environment {env_spec_normalized} already present in {lock_path}"
40
+ )
41
+ return 0
42
+
43
+ # Step 3: Ensure environment.json has this dependency, then run sync
44
+ env_json_path = cwd / "environment.json"
45
+ if env_json_path.exists():
46
+ with env_json_path.open("r", encoding="utf-8") as f:
47
+ try:
48
+ data = json.load(f)
49
+ except json.JSONDecodeError as e:
50
+ raise ValueError(f"Invalid environment.json: {e}") from e
51
+ else:
52
+ data = {}
53
+
54
+ deps = data.get("dependencies")
55
+ if deps is None:
56
+ deps = {}
57
+ if not isinstance(deps, dict):
58
+ raise ValueError("environment.json 'dependencies' field must be an object")
59
+
60
+ # Add or update the dependency
61
+ deps[name] = version
62
+ data["dependencies"] = deps
63
+
64
+ with env_json_path.open("w", encoding="utf-8") as f:
65
+ json.dump(data, f, indent=2, ensure_ascii=False)
66
+ f.write("\n")
67
+
68
+ print(
69
+ f"[INFO] Added {env_spec_normalized} to environment.json dependencies. Running sync..."
70
+ )
71
+ return Sync().run()
72
+
73
+ except (FileNotFoundError, ValueError, RuntimeError) as e:
74
+ print_error(str(e))
75
+ return 1
76
+ except Exception as e:
77
+ print_error(f"Unexpected error: {e}")
78
+ return 1