vuer-cli 0.0.4__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
@@ -6,75 +6,73 @@ from pathlib import Path
6
6
  from params_proto import proto
7
7
 
8
8
  from .sync import Sync, read_environments_lock
9
- from .utils import print_error, parse_env_spec, normalize_env_spec
9
+ from .utils import normalize_env_spec, parse_env_spec, print_error
10
10
 
11
11
 
12
12
  @proto
13
13
  class Add:
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 run(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(f"[INFO] Environment {env_spec_normalized} already present in {lock_path}")
39
- return 0
40
-
41
- # Step 3: Ensure environment.json has this dependency, then run sync
42
- env_json_path = cwd / "environment.json"
43
- if env_json_path.exists():
44
- with env_json_path.open("r", encoding="utf-8") as f:
45
- try:
46
- data = json.load(f)
47
- except json.JSONDecodeError as e:
48
- raise ValueError(
49
- f"Invalid environment.json: {e}"
50
- ) 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(
59
- "environment.json 'dependencies' field must be an object"
60
- )
61
-
62
- # Add or update the dependency
63
- deps[name] = version
64
- data["dependencies"] = deps
65
-
66
- with env_json_path.open("w", encoding="utf-8") as f:
67
- json.dump(data, f, indent=2, ensure_ascii=False)
68
- f.write("\n")
69
-
70
- print(
71
- f"[INFO] Added {env_spec_normalized} to environment.json dependencies. Running sync..."
72
- )
73
- return Sync().run()
74
-
75
- except (FileNotFoundError, ValueError, RuntimeError) as e:
76
- print_error(str(e))
77
- return 1
78
- except Exception as e:
79
- print_error(f"Unexpected error: {e}")
80
- 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