lading 0.2.0__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.
- lading/__init__.py +12 -0
- lading/cli.py +449 -0
- lading/commands/__init__.py +7 -0
- lading/commands/_shared.py +15 -0
- lading/commands/bump.py +574 -0
- lading/commands/bump_docs.py +402 -0
- lading/commands/bump_lockfiles.py +154 -0
- lading/commands/bump_output.py +131 -0
- lading/commands/bump_readme.py +284 -0
- lading/commands/bump_toml.py +253 -0
- lading/commands/cargo_output_adapter.py +217 -0
- lading/commands/lockfile.py +275 -0
- lading/commands/publish.py +746 -0
- lading/commands/publish_diagnostics.py +84 -0
- lading/commands/publish_errors.py +79 -0
- lading/commands/publish_execution.py +52 -0
- lading/commands/publish_index_check.py +394 -0
- lading/commands/publish_manifest.py +206 -0
- lading/commands/publish_plan.py +274 -0
- lading/commands/publish_preflight.py +392 -0
- lading/config.py +441 -0
- lading/exceptions.py +20 -0
- lading/runtime/__init__.py +39 -0
- lading/runtime/runner.py +53 -0
- lading/runtime/subprocess_runner.py +367 -0
- lading/testing/__init__.py +3 -0
- lading/testing/cmd_mox_runner.py +350 -0
- lading/testing/toml_utils.py +239 -0
- lading/utils/__init__.py +8 -0
- lading/utils/commands.py +39 -0
- lading/utils/metrics.py +167 -0
- lading/utils/path.py +32 -0
- lading/utils/process.py +186 -0
- lading/workspace/__init__.py +31 -0
- lading/workspace/metadata.py +157 -0
- lading/workspace/models.py +576 -0
- lading-0.2.0.dist-info/METADATA +68 -0
- lading-0.2.0.dist-info/RECORD +42 -0
- lading-0.2.0.dist-info/WHEEL +5 -0
- lading-0.2.0.dist-info/entry_points.txt +2 -0
- lading-0.2.0.dist-info/licenses/LICENSE +13 -0
- lading-0.2.0.dist-info/top_level.txt +1 -0
lading/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Lading CLI package.
|
|
2
|
+
|
|
3
|
+
This package initialises the Cyclopts application and exposes the
|
|
4
|
+
:func:`lading.cli.main` entry point for process launchers.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from .cli import app, main
|
|
10
|
+
from .exceptions import LadingError
|
|
11
|
+
|
|
12
|
+
__all__ = ["LadingError", "app", "main"]
|
lading/cli.py
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"""Command-line interface for the :mod:`lading` toolkit.
|
|
2
|
+
|
|
3
|
+
This module is the driving adapter between shell invocations and the command
|
|
4
|
+
implementations under :mod:`lading.commands`. It owns argument declarations,
|
|
5
|
+
environment-variable defaults, logging setup, workspace-root normalization,
|
|
6
|
+
configuration loading, and workspace metadata loading before dispatching to the
|
|
7
|
+
`bump` or `publish` command modules.
|
|
8
|
+
|
|
9
|
+
The CLI resolves user-interface concerns here before crossing into command
|
|
10
|
+
internals, but it does not coalesce optional flags against configuration
|
|
11
|
+
defaults. For example, :func:`bump` forwards its ``rebuild_lockfiles``
|
|
12
|
+
parameter as ``bool | None`` exactly as received; the command layer
|
|
13
|
+
(``lading.commands.bump._initialize_bump_context``) owns resolving an unset
|
|
14
|
+
value against ``configuration.bump.rebuild_lockfiles``. This keeps the
|
|
15
|
+
nullable-to-concrete defaulting in a single place rather than splitting it
|
|
16
|
+
across the CLI adapter and the command module.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import collections.abc as cabc
|
|
22
|
+
import importlib
|
|
23
|
+
import logging
|
|
24
|
+
import os
|
|
25
|
+
import re
|
|
26
|
+
import sys
|
|
27
|
+
import typing as typ
|
|
28
|
+
from contextlib import contextmanager
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
|
|
31
|
+
from cyclopts import App, Parameter
|
|
32
|
+
|
|
33
|
+
from . import commands, config
|
|
34
|
+
from .runtime import CommandRunner, subprocess_runner
|
|
35
|
+
from .utils import metrics, normalise_workspace_root
|
|
36
|
+
from .workspace import WorkspaceGraph, WorkspaceModelError, load_workspace
|
|
37
|
+
from .workspace import metadata as metadata_module
|
|
38
|
+
|
|
39
|
+
WORKSPACE_ROOT_ENV_VAR = "LADING_WORKSPACE_ROOT"
|
|
40
|
+
WORKSPACE_ROOT_REQUIRED_MESSAGE = "--workspace-root requires a value"
|
|
41
|
+
_WORKSPACE_PARAMETER = Parameter(
|
|
42
|
+
name="workspace-root",
|
|
43
|
+
env_var=WORKSPACE_ROOT_ENV_VAR,
|
|
44
|
+
help="Path to the Rust workspace root.",
|
|
45
|
+
)
|
|
46
|
+
WorkspaceRootOption = typ.Annotated[Path, _WORKSPACE_PARAMETER]
|
|
47
|
+
|
|
48
|
+
_VERSION_PARAMETER = Parameter(
|
|
49
|
+
help="Target semantic version (e.g., 1.2.3) to set across workspace manifests.",
|
|
50
|
+
)
|
|
51
|
+
VersionArgument = typ.Annotated[str, _VERSION_PARAMETER]
|
|
52
|
+
|
|
53
|
+
_DRY_RUN_PARAMETER = Parameter(
|
|
54
|
+
name="dry-run",
|
|
55
|
+
help="Preview manifest changes without writing files.",
|
|
56
|
+
)
|
|
57
|
+
DryRunFlag = typ.Annotated[bool, _DRY_RUN_PARAMETER]
|
|
58
|
+
|
|
59
|
+
_REBUILD_LOCKFILES_PARAMETER = Parameter(
|
|
60
|
+
name="rebuild-lockfiles",
|
|
61
|
+
negative="no-rebuild-lockfiles",
|
|
62
|
+
help="Regenerate Cargo.lock files after manifest updates.",
|
|
63
|
+
)
|
|
64
|
+
RebuildLockfilesFlag = typ.Annotated[bool, _REBUILD_LOCKFILES_PARAMETER]
|
|
65
|
+
|
|
66
|
+
_LIVE_PARAMETER = Parameter(
|
|
67
|
+
name="live",
|
|
68
|
+
help="Run cargo publish without --dry-run; default behaviour is dry-run.",
|
|
69
|
+
)
|
|
70
|
+
LiveFlag = typ.Annotated[bool, _LIVE_PARAMETER]
|
|
71
|
+
|
|
72
|
+
_FORBID_DIRTY_PARAMETER = Parameter(
|
|
73
|
+
name="forbid-dirty",
|
|
74
|
+
help=("Require a clean working tree before running publish pre-flight checks."),
|
|
75
|
+
)
|
|
76
|
+
ForbidDirtyFlag = typ.Annotated[bool, _FORBID_DIRTY_PARAMETER]
|
|
77
|
+
|
|
78
|
+
_ALLOW_UNPUBLISHED_WORKSPACE_DEPS_PARAMETER = Parameter(
|
|
79
|
+
name="allow-unpublished-workspace-deps",
|
|
80
|
+
help=(
|
|
81
|
+
"Dry-run only: downgrade cargo package failures caused by a sibling "
|
|
82
|
+
"workspace crate version not yet on crates.io to a warning when the "
|
|
83
|
+
"missing crate is part of the planned publish set and appears earlier "
|
|
84
|
+
"in publish order. Defaults to enabled in dry-run mode. Cannot be "
|
|
85
|
+
"combined with --live."
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
AllowUnpublishedWorkspaceDepsFlag = typ.Annotated[
|
|
89
|
+
bool | None, _ALLOW_UNPUBLISHED_WORKSPACE_DEPS_PARAMETER
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
LOG_LEVEL_ENV_VAR = "LADING_LOG_LEVEL"
|
|
93
|
+
_DEFAULT_LOG_LEVEL = logging.INFO
|
|
94
|
+
_LOG_FORMAT = "%(levelname)s: %(message)s"
|
|
95
|
+
_LADING_HANDLER_NAME = "lading-cli-handler"
|
|
96
|
+
_CMD_MOX_STUB_ENV = "LADING_USE_CMD_MOX_STUB"
|
|
97
|
+
_CMD_MOX_TRUTHY_VALUES = frozenset({"1", "true", "yes", "on"})
|
|
98
|
+
_LOG_LEVEL_ALIASES: dict[str, int] = {
|
|
99
|
+
"CRITICAL": logging.CRITICAL,
|
|
100
|
+
"FATAL": logging.CRITICAL,
|
|
101
|
+
"ERROR": logging.ERROR,
|
|
102
|
+
"WARNING": logging.WARNING,
|
|
103
|
+
"WARN": logging.WARNING,
|
|
104
|
+
"INFO": logging.INFO,
|
|
105
|
+
"DEBUG": logging.DEBUG,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
app = App(help="Manage Rust workspaces with the lading toolkit.")
|
|
109
|
+
LOGGER = logging.getLogger(__name__)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _select_runner() -> CommandRunner:
|
|
113
|
+
"""Return the command runner selected for this CLI invocation."""
|
|
114
|
+
stub_value = os.environ.get(_CMD_MOX_STUB_ENV, "")
|
|
115
|
+
if stub_value.lower() in _CMD_MOX_TRUTHY_VALUES:
|
|
116
|
+
try:
|
|
117
|
+
module = importlib.import_module("lading.testing.cmd_mox_runner")
|
|
118
|
+
except ModuleNotFoundError as exc:
|
|
119
|
+
message = (
|
|
120
|
+
f"{_CMD_MOX_STUB_ENV} is set, but the cmd-mox test runner "
|
|
121
|
+
"could not be imported. Install the test dependencies or unset "
|
|
122
|
+
f"{_CMD_MOX_STUB_ENV}."
|
|
123
|
+
)
|
|
124
|
+
raise SystemExit(message) from exc
|
|
125
|
+
return typ.cast("CommandRunner", module.cmd_mox_runner)
|
|
126
|
+
return subprocess_runner
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _validate_workspace_value(value: str) -> str:
|
|
130
|
+
"""Ensure ``value`` is usable as a workspace path."""
|
|
131
|
+
if not value or value.startswith("-"):
|
|
132
|
+
raise SystemExit(WORKSPACE_ROOT_REQUIRED_MESSAGE)
|
|
133
|
+
return value
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _parse_workspace_flag(tokens: cabc.Sequence[str], index: int) -> tuple[str, int]:
|
|
137
|
+
"""Parse ``--workspace-root <path>`` form starting at ``index``."""
|
|
138
|
+
try:
|
|
139
|
+
candidate = tokens[index + 1]
|
|
140
|
+
except IndexError as err:
|
|
141
|
+
raise SystemExit(WORKSPACE_ROOT_REQUIRED_MESSAGE) from err
|
|
142
|
+
workspace = _validate_workspace_value(candidate)
|
|
143
|
+
return workspace, index + 2
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _parse_workspace_equals(argument: str, index: int) -> tuple[str, int]:
|
|
147
|
+
"""Parse ``--workspace-root=<path>`` form for ``argument``."""
|
|
148
|
+
candidate = argument.partition("=")[2]
|
|
149
|
+
workspace = _validate_workspace_value(candidate)
|
|
150
|
+
return workspace, index + 1
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _resolve_allow_unpublished_workspace_deps(
|
|
154
|
+
*,
|
|
155
|
+
live: bool,
|
|
156
|
+
allow_unpublished_workspace_deps: bool | None,
|
|
157
|
+
) -> bool:
|
|
158
|
+
"""Resolve the tri-state ``--allow-unpublished-workspace-deps`` flag.
|
|
159
|
+
|
|
160
|
+
An explicit flag value is honoured verbatim. When the flag is omitted the
|
|
161
|
+
default depends on the publish mode: ``False`` for live publishes and
|
|
162
|
+
``True`` for dry runs, so unpublished workspace members do not abort a
|
|
163
|
+
rehearsal.
|
|
164
|
+
|
|
165
|
+
Logging side effects: applying the dry-run default emits an INFO record so
|
|
166
|
+
operators can see the decision, and every call emits a DEBUG record with the
|
|
167
|
+
raw input, mode, resolved value, and the reason it was chosen.
|
|
168
|
+
"""
|
|
169
|
+
if allow_unpublished_workspace_deps is not None:
|
|
170
|
+
resolved_value = allow_unpublished_workspace_deps
|
|
171
|
+
reason = "explicit flag"
|
|
172
|
+
elif live:
|
|
173
|
+
resolved_value = False
|
|
174
|
+
reason = "live mode suppresses default"
|
|
175
|
+
else:
|
|
176
|
+
# Dry runs default to permissive so unpublished workspace members do
|
|
177
|
+
# not abort a rehearsal; operators should see that decision at INFO.
|
|
178
|
+
LOGGER.info(
|
|
179
|
+
"Defaulting to allow unpublished workspace dependencies "
|
|
180
|
+
"during dry-run publish"
|
|
181
|
+
)
|
|
182
|
+
resolved_value = True
|
|
183
|
+
reason = "dry-run default"
|
|
184
|
+
LOGGER.debug(
|
|
185
|
+
"_resolve_allow_unpublished_workspace_deps: raw=%r live=%r -> resolved=%r (%s)",
|
|
186
|
+
allow_unpublished_workspace_deps,
|
|
187
|
+
live,
|
|
188
|
+
resolved_value,
|
|
189
|
+
reason,
|
|
190
|
+
)
|
|
191
|
+
return resolved_value
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _extract_workspace_override(
|
|
195
|
+
tokens: cabc.Sequence[str],
|
|
196
|
+
) -> tuple[str | None, list[str]]:
|
|
197
|
+
"""Split ``--workspace-root`` from CLI tokens.
|
|
198
|
+
|
|
199
|
+
The flag can appear in either ``--workspace-root <path>`` or
|
|
200
|
+
``--workspace-root=<path>`` form. The last occurrence wins, matching
|
|
201
|
+
common CLI conventions. The returned token list can be passed directly
|
|
202
|
+
to :func:`cyclopts.App.__call__`.
|
|
203
|
+
"""
|
|
204
|
+
workspace: str | None = None
|
|
205
|
+
remainder: list[str] = []
|
|
206
|
+
index = 0
|
|
207
|
+
while index < len(tokens):
|
|
208
|
+
current_argument = tokens[index]
|
|
209
|
+
if current_argument == "--workspace-root":
|
|
210
|
+
workspace, index = _parse_workspace_flag(tokens, index)
|
|
211
|
+
continue
|
|
212
|
+
if current_argument.startswith("--workspace-root="):
|
|
213
|
+
workspace, index = _parse_workspace_equals(current_argument, index)
|
|
214
|
+
continue
|
|
215
|
+
remainder.append(current_argument)
|
|
216
|
+
index += 1
|
|
217
|
+
return workspace, remainder
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _resolve_log_level(value: str | None) -> int:
|
|
221
|
+
"""Return the configured log level or :data:`_DEFAULT_LOG_LEVEL`."""
|
|
222
|
+
if value is None:
|
|
223
|
+
return _DEFAULT_LOG_LEVEL
|
|
224
|
+
candidate = value.strip()
|
|
225
|
+
if not candidate:
|
|
226
|
+
return _DEFAULT_LOG_LEVEL
|
|
227
|
+
level = _LOG_LEVEL_ALIASES.get(candidate.upper())
|
|
228
|
+
if level is None:
|
|
229
|
+
choices = ", ".join(sorted(_LOG_LEVEL_ALIASES))
|
|
230
|
+
message = (
|
|
231
|
+
f"Invalid {LOG_LEVEL_ENV_VAR} value {value!r}; expected one of: {choices}"
|
|
232
|
+
)
|
|
233
|
+
raise SystemExit(message)
|
|
234
|
+
return level
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _configure_logging(stream: typ.TextIO | None = None) -> None:
|
|
238
|
+
"""Configure root logging so command execution is visible."""
|
|
239
|
+
level = _resolve_log_level(os.environ.get(LOG_LEVEL_ENV_VAR))
|
|
240
|
+
root_logger = logging.getLogger()
|
|
241
|
+
root_logger.setLevel(level)
|
|
242
|
+
existing_handler = next(
|
|
243
|
+
(
|
|
244
|
+
existing
|
|
245
|
+
for existing in root_logger.handlers
|
|
246
|
+
if getattr(existing, "name", "") == _LADING_HANDLER_NAME
|
|
247
|
+
),
|
|
248
|
+
None,
|
|
249
|
+
)
|
|
250
|
+
if existing_handler is None:
|
|
251
|
+
handler = logging.StreamHandler(stream)
|
|
252
|
+
handler.name = _LADING_HANDLER_NAME
|
|
253
|
+
root_logger.addHandler(handler)
|
|
254
|
+
else:
|
|
255
|
+
handler = existing_handler
|
|
256
|
+
if stream is not None and isinstance(handler, logging.StreamHandler):
|
|
257
|
+
handler.stream = stream
|
|
258
|
+
handler.setLevel(level)
|
|
259
|
+
handler.setFormatter(logging.Formatter(_LOG_FORMAT))
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@contextmanager
|
|
263
|
+
def _workspace_env(value: Path) -> cabc.Iterator[None]:
|
|
264
|
+
"""Temporarily set :data:`WORKSPACE_ROOT_ENV_VAR` to ``value``."""
|
|
265
|
+
previous = os.environ.get(WORKSPACE_ROOT_ENV_VAR)
|
|
266
|
+
os.environ[WORKSPACE_ROOT_ENV_VAR] = str(value)
|
|
267
|
+
try:
|
|
268
|
+
yield
|
|
269
|
+
finally:
|
|
270
|
+
if previous is None:
|
|
271
|
+
os.environ.pop(WORKSPACE_ROOT_ENV_VAR, None)
|
|
272
|
+
else:
|
|
273
|
+
os.environ[WORKSPACE_ROOT_ENV_VAR] = previous
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _dispatch_and_print(tokens: cabc.Sequence[str]) -> int:
|
|
277
|
+
"""Execute the Cyclopts app and print command results."""
|
|
278
|
+
try:
|
|
279
|
+
result = app(tokens)
|
|
280
|
+
except SystemExit as err:
|
|
281
|
+
code = err.code
|
|
282
|
+
if code is None:
|
|
283
|
+
return 0
|
|
284
|
+
if isinstance(code, int):
|
|
285
|
+
return code
|
|
286
|
+
print(code, file=sys.stderr)
|
|
287
|
+
return 1
|
|
288
|
+
if isinstance(result, int):
|
|
289
|
+
return result
|
|
290
|
+
if result is not None:
|
|
291
|
+
print(result)
|
|
292
|
+
return 0
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def main(argv: cabc.Sequence[str] | None = None) -> int:
|
|
296
|
+
"""Entry point for ``python -m lading.cli``."""
|
|
297
|
+
try:
|
|
298
|
+
if argv is None:
|
|
299
|
+
argv = sys.argv[1:]
|
|
300
|
+
_configure_logging()
|
|
301
|
+
# Flush the accumulated metrics summary when this CLI process exits.
|
|
302
|
+
# Registered here in bootstrap so the lifecycle is explicit rather than
|
|
303
|
+
# an import-time side effect of lading.utils.metrics.
|
|
304
|
+
metrics.register_summary_atexit()
|
|
305
|
+
workspace_override, remaining = _extract_workspace_override(list(argv))
|
|
306
|
+
workspace_root = normalise_workspace_root(workspace_override)
|
|
307
|
+
if not remaining:
|
|
308
|
+
_dispatch_and_print(remaining) # Print usage message
|
|
309
|
+
return 2 # Standard exit code for missing subcommand
|
|
310
|
+
previous_config = app.config
|
|
311
|
+
config_loader = config.build_loader(workspace_root)
|
|
312
|
+
try:
|
|
313
|
+
configuration = config.load_from_loader(config_loader)
|
|
314
|
+
except config.ConfigurationError as exc:
|
|
315
|
+
print(f"Configuration error: {exc}", file=sys.stderr)
|
|
316
|
+
return 1
|
|
317
|
+
app.config = (config_loader,)
|
|
318
|
+
try:
|
|
319
|
+
with (
|
|
320
|
+
_workspace_env(workspace_root),
|
|
321
|
+
config.use_configuration(configuration),
|
|
322
|
+
):
|
|
323
|
+
try:
|
|
324
|
+
return _dispatch_and_print(remaining)
|
|
325
|
+
except WorkspaceModelError as exc:
|
|
326
|
+
print(f"Workspace error: {exc}", file=sys.stderr)
|
|
327
|
+
return 1
|
|
328
|
+
finally:
|
|
329
|
+
app.config = previous_config
|
|
330
|
+
except KeyboardInterrupt:
|
|
331
|
+
print("\nOperation cancelled by user.", file=sys.stderr)
|
|
332
|
+
return 130
|
|
333
|
+
except Exception as exc: # noqa: BLE001 - fallback guard for CLI entry point
|
|
334
|
+
print(f"Unexpected error: {exc}", file=sys.stderr)
|
|
335
|
+
return 1
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def _run_with_context(
|
|
339
|
+
workspace_root: Path,
|
|
340
|
+
runner: cabc.Callable[
|
|
341
|
+
[Path, config.LadingConfig, WorkspaceGraph, CommandRunner],
|
|
342
|
+
str,
|
|
343
|
+
],
|
|
344
|
+
*,
|
|
345
|
+
command_runner: CommandRunner | None = None,
|
|
346
|
+
) -> str:
|
|
347
|
+
"""Execute ``runner`` with configuration and workspace data."""
|
|
348
|
+
active_runner = command_runner or _select_runner()
|
|
349
|
+
try:
|
|
350
|
+
configuration = config.current_configuration()
|
|
351
|
+
except config.ConfigurationNotLoadedError:
|
|
352
|
+
configuration = config.load_configuration(workspace_root)
|
|
353
|
+
with (
|
|
354
|
+
config.use_configuration(configuration),
|
|
355
|
+
metadata_module.use_command_runner(active_runner),
|
|
356
|
+
):
|
|
357
|
+
workspace_model = load_workspace(workspace_root)
|
|
358
|
+
return runner(workspace_root, configuration, workspace_model, active_runner)
|
|
359
|
+
with metadata_module.use_command_runner(active_runner):
|
|
360
|
+
workspace_model = load_workspace(workspace_root)
|
|
361
|
+
return runner(workspace_root, configuration, workspace_model, active_runner)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
_VERSION_PATTERN = re.compile(
|
|
365
|
+
r"^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$"
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _validate_version_argument(version: str) -> None:
|
|
370
|
+
"""Ensure ``version`` matches the semantic version pattern."""
|
|
371
|
+
if not _VERSION_PATTERN.fullmatch(version):
|
|
372
|
+
message = (
|
|
373
|
+
"Invalid version argument "
|
|
374
|
+
f"{version!r}. Expected semantic version in the form "
|
|
375
|
+
"<major>.<minor>.<patch> with optional pre-release/build segments."
|
|
376
|
+
)
|
|
377
|
+
raise SystemExit(message)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
@app.command
|
|
381
|
+
def bump(
|
|
382
|
+
version: VersionArgument,
|
|
383
|
+
workspace_root: WorkspaceRootOption | None = None,
|
|
384
|
+
*,
|
|
385
|
+
dry_run: DryRunFlag = False,
|
|
386
|
+
rebuild_lockfiles: RebuildLockfilesFlag | None = None,
|
|
387
|
+
) -> str:
|
|
388
|
+
"""Update workspace manifests to ``version``."""
|
|
389
|
+
_validate_version_argument(version)
|
|
390
|
+
resolved = normalise_workspace_root(workspace_root)
|
|
391
|
+
return _run_with_context(
|
|
392
|
+
resolved,
|
|
393
|
+
lambda root, configuration, workspace, command_runner: commands.bump.run(
|
|
394
|
+
root,
|
|
395
|
+
version,
|
|
396
|
+
options=commands.bump.BumpOptions(
|
|
397
|
+
dry_run=dry_run,
|
|
398
|
+
# Forwarded unresolved: default-resolution against the
|
|
399
|
+
# configuration is the bump command's responsibility
|
|
400
|
+
# (_initialize_bump_context), not the CLI adapter's.
|
|
401
|
+
rebuild_lockfiles=rebuild_lockfiles,
|
|
402
|
+
configuration=configuration,
|
|
403
|
+
workspace=workspace,
|
|
404
|
+
command_runner=command_runner,
|
|
405
|
+
),
|
|
406
|
+
),
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
@app.command
|
|
411
|
+
def publish(
|
|
412
|
+
workspace_root: WorkspaceRootOption | None = None,
|
|
413
|
+
*,
|
|
414
|
+
forbid_dirty: ForbidDirtyFlag = False,
|
|
415
|
+
live: LiveFlag = False,
|
|
416
|
+
allow_unpublished_workspace_deps: AllowUnpublishedWorkspaceDepsFlag = None,
|
|
417
|
+
) -> str:
|
|
418
|
+
"""Run pre-flight checks, package crates, and execute cargo publish.
|
|
419
|
+
|
|
420
|
+
The command performs pre-flight validation, stages the workspace, runs
|
|
421
|
+
``cargo package`` for each publishable crate, and then executes ``cargo
|
|
422
|
+
publish`` (dry-run by default, live when ``--live`` is supplied).
|
|
423
|
+
"""
|
|
424
|
+
resolved = normalise_workspace_root(workspace_root)
|
|
425
|
+
return _run_with_context(
|
|
426
|
+
resolved,
|
|
427
|
+
lambda root, configuration, workspace, command_runner: commands.publish.run(
|
|
428
|
+
root,
|
|
429
|
+
configuration,
|
|
430
|
+
workspace,
|
|
431
|
+
options=commands.publish.PublishOptions(
|
|
432
|
+
allow_dirty=not forbid_dirty,
|
|
433
|
+
live=live,
|
|
434
|
+
allow_unpublished_workspace_deps=(
|
|
435
|
+
_resolve_allow_unpublished_workspace_deps(
|
|
436
|
+
live=live,
|
|
437
|
+
allow_unpublished_workspace_deps=(
|
|
438
|
+
allow_unpublished_workspace_deps
|
|
439
|
+
),
|
|
440
|
+
)
|
|
441
|
+
),
|
|
442
|
+
command_runner=command_runner,
|
|
443
|
+
),
|
|
444
|
+
),
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
if __name__ == "__main__": # pragma: no cover - convenience entry point
|
|
449
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Shared helpers for placeholder command implementations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typing as typ
|
|
6
|
+
|
|
7
|
+
if typ.TYPE_CHECKING: # pragma: no cover - typing helper only
|
|
8
|
+
from lading.workspace import WorkspaceGraph
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def describe_crates(workspace: WorkspaceGraph) -> str:
|
|
12
|
+
"""Return a human-friendly crate count summary."""
|
|
13
|
+
count = len(workspace.crates)
|
|
14
|
+
label = "crate" if count == 1 else "crates"
|
|
15
|
+
return f"{count} {label}"
|