uv-stack 0.1.2__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.
- uv_stack/__init__.py +3 -0
- uv_stack/cli/__init__.py +114 -0
- uv_stack/cli/_render.py +42 -0
- uv_stack/cli/config_cmd.py +27 -0
- uv_stack/cli/create.py +50 -0
- uv_stack/cli/doctor.py +24 -0
- uv_stack/cli/list_cmd.py +23 -0
- uv_stack/cli/resolve.py +33 -0
- uv_stack/cli/show.py +68 -0
- uv_stack/cli/upgrade.py +125 -0
- uv_stack/commands.py +78 -0
- uv_stack/config.py +151 -0
- uv_stack/errors.py +52 -0
- uv_stack/fsutil.py +35 -0
- uv_stack/models.py +72 -0
- uv_stack/operations/__init__.py +0 -0
- uv_stack/operations/create.py +61 -0
- uv_stack/operations/doctor.py +112 -0
- uv_stack/operations/init.py +26 -0
- uv_stack/operations/project.py +82 -0
- uv_stack/operations/upgrade.py +158 -0
- uv_stack/parse.py +43 -0
- uv_stack/render.py +105 -0
- uv_stack/resolver.py +173 -0
- uv_stack/runner.py +100 -0
- uv_stack-0.1.2.dist-info/METADATA +16 -0
- uv_stack-0.1.2.dist-info/RECORD +29 -0
- uv_stack-0.1.2.dist-info/WHEEL +4 -0
- uv_stack-0.1.2.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""The ``upgrade`` operation: render → compile → install → check.
|
|
2
|
+
|
|
3
|
+
Filesystem writes (``requirements.in``, ``environment.yml``, the lock) are
|
|
4
|
+
guarded explicitly; ``--dry-run`` renders the two safe generated files, builds
|
|
5
|
+
the command plan, and returns without touching the env or the lock.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import tempfile
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from uv_stack.commands import (
|
|
16
|
+
micromamba_create,
|
|
17
|
+
micromamba_python_path,
|
|
18
|
+
micromamba_remove,
|
|
19
|
+
uv_pip_check,
|
|
20
|
+
uv_pip_compile,
|
|
21
|
+
uv_pip_install,
|
|
22
|
+
)
|
|
23
|
+
from uv_stack.config import ConfigRoot
|
|
24
|
+
from uv_stack.errors import EnvError
|
|
25
|
+
from uv_stack.fsutil import atomic_write
|
|
26
|
+
from uv_stack.operations.create import ensure_env
|
|
27
|
+
from uv_stack.render import render_environment_yml, render_requirements_in
|
|
28
|
+
from uv_stack.resolver import Resolver
|
|
29
|
+
from uv_stack.runner import Command, Runner
|
|
30
|
+
|
|
31
|
+
_DRY_RUN_PYTHON = "<env-python>"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class UpgradeOptions:
|
|
36
|
+
"""Options controlling an environment upgrade.
|
|
37
|
+
|
|
38
|
+
:param create: Create the micromamba env if missing.
|
|
39
|
+
:param recreate: Remove and recreate the env first.
|
|
40
|
+
:param dry_run: Render generated files and return the plan without executing.
|
|
41
|
+
:param upgrade_packages: Upgrade only these packages (disables full upgrade).
|
|
42
|
+
:param no_upgrade: Recompile without forcing any upgrade.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
create: bool = False
|
|
46
|
+
recreate: bool = False
|
|
47
|
+
dry_run: bool = False
|
|
48
|
+
upgrade_packages: list[str] = field(default_factory=list)
|
|
49
|
+
no_upgrade: bool = False
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class UpgradeResult:
|
|
54
|
+
"""Outcome of :func:`upgrade_env`.
|
|
55
|
+
|
|
56
|
+
:param env_name: The environment that was upgraded.
|
|
57
|
+
:param planned: The commands that would run (populated for dry runs).
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
env_name: str
|
|
61
|
+
planned: list[Command] = field(default_factory=list)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _should_upgrade_all(options: UpgradeOptions) -> bool:
|
|
65
|
+
return not options.no_upgrade and not options.upgrade_packages
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def upgrade_env(
|
|
69
|
+
config: ConfigRoot,
|
|
70
|
+
runner: Runner,
|
|
71
|
+
env_name: str,
|
|
72
|
+
options: UpgradeOptions,
|
|
73
|
+
) -> UpgradeResult:
|
|
74
|
+
"""Render config, then compile, install, and check an environment.
|
|
75
|
+
|
|
76
|
+
:param config: Configuration root.
|
|
77
|
+
:param runner: Command runner.
|
|
78
|
+
:param env_name: Environment name.
|
|
79
|
+
:param options: Upgrade options.
|
|
80
|
+
:returns: An :class:`UpgradeResult`.
|
|
81
|
+
:raises ConfigError: If the environment config is missing or invalid.
|
|
82
|
+
:raises EnvError: If the env is missing and creation was not requested.
|
|
83
|
+
:raises ToolError: If a uv/micromamba command fails.
|
|
84
|
+
"""
|
|
85
|
+
env = config.load_env(env_name)
|
|
86
|
+
stack = Resolver(config).resolve(env.stack)
|
|
87
|
+
|
|
88
|
+
atomic_write(
|
|
89
|
+
config.env_requirements_in(env_name),
|
|
90
|
+
render_requirements_in(stack, config, env_name),
|
|
91
|
+
)
|
|
92
|
+
atomic_write(
|
|
93
|
+
config.env_environment_yml(env_name),
|
|
94
|
+
render_environment_yml(env),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
upgrade_all = _should_upgrade_all(options)
|
|
98
|
+
requirements_in = config.env_requirements_in(env_name)
|
|
99
|
+
lock = config.env_lock(env_name)
|
|
100
|
+
|
|
101
|
+
if options.dry_run:
|
|
102
|
+
planned: list[Command] = []
|
|
103
|
+
if options.recreate:
|
|
104
|
+
planned.append(micromamba_remove(env_name))
|
|
105
|
+
planned.append(micromamba_create(config.env_environment_yml(env_name)))
|
|
106
|
+
elif options.create:
|
|
107
|
+
planned.append(micromamba_create(config.env_environment_yml(env_name)))
|
|
108
|
+
planned.append(
|
|
109
|
+
uv_pip_compile(
|
|
110
|
+
_DRY_RUN_PYTHON,
|
|
111
|
+
requirements_in,
|
|
112
|
+
lock,
|
|
113
|
+
upgrade=upgrade_all,
|
|
114
|
+
upgrade_packages=options.upgrade_packages,
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
planned.append(uv_pip_install(_DRY_RUN_PYTHON, lock))
|
|
118
|
+
planned.append(uv_pip_check(_DRY_RUN_PYTHON))
|
|
119
|
+
return UpgradeResult(env_name=env_name, planned=planned)
|
|
120
|
+
|
|
121
|
+
ensure_env(
|
|
122
|
+
config, runner, env_name, create=options.create, recreate=options.recreate
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
python = runner.run(micromamba_python_path(env_name), capture=True).stdout.strip()
|
|
126
|
+
if not python:
|
|
127
|
+
raise EnvError(
|
|
128
|
+
f"Could not determine the Python interpreter for env '{env_name}'.",
|
|
129
|
+
hint="Verify the micromamba environment was created successfully.",
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
# Compile to a temp lock, then atomically replace, so a failed compile never
|
|
133
|
+
# corrupts an existing lockfile.
|
|
134
|
+
tmp_fd, tmp_name = tempfile.mkstemp(
|
|
135
|
+
dir=lock.parent, prefix=lock.name + ".", suffix=".tmp"
|
|
136
|
+
)
|
|
137
|
+
os.close(tmp_fd)
|
|
138
|
+
tmp_lock = Path(tmp_name)
|
|
139
|
+
try:
|
|
140
|
+
runner.run(
|
|
141
|
+
uv_pip_compile(
|
|
142
|
+
python,
|
|
143
|
+
requirements_in,
|
|
144
|
+
tmp_lock,
|
|
145
|
+
upgrade=upgrade_all,
|
|
146
|
+
upgrade_packages=options.upgrade_packages,
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
tmp_lock.replace(lock)
|
|
150
|
+
except BaseException:
|
|
151
|
+
if tmp_lock.exists():
|
|
152
|
+
tmp_lock.unlink()
|
|
153
|
+
raise
|
|
154
|
+
|
|
155
|
+
runner.run(uv_pip_install(python, lock))
|
|
156
|
+
runner.run(uv_pip_check(python))
|
|
157
|
+
|
|
158
|
+
return UpgradeResult(env_name=env_name)
|
uv_stack/parse.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Shared parsing helpers for ``.in`` / ``.bundle`` / ``.txt`` config files.
|
|
2
|
+
|
|
3
|
+
Config files use a simple line-oriented grammar: ``#`` starts a comment,
|
|
4
|
+
surrounding whitespace is insignificant, and blank lines are ignored.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def clean_line(line: str) -> str:
|
|
13
|
+
"""Strip a trailing ``#`` comment and surrounding whitespace.
|
|
14
|
+
|
|
15
|
+
:param line: A raw line from a config file.
|
|
16
|
+
:returns: The cleaned content, or an empty string if the line is blank or
|
|
17
|
+
a pure comment.
|
|
18
|
+
"""
|
|
19
|
+
text, _, _ = line.partition("#")
|
|
20
|
+
return text.strip()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def read_clean_lines(path: Path) -> list[str]:
|
|
24
|
+
"""Read a file and return its non-empty, comment-stripped lines.
|
|
25
|
+
|
|
26
|
+
:param path: File to read.
|
|
27
|
+
:returns: Cleaned lines in order; an empty list if the file does not exist.
|
|
28
|
+
"""
|
|
29
|
+
if not path.is_file():
|
|
30
|
+
return []
|
|
31
|
+
cleaned = (clean_line(raw) for raw in path.read_text().splitlines())
|
|
32
|
+
return [line for line in cleaned if line]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def first_clean_line(path: Path, default: str = "") -> str:
|
|
36
|
+
"""Return the first non-empty cleaned line of a file.
|
|
37
|
+
|
|
38
|
+
:param path: File to read.
|
|
39
|
+
:param default: Value returned when the file is missing or has no content.
|
|
40
|
+
:returns: The first cleaned line, or ``default``.
|
|
41
|
+
"""
|
|
42
|
+
lines = read_clean_lines(path)
|
|
43
|
+
return lines[0] if lines else default
|
uv_stack/render.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Pure renderers that turn resolved config into generated file text.
|
|
2
|
+
|
|
3
|
+
These functions never write to disk; they return strings. Filesystem writes are
|
|
4
|
+
the operations layer's responsibility.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from uv_stack.config import ConfigRoot
|
|
10
|
+
from uv_stack.models import EnvConfig, ResolvedStack
|
|
11
|
+
|
|
12
|
+
_HEADER = "# Generated by uv-stack — do not edit."
|
|
13
|
+
_EDIT_HINT = (
|
|
14
|
+
"# Edit stack.txt, requirements.local.in, profiles/*.in, or bundles/*.bundle instead."
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def render_requirements_in(stack: ResolvedStack, config: ConfigRoot, env_name: str) -> str:
|
|
19
|
+
"""Render the layered ``requirements.in`` for a named environment.
|
|
20
|
+
|
|
21
|
+
Profiles are referenced with ``-r`` so edits to a profile propagate without
|
|
22
|
+
re-rendering. The environment's ``requirements.local.in`` is referenced only
|
|
23
|
+
if it exists.
|
|
24
|
+
|
|
25
|
+
:param stack: The resolved stack.
|
|
26
|
+
:param config: The configuration root (for absolute profile/local paths).
|
|
27
|
+
:param env_name: Name of the environment being rendered.
|
|
28
|
+
:returns: File text ending with a trailing newline.
|
|
29
|
+
"""
|
|
30
|
+
lines: list[str] = [_HEADER, _EDIT_HINT, ""]
|
|
31
|
+
|
|
32
|
+
if stack.profiles:
|
|
33
|
+
lines.append("# Profile requirements")
|
|
34
|
+
lines += [f"-r {config.profile_path(name)}" for name in stack.profiles]
|
|
35
|
+
lines.append("")
|
|
36
|
+
|
|
37
|
+
if stack.inline:
|
|
38
|
+
lines.append("# Inline requirements from bundles/stack")
|
|
39
|
+
lines += list(stack.inline)
|
|
40
|
+
lines.append("")
|
|
41
|
+
|
|
42
|
+
local = config.env_local_path(env_name)
|
|
43
|
+
if local.is_file():
|
|
44
|
+
lines.append("# Environment-local additions")
|
|
45
|
+
lines.append(f"-r {local}")
|
|
46
|
+
lines.append("")
|
|
47
|
+
|
|
48
|
+
return "\n".join(lines).rstrip("\n") + "\n"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def render_requirements_flat(stack: ResolvedStack, config: ConfigRoot) -> str:
|
|
52
|
+
"""Render a flattened requirements list for ``project init``.
|
|
53
|
+
|
|
54
|
+
Each profile's lines are expanded inline so the result is self-contained and
|
|
55
|
+
does not reference files under the config root.
|
|
56
|
+
|
|
57
|
+
:param stack: The resolved stack.
|
|
58
|
+
:param config: The configuration root (for loading profile contents).
|
|
59
|
+
:returns: File text ending with a trailing newline.
|
|
60
|
+
"""
|
|
61
|
+
lines: list[str] = [_HEADER, ""]
|
|
62
|
+
|
|
63
|
+
for name in stack.profiles:
|
|
64
|
+
profile = config.load_profile(name)
|
|
65
|
+
lines.append(f"# Profile: {name}")
|
|
66
|
+
lines += list(profile.requirements)
|
|
67
|
+
lines.append("")
|
|
68
|
+
|
|
69
|
+
if stack.inline:
|
|
70
|
+
lines.append("# Inline requirements from bundles/stack")
|
|
71
|
+
lines += list(stack.inline)
|
|
72
|
+
lines.append("")
|
|
73
|
+
|
|
74
|
+
return "\n".join(lines).rstrip("\n") + "\n"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def render_environment_yml(env: EnvConfig) -> str:
|
|
78
|
+
"""Render a micromamba ``environment.yml`` for a named environment.
|
|
79
|
+
|
|
80
|
+
``conda-forge`` is always the top-priority channel; any channels from the
|
|
81
|
+
env's ``channels.txt`` are appended after it (de-duplicated, so listing
|
|
82
|
+
``conda-forge`` there does not produce a duplicate). Channel order is
|
|
83
|
+
priority order in conda/mamba, so the first listed wins.
|
|
84
|
+
|
|
85
|
+
:param env: The environment config (name, python, channels, packages).
|
|
86
|
+
:returns: File text ending with a trailing newline.
|
|
87
|
+
"""
|
|
88
|
+
channels = ["conda-forge"]
|
|
89
|
+
for channel in env.channels:
|
|
90
|
+
if channel not in channels:
|
|
91
|
+
channels.append(channel)
|
|
92
|
+
|
|
93
|
+
lines = [
|
|
94
|
+
_HEADER,
|
|
95
|
+
f"name: {env.name}",
|
|
96
|
+
"channels:",
|
|
97
|
+
]
|
|
98
|
+
lines += [f" - {channel}" for channel in channels]
|
|
99
|
+
lines += [
|
|
100
|
+
"dependencies:",
|
|
101
|
+
f" - python={env.python}",
|
|
102
|
+
" - pip",
|
|
103
|
+
]
|
|
104
|
+
lines += [f" - {pkg}" for pkg in env.micromamba]
|
|
105
|
+
return "\n".join(lines) + "\n"
|
uv_stack/resolver.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Resolve stack tokens into an ordered, de-duplicated :class:`ResolvedStack`.
|
|
2
|
+
|
|
3
|
+
The grammar mirrors the original zsh tooling:
|
|
4
|
+
|
|
5
|
+
``@x`` / ``bundle:x``
|
|
6
|
+
Resolve bundle ``x`` (recursively resolving each of its lines).
|
|
7
|
+
``profile:x``
|
|
8
|
+
Add profile ``x`` (must exist).
|
|
9
|
+
``package:x`` / ``pkg:x``
|
|
10
|
+
Add ``x`` as a literal inline requirement.
|
|
11
|
+
unqualified ``x``
|
|
12
|
+
Profile if ``profiles/x.in`` exists, else bundle if ``bundles/x.bundle``
|
|
13
|
+
exists, else a literal inline requirement.
|
|
14
|
+
``-e <path>`` / archive paths / anything else
|
|
15
|
+
Literal inline requirement.
|
|
16
|
+
|
|
17
|
+
Profiles are recorded by name (rendered later as ``-r profiles/<name>.in``).
|
|
18
|
+
First occurrence wins for ordering; bundles already on the resolution path are
|
|
19
|
+
skipped, so mutually-referential bundles cannot recurse forever.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from collections.abc import Iterable
|
|
25
|
+
|
|
26
|
+
from uv_stack.config import ConfigRoot
|
|
27
|
+
from uv_stack.errors import ResolutionError
|
|
28
|
+
from uv_stack.models import ResolvedStack
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Resolver:
|
|
32
|
+
"""Turns stack tokens into a :class:`ResolvedStack`.
|
|
33
|
+
|
|
34
|
+
:param config: The configuration root used to look up profiles and bundles.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, config: ConfigRoot) -> None:
|
|
38
|
+
self._config = config
|
|
39
|
+
|
|
40
|
+
def resolve(self, tokens: Iterable[str]) -> ResolvedStack:
|
|
41
|
+
"""Resolve ``tokens`` into profiles and inline requirements.
|
|
42
|
+
|
|
43
|
+
:param tokens: Stack tokens (from a ``stack.txt``, a bundle, or the CLI).
|
|
44
|
+
:returns: The resolved, de-duplicated stack.
|
|
45
|
+
:raises ResolutionError: For an explicitly-qualified profile or bundle
|
|
46
|
+
that does not exist.
|
|
47
|
+
"""
|
|
48
|
+
self._profiles: list[str] = []
|
|
49
|
+
self._inline: list[str] = []
|
|
50
|
+
self._seen_profiles: set[str] = set()
|
|
51
|
+
self._seen_inline: set[str] = set()
|
|
52
|
+
self._seen_bundles: set[str] = set()
|
|
53
|
+
for token in tokens:
|
|
54
|
+
self._resolve_token(token)
|
|
55
|
+
return ResolvedStack(profiles=self._profiles, inline=self._inline)
|
|
56
|
+
|
|
57
|
+
def classify(self, tokens: Iterable[str]) -> list[str]:
|
|
58
|
+
"""Classify each token without expanding bundles or profiles.
|
|
59
|
+
|
|
60
|
+
Each token is labeled by what it *is* — ``bundle:<name>``,
|
|
61
|
+
``profile:<name>``, or ``package:<spec>`` — using the same precedence as
|
|
62
|
+
:meth:`resolve` but with no recursion. The result is de-duplicated with
|
|
63
|
+
first occurrence winning.
|
|
64
|
+
|
|
65
|
+
:param tokens: Stack tokens to classify.
|
|
66
|
+
:returns: Full specifiers (e.g. ``["bundle:standard", "package:numpy"]``).
|
|
67
|
+
"""
|
|
68
|
+
classified: list[str] = []
|
|
69
|
+
seen: set[str] = set()
|
|
70
|
+
for token in tokens:
|
|
71
|
+
spec = self._classify_token(token)
|
|
72
|
+
if spec is not None and spec not in seen:
|
|
73
|
+
seen.add(spec)
|
|
74
|
+
classified.append(spec)
|
|
75
|
+
return classified
|
|
76
|
+
|
|
77
|
+
def resolve_packages(self, tokens: Iterable[str]) -> list[str]:
|
|
78
|
+
"""Fully resolve ``tokens`` to a flat, de-duplicated package list.
|
|
79
|
+
|
|
80
|
+
Bundles and profiles are expanded to the packages they contain, so the
|
|
81
|
+
result is a raw requirements list with no ``-r`` references or kind
|
|
82
|
+
prefixes (compatible with a ``requirements.txt``). Profile packages come
|
|
83
|
+
first in resolution order, followed by inline requirements.
|
|
84
|
+
|
|
85
|
+
:param tokens: Stack tokens to resolve.
|
|
86
|
+
:returns: Package specifiers in order, de-duplicated.
|
|
87
|
+
:raises ResolutionError: For an explicitly-qualified profile or bundle
|
|
88
|
+
that does not exist.
|
|
89
|
+
"""
|
|
90
|
+
stack = self.resolve(tokens)
|
|
91
|
+
packages: list[str] = []
|
|
92
|
+
seen: set[str] = set()
|
|
93
|
+
for name in stack.profiles:
|
|
94
|
+
for req in self._config.load_profile(name).requirements:
|
|
95
|
+
if req not in seen:
|
|
96
|
+
seen.add(req)
|
|
97
|
+
packages.append(req)
|
|
98
|
+
for req in stack.inline:
|
|
99
|
+
if req not in seen:
|
|
100
|
+
seen.add(req)
|
|
101
|
+
packages.append(req)
|
|
102
|
+
return packages
|
|
103
|
+
|
|
104
|
+
def _classify_token(self, token: str) -> str | None:
|
|
105
|
+
token = token.strip()
|
|
106
|
+
if not token:
|
|
107
|
+
return None
|
|
108
|
+
if token.startswith("@"):
|
|
109
|
+
return f"bundle:{token[1:]}"
|
|
110
|
+
if token.startswith("bundle:"):
|
|
111
|
+
return token
|
|
112
|
+
if token.startswith("profile:"):
|
|
113
|
+
return token
|
|
114
|
+
if token.startswith("package:"):
|
|
115
|
+
return token
|
|
116
|
+
if token.startswith("pkg:"):
|
|
117
|
+
return f"package:{token[len('pkg:') :]}"
|
|
118
|
+
if self._config.profile_exists(token):
|
|
119
|
+
return f"profile:{token}"
|
|
120
|
+
if self._config.bundle_exists(token):
|
|
121
|
+
return f"bundle:{token}"
|
|
122
|
+
return f"package:{token}"
|
|
123
|
+
|
|
124
|
+
def _resolve_token(self, token: str) -> None:
|
|
125
|
+
token = token.strip()
|
|
126
|
+
if not token:
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
if token.startswith("@"):
|
|
130
|
+
self._resolve_bundle(token[1:], explicit=True)
|
|
131
|
+
elif token.startswith("bundle:"):
|
|
132
|
+
self._resolve_bundle(token[len("bundle:") :], explicit=True)
|
|
133
|
+
elif token.startswith("profile:"):
|
|
134
|
+
self._add_profile(token[len("profile:") :], explicit=True)
|
|
135
|
+
elif token.startswith("package:"):
|
|
136
|
+
self._add_inline(token[len("package:") :])
|
|
137
|
+
elif token.startswith("pkg:"):
|
|
138
|
+
self._add_inline(token[len("pkg:") :])
|
|
139
|
+
elif self._config.profile_exists(token):
|
|
140
|
+
self._add_profile(token, explicit=False)
|
|
141
|
+
elif self._config.bundle_exists(token):
|
|
142
|
+
self._resolve_bundle(token, explicit=False)
|
|
143
|
+
else:
|
|
144
|
+
self._add_inline(token)
|
|
145
|
+
|
|
146
|
+
def _add_profile(self, name: str, *, explicit: bool) -> None:
|
|
147
|
+
if explicit and not self._config.profile_exists(name):
|
|
148
|
+
raise ResolutionError(
|
|
149
|
+
f"Missing profile: {self._config.profile_path(name)}",
|
|
150
|
+
hint="Check the profile name or create the .in file.",
|
|
151
|
+
)
|
|
152
|
+
if name not in self._seen_profiles:
|
|
153
|
+
self._seen_profiles.add(name)
|
|
154
|
+
self._profiles.append(name)
|
|
155
|
+
|
|
156
|
+
def _add_inline(self, requirement: str) -> None:
|
|
157
|
+
requirement = requirement.strip()
|
|
158
|
+
if requirement and requirement not in self._seen_inline:
|
|
159
|
+
self._seen_inline.add(requirement)
|
|
160
|
+
self._inline.append(requirement)
|
|
161
|
+
|
|
162
|
+
def _resolve_bundle(self, name: str, *, explicit: bool) -> None:
|
|
163
|
+
if explicit and not self._config.bundle_exists(name):
|
|
164
|
+
raise ResolutionError(
|
|
165
|
+
f"Missing bundle: {self._config.bundle_path(name)}",
|
|
166
|
+
hint="Check the bundle name or create the .bundle file.",
|
|
167
|
+
)
|
|
168
|
+
if name in self._seen_bundles:
|
|
169
|
+
return
|
|
170
|
+
self._seen_bundles.add(name)
|
|
171
|
+
bundle = self._config.load_bundle(name)
|
|
172
|
+
for token in bundle.tokens:
|
|
173
|
+
self._resolve_token(token)
|
uv_stack/runner.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""The command-execution seam.
|
|
2
|
+
|
|
3
|
+
Operations build :class:`Command` objects and hand them to a :class:`Runner`.
|
|
4
|
+
``SubprocessRunner`` actually executes (streaming output by default, or
|
|
5
|
+
capturing it); ``RecordingRunner`` records commands for tests and dry-runs. This
|
|
6
|
+
is the single mock point for the otherwise side-effect-free core.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import subprocess
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Protocol
|
|
16
|
+
|
|
17
|
+
from uv_stack.errors import ToolError
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class Command:
|
|
22
|
+
"""A single external command to run.
|
|
23
|
+
|
|
24
|
+
:param args: The argv list.
|
|
25
|
+
:param cwd: Optional working directory.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
args: list[str]
|
|
29
|
+
cwd: Path | None = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class CommandResult:
|
|
34
|
+
"""The outcome of running a :class:`Command`.
|
|
35
|
+
|
|
36
|
+
:param returncode: Process exit code.
|
|
37
|
+
:param stdout: Captured standard output (empty unless ``capture=True``).
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
returncode: int
|
|
41
|
+
stdout: str = ""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Runner(Protocol):
|
|
45
|
+
"""Protocol implemented by command runners."""
|
|
46
|
+
|
|
47
|
+
def run(
|
|
48
|
+
self, command: Command, *, capture: bool = False, check: bool = True
|
|
49
|
+
) -> CommandResult:
|
|
50
|
+
"""Execute ``command``.
|
|
51
|
+
|
|
52
|
+
:param command: The command to run.
|
|
53
|
+
:param capture: Capture and return stdout instead of streaming it.
|
|
54
|
+
:param check: Raise :class:`ToolError` on a non-zero exit.
|
|
55
|
+
"""
|
|
56
|
+
...
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class SubprocessRunner:
|
|
60
|
+
"""Runs commands with :mod:`subprocess`."""
|
|
61
|
+
|
|
62
|
+
def run(
|
|
63
|
+
self, command: Command, *, capture: bool = False, check: bool = True
|
|
64
|
+
) -> CommandResult:
|
|
65
|
+
completed = subprocess.run(
|
|
66
|
+
command.args,
|
|
67
|
+
cwd=command.cwd,
|
|
68
|
+
capture_output=capture,
|
|
69
|
+
text=True,
|
|
70
|
+
)
|
|
71
|
+
if check and completed.returncode != 0:
|
|
72
|
+
raise ToolError(
|
|
73
|
+
f"Command failed ({completed.returncode}): {' '.join(command.args)}",
|
|
74
|
+
command=command.args,
|
|
75
|
+
returncode=completed.returncode,
|
|
76
|
+
)
|
|
77
|
+
return CommandResult(
|
|
78
|
+
returncode=completed.returncode,
|
|
79
|
+
stdout=completed.stdout or "" if capture else "",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass
|
|
84
|
+
class RecordingRunner:
|
|
85
|
+
"""Records commands without executing them.
|
|
86
|
+
|
|
87
|
+
:param responder: Optional callable returning a :class:`CommandResult` for a
|
|
88
|
+
given command; defaults to a successful empty result.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
responder: Callable[[Command], CommandResult] | None = None
|
|
92
|
+
commands: list[Command] = field(default_factory=list)
|
|
93
|
+
|
|
94
|
+
def run(
|
|
95
|
+
self, command: Command, *, capture: bool = False, check: bool = True
|
|
96
|
+
) -> CommandResult:
|
|
97
|
+
self.commands.append(command)
|
|
98
|
+
if self.responder is not None:
|
|
99
|
+
return self.responder(command)
|
|
100
|
+
return CommandResult(returncode=0, stdout="")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uv-stack
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Formalized uv + micromamba Python environment management
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: pydantic>=2
|
|
7
|
+
Requires-Dist: rich-click>=1.7
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# uv-stack
|
|
11
|
+
|
|
12
|
+
A command-line interface and library that formalizes a `uv` + `micromamba`
|
|
13
|
+
Python environment workflow built around profiles, bundles, stacks, and named
|
|
14
|
+
environments.
|
|
15
|
+
|
|
16
|
+
See `docs/superpowers/specs/2026-05-28-uvstack-design.md` for the design.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
uv_stack/__init__.py,sha256=NeV-KhtjfQ_Q7d9dUS-R6eHWHLCwT35LlHfFztIVYqE,90
|
|
2
|
+
uv_stack/commands.py,sha256=ieaFv-G54l2wtues7dkjAKCXYgMUDlKI9uMEu3pgaGg,2509
|
|
3
|
+
uv_stack/config.py,sha256=RLli07V3KUGxSKfdT8SbcFpnrlOs-93K8qBW3Kfhq_o,5312
|
|
4
|
+
uv_stack/errors.py,sha256=5ylgquAIpj93GzPayfJSOeOVnqTMMjVGRnGXNQ3B7Yo,1517
|
|
5
|
+
uv_stack/fsutil.py,sha256=tSNU3db9rDXcDiMlykoSQf3QnDQttRL1u2toje00how,1182
|
|
6
|
+
uv_stack/models.py,sha256=2iQhfqRHZYbHldf-20pocwWtUOYf2cnTfysxXNWNiGU,2144
|
|
7
|
+
uv_stack/parse.py,sha256=UdGz8U7Rg5Kg6x0Ik966CEavVqqHjfUJXMIdoZkqu7A,1381
|
|
8
|
+
uv_stack/render.py,sha256=9RKfiRXEwFS2PWgmeJqS3p4WEX_fqucWHLRHDuIvTzQ,3585
|
|
9
|
+
uv_stack/resolver.py,sha256=mnBJJcuwNn-P252RG7hJ9ZQGdJ3NUUpOD0ta6xzdl2w,6802
|
|
10
|
+
uv_stack/runner.py,sha256=Gom4RH8kiRQl0phmAhzX36LzgcHhuOTa69JK6gh_zek,2858
|
|
11
|
+
uv_stack/cli/__init__.py,sha256=dckhq31vcuyRvkkbMOZShfMjchY9TQHplYOR5JOtsIA,3701
|
|
12
|
+
uv_stack/cli/_render.py,sha256=1l0oNIXKvCjfNS9SM1ls2uKX5FD-pkU3De_lkC5qW0Q,1378
|
|
13
|
+
uv_stack/cli/config_cmd.py,sha256=zSLs6O3dfHgLTU5dPsEJbsN0xTrFvcxjqTcToCebj_c,755
|
|
14
|
+
uv_stack/cli/create.py,sha256=gxoEgzotqJ01QZQbg1E35uzLYiiaFWYWNgIUNdbmoW8,1848
|
|
15
|
+
uv_stack/cli/doctor.py,sha256=UvGmaOiQUT63R2TTRIqhA8K9jsuuMKwBU6K0-1t9EEY,832
|
|
16
|
+
uv_stack/cli/list_cmd.py,sha256=ZxzA9ty4qnHCi4MzTeALvo4r_qJ9UJUYTQoZldecTcU,743
|
|
17
|
+
uv_stack/cli/resolve.py,sha256=5QUPfY9ip4BaaSj7189esB49Zl9VOmiTTWxahlqDh8c,1000
|
|
18
|
+
uv_stack/cli/show.py,sha256=tV96Y7Hr29d4z1k9Apha8XcJDgMlc7Axpq4cTkAk1x4,2082
|
|
19
|
+
uv_stack/cli/upgrade.py,sha256=mNFKKXDjUO0BEqMfdE3XrtQUdgmAo92Rh4XyPkZNf6Y,4101
|
|
20
|
+
uv_stack/operations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
uv_stack/operations/create.py,sha256=3Rd6rDfoDQLWojWoyVdbthYNHvtMS6ecruRtcN3xzWU,2065
|
|
22
|
+
uv_stack/operations/doctor.py,sha256=45xkTqbCxI_5-ySVsi-7MvfyJbRQig_7tB8dh47P6LE,3625
|
|
23
|
+
uv_stack/operations/init.py,sha256=FX5mf0QAMnk2NEmBWa0wRC5ULYl-gUZZ9o07AREIiqA,885
|
|
24
|
+
uv_stack/operations/project.py,sha256=6sA6A1axYC-PDubNIALjy9yFnjF3whHJHFVnYRLmpyg,2568
|
|
25
|
+
uv_stack/operations/upgrade.py,sha256=cuVNx1zdFyHONDqoVCWZfDEnahNGk6ae4RWuPtYeOjw,5036
|
|
26
|
+
uv_stack-0.1.2.dist-info/METADATA,sha256=GALxy5UNY16PShoi6G6aEyWSGgcT0F39IS5kvuw4tQE,495
|
|
27
|
+
uv_stack-0.1.2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
28
|
+
uv_stack-0.1.2.dist-info/entry_points.txt,sha256=GTSqWe7vFv-vkFM5ickPiQ40BE5ExnJ2od4wAVZp1bs,44
|
|
29
|
+
uv_stack-0.1.2.dist-info/RECORD,,
|