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/commands/bump.py
ADDED
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
"""Version bumping command implementation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import collections.abc as cabc
|
|
6
|
+
import dataclasses as dc
|
|
7
|
+
import logging
|
|
8
|
+
import types
|
|
9
|
+
import typing as typ
|
|
10
|
+
|
|
11
|
+
from lading import config as config_module
|
|
12
|
+
from lading.commands import bump_docs, bump_lockfiles, bump_readme, bump_toml
|
|
13
|
+
from lading.utils import normalise_workspace_root
|
|
14
|
+
|
|
15
|
+
if typ.TYPE_CHECKING:
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from lading.config import LadingConfig
|
|
19
|
+
from lading.runtime import CommandRunner
|
|
20
|
+
from lading.workspace import WorkspaceCrate, WorkspaceGraph
|
|
21
|
+
|
|
22
|
+
_WORKSPACE_SELECTORS: typ.Final[tuple[tuple[str, ...], ...]] = (
|
|
23
|
+
("package",),
|
|
24
|
+
("workspace", "package"),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Derived from the canonical section vocabulary so the kind mapping cannot
|
|
28
|
+
# drift from ``bump_toml.DEPENDENCY_SECTIONS``.
|
|
29
|
+
_NORMAL_SECTION, _DEV_SECTION, _BUILD_SECTION = bump_toml.DEPENDENCY_SECTIONS
|
|
30
|
+
|
|
31
|
+
_DEPENDENCY_SECTION_BY_KIND: typ.Final[dict[str | None, str]] = {
|
|
32
|
+
None: _NORMAL_SECTION,
|
|
33
|
+
"normal": _NORMAL_SECTION,
|
|
34
|
+
"dev": _DEV_SECTION,
|
|
35
|
+
"build": _BUILD_SECTION,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
LOGGER = logging.getLogger(__name__)
|
|
39
|
+
_log = LOGGER
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dc.dataclass(frozen=True, slots=True)
|
|
43
|
+
class BumpOptions:
|
|
44
|
+
"""Configuration options for bump operations.
|
|
45
|
+
|
|
46
|
+
Attributes
|
|
47
|
+
----------
|
|
48
|
+
dry_run : bool, default False
|
|
49
|
+
Preview manifest, documentation, and lockfile changes without writing
|
|
50
|
+
files or running state-changing lockfile rebuild commands. Dry-runs
|
|
51
|
+
report the lockfiles that would be rebuilt.
|
|
52
|
+
rebuild_lockfiles : bool | None, default None
|
|
53
|
+
Controls lockfile regeneration after manifest updates. ``None`` inherits
|
|
54
|
+
``configuration.bump.rebuild_lockfiles``; ``True`` and ``False``
|
|
55
|
+
override configuration for this run.
|
|
56
|
+
configuration : LadingConfig | None, default None
|
|
57
|
+
Loaded lading configuration. Programmatic callers may omit it only when
|
|
58
|
+
they want ``run`` to load configuration from the workspace root.
|
|
59
|
+
workspace : WorkspaceGraph | None, default None
|
|
60
|
+
Loaded workspace graph. Programmatic callers may omit it only when they
|
|
61
|
+
want ``run`` to inspect the workspace.
|
|
62
|
+
command_runner : CommandRunner | None, default None
|
|
63
|
+
Callable with the runtime command-runner interface. It is used for
|
|
64
|
+
lockfile rebuild commands; ``None`` uses the default subprocess runner.
|
|
65
|
+
dependency_sections : Mapping[str, Collection[str]]
|
|
66
|
+
Explicit dependency sections to rewrite by crate name.
|
|
67
|
+
include_workspace_sections : bool, default False
|
|
68
|
+
Whether workspace dependency tables should be rewritten as well.
|
|
69
|
+
|
|
70
|
+
Notes
|
|
71
|
+
-----
|
|
72
|
+
Instances are frozen and slot-based. Options are immutable after creation
|
|
73
|
+
and compact, but callers should not rely on dynamic attributes or mutation.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
dry_run: bool = False
|
|
77
|
+
rebuild_lockfiles: bool | None = None
|
|
78
|
+
configuration: LadingConfig | None = None
|
|
79
|
+
workspace: WorkspaceGraph | None = None
|
|
80
|
+
command_runner: CommandRunner | None = None
|
|
81
|
+
dependency_sections: cabc.Mapping[str, cabc.Collection[str]] = dc.field(
|
|
82
|
+
default_factory=lambda: types.MappingProxyType({})
|
|
83
|
+
)
|
|
84
|
+
include_workspace_sections: bool = False
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@dc.dataclass(frozen=True, slots=True)
|
|
88
|
+
class BumpChanges:
|
|
89
|
+
"""Collection of files altered by a bump run."""
|
|
90
|
+
|
|
91
|
+
manifests: cabc.Sequence[Path] = ()
|
|
92
|
+
documents: cabc.Sequence[Path] = ()
|
|
93
|
+
lockfiles: cabc.Sequence[Path] = ()
|
|
94
|
+
transposed_readmes: cabc.Sequence[Path] = ()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dc.dataclass(frozen=True, slots=True)
|
|
98
|
+
class _BumpContext:
|
|
99
|
+
"""Initialisation context for bump operations."""
|
|
100
|
+
|
|
101
|
+
root_path: Path
|
|
102
|
+
configuration: LadingConfig
|
|
103
|
+
workspace: WorkspaceGraph
|
|
104
|
+
base_options: BumpOptions
|
|
105
|
+
workspace_manifest: Path
|
|
106
|
+
excluded: frozenset[str]
|
|
107
|
+
updated_crate_names: frozenset[str]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _build_changes_description(changes: BumpChanges) -> str:
|
|
111
|
+
"""Build a human-readable description of changed files."""
|
|
112
|
+
parts: list[str] = []
|
|
113
|
+
if changes.manifests:
|
|
114
|
+
parts.append(f"{len(changes.manifests)} manifest(s)")
|
|
115
|
+
if changes.documents:
|
|
116
|
+
parts.append(f"{len(changes.documents)} documentation file(s)")
|
|
117
|
+
if changes.transposed_readmes:
|
|
118
|
+
parts.append(f"{len(changes.transposed_readmes)} readme file(s)")
|
|
119
|
+
if changes.lockfiles:
|
|
120
|
+
parts.append(f"{len(changes.lockfiles)} lockfile(s)")
|
|
121
|
+
return parts[0] if len(parts) == 1 else " and ".join(parts)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _format_no_changes_message(target_version: str, *, dry_run: bool) -> str:
|
|
125
|
+
"""Format message when no changes are required."""
|
|
126
|
+
if dry_run:
|
|
127
|
+
return (
|
|
128
|
+
"Dry run; no manifest changes required; "
|
|
129
|
+
f"all versions already {target_version}."
|
|
130
|
+
)
|
|
131
|
+
return f"No manifest changes required; all versions already {target_version}."
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _format_header(description: str, target_version: str, *, dry_run: bool) -> str:
|
|
135
|
+
"""Format the summary header line."""
|
|
136
|
+
if dry_run:
|
|
137
|
+
return f"Dry run; would update version to {target_version} in {description}:"
|
|
138
|
+
return f"Updated version to {target_version} in {description}:"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _format_manifest_path(manifest_path: Path, workspace_root: Path) -> str:
|
|
142
|
+
"""Return ``manifest_path`` relative to ``workspace_root`` when possible."""
|
|
143
|
+
try:
|
|
144
|
+
relative = manifest_path.relative_to(workspace_root)
|
|
145
|
+
except ValueError:
|
|
146
|
+
return str(manifest_path)
|
|
147
|
+
return str(relative)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _has_changes(changes: BumpChanges) -> bool:
|
|
151
|
+
"""Return True when a bump run changed at least one file category."""
|
|
152
|
+
return any((
|
|
153
|
+
changes.manifests,
|
|
154
|
+
changes.documents,
|
|
155
|
+
changes.transposed_readmes,
|
|
156
|
+
changes.lockfiles,
|
|
157
|
+
))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def run(
|
|
161
|
+
workspace_root: Path | str,
|
|
162
|
+
target_version: str,
|
|
163
|
+
*,
|
|
164
|
+
options: BumpOptions | None = None,
|
|
165
|
+
) -> str:
|
|
166
|
+
"""Update workspace and crate manifest versions to ``target_version``."""
|
|
167
|
+
context = _initialize_bump_context(workspace_root, options)
|
|
168
|
+
changed_manifests: set[Path] = set()
|
|
169
|
+
_process_workspace_manifest(context, target_version, changed_manifests)
|
|
170
|
+
_process_crate_manifests(context, target_version, changed_manifests)
|
|
171
|
+
changed_documents = _process_documentation_files(context, target_version)
|
|
172
|
+
changed_readmes = _process_readme_transposition(
|
|
173
|
+
context, dry_run=context.base_options.dry_run
|
|
174
|
+
)
|
|
175
|
+
changed_lockfiles = _process_lockfiles(context, changed_manifests)
|
|
176
|
+
changes = _prepare_sorted_changes(
|
|
177
|
+
context,
|
|
178
|
+
changed_manifests,
|
|
179
|
+
(changed_documents, changed_readmes, changed_lockfiles),
|
|
180
|
+
)
|
|
181
|
+
return _format_result_message(
|
|
182
|
+
changes,
|
|
183
|
+
target_version,
|
|
184
|
+
dry_run=context.base_options.dry_run,
|
|
185
|
+
workspace_root=context.root_path,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _initialize_bump_context(
|
|
190
|
+
workspace_root: Path | str,
|
|
191
|
+
options: BumpOptions | None,
|
|
192
|
+
) -> _BumpContext:
|
|
193
|
+
"""Return initialised bump context for ``workspace_root``."""
|
|
194
|
+
resolved_options = BumpOptions() if options is None else options
|
|
195
|
+
root_path = normalise_workspace_root(workspace_root)
|
|
196
|
+
configuration = resolved_options.configuration
|
|
197
|
+
if configuration is None:
|
|
198
|
+
configuration = config_module.current_configuration()
|
|
199
|
+
|
|
200
|
+
workspace = resolved_options.workspace
|
|
201
|
+
if workspace is None:
|
|
202
|
+
from lading.workspace import load_workspace
|
|
203
|
+
|
|
204
|
+
workspace = load_workspace(root_path)
|
|
205
|
+
|
|
206
|
+
rebuild_lockfiles = (
|
|
207
|
+
configuration.bump.rebuild_lockfiles
|
|
208
|
+
if resolved_options.rebuild_lockfiles is None
|
|
209
|
+
else resolved_options.rebuild_lockfiles
|
|
210
|
+
)
|
|
211
|
+
_log.debug(
|
|
212
|
+
"rebuild_lockfiles resolution: raw_flag=%r, configured_default=%r, resolved=%r",
|
|
213
|
+
resolved_options.rebuild_lockfiles,
|
|
214
|
+
configuration.bump.rebuild_lockfiles,
|
|
215
|
+
rebuild_lockfiles,
|
|
216
|
+
)
|
|
217
|
+
base_options = BumpOptions(
|
|
218
|
+
dry_run=resolved_options.dry_run,
|
|
219
|
+
rebuild_lockfiles=rebuild_lockfiles,
|
|
220
|
+
configuration=configuration,
|
|
221
|
+
workspace=workspace,
|
|
222
|
+
command_runner=resolved_options.command_runner,
|
|
223
|
+
dependency_sections=resolved_options.dependency_sections,
|
|
224
|
+
include_workspace_sections=resolved_options.include_workspace_sections,
|
|
225
|
+
)
|
|
226
|
+
excluded = frozenset(configuration.bump.exclude)
|
|
227
|
+
updated_crate_names = frozenset(
|
|
228
|
+
crate.name for crate in workspace.crates if crate.name not in excluded
|
|
229
|
+
)
|
|
230
|
+
workspace_manifest = root_path / "Cargo.toml"
|
|
231
|
+
return _BumpContext(
|
|
232
|
+
root_path=root_path,
|
|
233
|
+
configuration=configuration,
|
|
234
|
+
workspace=workspace,
|
|
235
|
+
base_options=base_options,
|
|
236
|
+
workspace_manifest=workspace_manifest,
|
|
237
|
+
excluded=excluded,
|
|
238
|
+
updated_crate_names=updated_crate_names,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _process_workspace_manifest(
|
|
243
|
+
context: _BumpContext,
|
|
244
|
+
target_version: str,
|
|
245
|
+
changed_manifests: set[Path],
|
|
246
|
+
) -> None:
|
|
247
|
+
"""Update the workspace manifest when necessary."""
|
|
248
|
+
dependency_sections = _workspace_dependency_sections(context.updated_crate_names)
|
|
249
|
+
workspace_options = dc.replace(
|
|
250
|
+
context.base_options,
|
|
251
|
+
dependency_sections=_freeze_dependency_sections(dependency_sections),
|
|
252
|
+
include_workspace_sections=True,
|
|
253
|
+
)
|
|
254
|
+
if _update_manifest(
|
|
255
|
+
context.workspace_manifest,
|
|
256
|
+
_WORKSPACE_SELECTORS,
|
|
257
|
+
target_version,
|
|
258
|
+
workspace_options,
|
|
259
|
+
):
|
|
260
|
+
changed_manifests.add(context.workspace_manifest)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def _process_crate_manifests(
|
|
264
|
+
context: _BumpContext,
|
|
265
|
+
target_version: str,
|
|
266
|
+
changed_manifests: set[Path],
|
|
267
|
+
) -> None:
|
|
268
|
+
"""Update member crate manifests for the workspace."""
|
|
269
|
+
for crate in context.workspace.crates:
|
|
270
|
+
if _update_crate_manifest(crate, target_version, context.base_options):
|
|
271
|
+
changed_manifests.add(crate.manifest_path)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _process_documentation_files(
|
|
275
|
+
context: _BumpContext,
|
|
276
|
+
target_version: str,
|
|
277
|
+
) -> set[Path]:
|
|
278
|
+
"""Update configured documentation targets for the workspace."""
|
|
279
|
+
documentation_paths = bump_docs.resolve_documentation_targets(
|
|
280
|
+
context.root_path, context.configuration.bump.documentation
|
|
281
|
+
)
|
|
282
|
+
return bump_docs.update_documentation_files(
|
|
283
|
+
documentation_paths,
|
|
284
|
+
target_version,
|
|
285
|
+
context.updated_crate_names,
|
|
286
|
+
dry_run=context.base_options.dry_run,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _process_readme_transposition(context: _BumpContext, *, dry_run: bool) -> set[Path]:
|
|
291
|
+
"""Transpose workspace README files into opted-in member crates."""
|
|
292
|
+
_log.debug("Starting workspace README transposition")
|
|
293
|
+
changed_readmes: set[Path] = set()
|
|
294
|
+
source_readme_path = context.root_path / "README.md"
|
|
295
|
+
cached_text: str | None = (
|
|
296
|
+
source_readme_path.read_text(encoding="utf-8")
|
|
297
|
+
if source_readme_path.exists()
|
|
298
|
+
else None
|
|
299
|
+
)
|
|
300
|
+
for crate in context.workspace.crates:
|
|
301
|
+
if not crate.readme_is_workspace:
|
|
302
|
+
continue
|
|
303
|
+
try:
|
|
304
|
+
changed_path = bump_readme.transpose_readme_to_crate(
|
|
305
|
+
context.root_path,
|
|
306
|
+
crate,
|
|
307
|
+
dry_run=dry_run,
|
|
308
|
+
_source_text=cached_text,
|
|
309
|
+
)
|
|
310
|
+
except bump_readme.ReadmeTranspositionError:
|
|
311
|
+
_log.error("README transposition failed for crate %r", crate.name)
|
|
312
|
+
raise
|
|
313
|
+
if changed_path is not None:
|
|
314
|
+
changed_readmes.add(changed_path)
|
|
315
|
+
_log.debug(
|
|
316
|
+
"README transposition complete: %d file(s) changed",
|
|
317
|
+
len(changed_readmes),
|
|
318
|
+
)
|
|
319
|
+
return changed_readmes
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _process_lockfiles(
|
|
323
|
+
context: _BumpContext,
|
|
324
|
+
changed_manifests: set[Path],
|
|
325
|
+
) -> tuple[Path, ...]:
|
|
326
|
+
"""Regenerate Cargo lockfiles when bump changes manifest content."""
|
|
327
|
+
if context.base_options.rebuild_lockfiles is not True or not changed_manifests:
|
|
328
|
+
return ()
|
|
329
|
+
lockfile_manifests = context.configuration.bump.lockfile_manifests
|
|
330
|
+
if context.base_options.dry_run:
|
|
331
|
+
return bump_lockfiles.resolve_lockfile_paths(
|
|
332
|
+
context.root_path, lockfile_manifests
|
|
333
|
+
)
|
|
334
|
+
return bump_lockfiles.regenerate_lockfiles(
|
|
335
|
+
context.root_path,
|
|
336
|
+
lockfile_manifests,
|
|
337
|
+
runner=context.base_options.command_runner,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _prepare_sorted_changes(
|
|
342
|
+
context: _BumpContext,
|
|
343
|
+
changed_manifests: set[Path],
|
|
344
|
+
changed_aux: tuple[set[Path], set[Path], cabc.Sequence[Path]],
|
|
345
|
+
) -> BumpChanges:
|
|
346
|
+
"""Return ordered :class:`BumpChanges` suitable for result rendering."""
|
|
347
|
+
changed_documents, changed_readmes, changed_lockfiles = changed_aux
|
|
348
|
+
ordered_manifests = tuple(
|
|
349
|
+
sorted(
|
|
350
|
+
changed_manifests,
|
|
351
|
+
key=lambda path: (path != context.workspace_manifest, str(path)),
|
|
352
|
+
)
|
|
353
|
+
)
|
|
354
|
+
ordered_documents: tuple[Path, ...] = tuple(
|
|
355
|
+
sorted(changed_documents, key=lambda path: str(path))
|
|
356
|
+
)
|
|
357
|
+
ordered_lockfiles: tuple[Path, ...] = tuple(
|
|
358
|
+
sorted(
|
|
359
|
+
changed_lockfiles,
|
|
360
|
+
key=lambda path: (path != context.root_path / "Cargo.lock", str(path)),
|
|
361
|
+
)
|
|
362
|
+
)
|
|
363
|
+
ordered_readmes: tuple[Path, ...] = tuple(
|
|
364
|
+
sorted(changed_readmes, key=lambda path: str(path))
|
|
365
|
+
)
|
|
366
|
+
return BumpChanges(
|
|
367
|
+
manifests=ordered_manifests,
|
|
368
|
+
documents=ordered_documents,
|
|
369
|
+
transposed_readmes=ordered_readmes,
|
|
370
|
+
lockfiles=ordered_lockfiles,
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _update_crate_manifest(
|
|
375
|
+
crate: WorkspaceCrate,
|
|
376
|
+
target_version: str,
|
|
377
|
+
options: BumpOptions,
|
|
378
|
+
) -> bool:
|
|
379
|
+
"""Apply updates for ``crate`` while respecting exclusion rules."""
|
|
380
|
+
configuration, workspace = _validate_bump_options(options)
|
|
381
|
+
|
|
382
|
+
excluded = set(configuration.bump.exclude)
|
|
383
|
+
updated_crate_names = {
|
|
384
|
+
member.name for member in workspace.crates if member.name not in excluded
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
selectors = _determine_package_selectors(crate.name, excluded)
|
|
388
|
+
dependency_sections = _dependency_sections_for_crate(crate, updated_crate_names)
|
|
389
|
+
|
|
390
|
+
if _should_skip_crate_update(selectors, dependency_sections):
|
|
391
|
+
return False
|
|
392
|
+
|
|
393
|
+
crate_options = dc.replace(
|
|
394
|
+
options,
|
|
395
|
+
dependency_sections=_freeze_dependency_sections(dependency_sections),
|
|
396
|
+
)
|
|
397
|
+
return _update_manifest(
|
|
398
|
+
crate.manifest_path,
|
|
399
|
+
selectors,
|
|
400
|
+
target_version,
|
|
401
|
+
crate_options,
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def _format_result_message(
|
|
406
|
+
changes: BumpChanges,
|
|
407
|
+
target_version: str,
|
|
408
|
+
*,
|
|
409
|
+
dry_run: bool,
|
|
410
|
+
workspace_root: Path,
|
|
411
|
+
) -> str:
|
|
412
|
+
"""Summarise the bump outcome for CLI presentation."""
|
|
413
|
+
if not _has_changes(changes):
|
|
414
|
+
return _format_no_changes_message(target_version, dry_run=dry_run)
|
|
415
|
+
|
|
416
|
+
description = _build_changes_description(changes)
|
|
417
|
+
header = _format_header(description, target_version, dry_run=dry_run)
|
|
418
|
+
formatted_paths = [
|
|
419
|
+
f"- {_format_manifest_path(manifest_path, workspace_root)}"
|
|
420
|
+
for manifest_path in changes.manifests
|
|
421
|
+
]
|
|
422
|
+
formatted_paths.extend(
|
|
423
|
+
f"- {_format_manifest_path(document_path, workspace_root)} (documentation)"
|
|
424
|
+
for document_path in changes.documents
|
|
425
|
+
)
|
|
426
|
+
formatted_paths.extend(
|
|
427
|
+
f"- {_format_manifest_path(readme_path, workspace_root)} (readme)"
|
|
428
|
+
for readme_path in changes.transposed_readmes
|
|
429
|
+
)
|
|
430
|
+
formatted_paths.extend(
|
|
431
|
+
f"- {_format_manifest_path(lockfile_path, workspace_root)} (lockfile)"
|
|
432
|
+
for lockfile_path in changes.lockfiles
|
|
433
|
+
)
|
|
434
|
+
return "\n".join([header, *formatted_paths])
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _validate_bump_options(options: BumpOptions) -> tuple[LadingConfig, WorkspaceGraph]:
|
|
438
|
+
"""Validate and extract required configuration and workspace from options.
|
|
439
|
+
|
|
440
|
+
Raises
|
|
441
|
+
------
|
|
442
|
+
ValueError: If configuration or workspace is None.
|
|
443
|
+
|
|
444
|
+
Returns
|
|
445
|
+
-------
|
|
446
|
+
Tuple of (configuration, workspace).
|
|
447
|
+
|
|
448
|
+
"""
|
|
449
|
+
if options.configuration is None or options.workspace is None:
|
|
450
|
+
message = "BumpOptions must supply configuration and workspace."
|
|
451
|
+
raise ValueError(message)
|
|
452
|
+
return options.configuration, options.workspace
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def _determine_package_selectors(
|
|
456
|
+
crate_name: str,
|
|
457
|
+
excluded: cabc.Collection[str],
|
|
458
|
+
) -> tuple[tuple[str, ...], ...]:
|
|
459
|
+
"""Return package selectors for the crate, respecting exclusion rules.
|
|
460
|
+
|
|
461
|
+
Args:
|
|
462
|
+
crate_name: Name of the crate to check.
|
|
463
|
+
excluded: Collection of excluded crate names.
|
|
464
|
+
|
|
465
|
+
Returns
|
|
466
|
+
-------
|
|
467
|
+
Package selectors tuple, or empty tuple if crate is excluded.
|
|
468
|
+
|
|
469
|
+
"""
|
|
470
|
+
return () if crate_name in excluded else (("package",),)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _should_skip_crate_update(
|
|
474
|
+
selectors: tuple[tuple[str, ...], ...],
|
|
475
|
+
dependency_sections: cabc.Mapping[str, cabc.Collection[str]],
|
|
476
|
+
) -> bool:
|
|
477
|
+
"""Check if a crate update should be skipped due to no work required.
|
|
478
|
+
|
|
479
|
+
Returns
|
|
480
|
+
-------
|
|
481
|
+
True if both selectors and dependency_sections are empty.
|
|
482
|
+
|
|
483
|
+
"""
|
|
484
|
+
return not selectors and not dependency_sections
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _freeze_dependency_sections(
|
|
488
|
+
sections: cabc.Mapping[str, cabc.Collection[str]],
|
|
489
|
+
) -> cabc.Mapping[str, cabc.Collection[str]]:
|
|
490
|
+
"""Return an immutable mapping for dependency sections."""
|
|
491
|
+
if not sections:
|
|
492
|
+
return types.MappingProxyType({})
|
|
493
|
+
frozen_sections = {key: tuple(sorted(names)) for key, names in sections.items()}
|
|
494
|
+
return types.MappingProxyType(frozen_sections)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def _update_manifest(
|
|
498
|
+
manifest_path: Path,
|
|
499
|
+
selectors: tuple[tuple[str, ...], ...],
|
|
500
|
+
target_version: str,
|
|
501
|
+
options: BumpOptions,
|
|
502
|
+
) -> bool:
|
|
503
|
+
"""Apply ``target_version`` to each table described by ``selectors``.
|
|
504
|
+
|
|
505
|
+
Args:
|
|
506
|
+
manifest_path: Path to the Cargo.toml manifest file.
|
|
507
|
+
selectors: Tuple of key tuples identifying version tables to update.
|
|
508
|
+
target_version: The target version to apply.
|
|
509
|
+
options: Bump options controlling dry-run, dependency sections, and
|
|
510
|
+
whether to include workspace-level dependency sections.
|
|
511
|
+
|
|
512
|
+
Returns
|
|
513
|
+
-------
|
|
514
|
+
True if any changes were made.
|
|
515
|
+
|
|
516
|
+
"""
|
|
517
|
+
document = bump_toml.parse_manifest(manifest_path)
|
|
518
|
+
changed = False
|
|
519
|
+
for selector in selectors:
|
|
520
|
+
table = bump_toml.select_table(document, selector)
|
|
521
|
+
changed |= bump_toml.assign_version(table, target_version)
|
|
522
|
+
if options.dependency_sections:
|
|
523
|
+
changed |= bump_toml.update_dependency_sections(
|
|
524
|
+
document,
|
|
525
|
+
options.dependency_sections,
|
|
526
|
+
target_version,
|
|
527
|
+
include_workspace_sections=options.include_workspace_sections,
|
|
528
|
+
)
|
|
529
|
+
if changed and not options.dry_run:
|
|
530
|
+
bump_toml.write_atomic_text(manifest_path, document.as_string())
|
|
531
|
+
return changed
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def _workspace_dependency_sections(
|
|
535
|
+
updated_crates: cabc.Collection[str],
|
|
536
|
+
) -> dict[str, set[str]]:
|
|
537
|
+
"""Return dependency names to update for the workspace manifest."""
|
|
538
|
+
crate_names = {name for name in updated_crates if name}
|
|
539
|
+
if not crate_names:
|
|
540
|
+
return {}
|
|
541
|
+
return {section: set(crate_names) for section in bump_toml.DEPENDENCY_SECTIONS}
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def _dependency_sections_for_crate(
|
|
545
|
+
crate: WorkspaceCrate,
|
|
546
|
+
updated_crates: cabc.Collection[str],
|
|
547
|
+
) -> dict[str, set[str]]:
|
|
548
|
+
"""Return dependency names grouped by section for ``crate``."""
|
|
549
|
+
if not crate.dependencies:
|
|
550
|
+
return {}
|
|
551
|
+
targets = {name for name in updated_crates if name}
|
|
552
|
+
if not targets:
|
|
553
|
+
return {}
|
|
554
|
+
sections: dict[str, set[str]] = {}
|
|
555
|
+
for dependency in crate.dependencies:
|
|
556
|
+
if dependency.name not in targets:
|
|
557
|
+
continue
|
|
558
|
+
section = _DEPENDENCY_SECTION_BY_KIND.get(dependency.kind, _NORMAL_SECTION)
|
|
559
|
+
# ``manifest_name`` preserves the dependency key used in the manifest.
|
|
560
|
+
# When a crate is aliased (e.g. ``alpha-core = { package = "alpha" }``)
|
|
561
|
+
# the workspace dependency name remains ``alpha`` while the manifest
|
|
562
|
+
# entry becomes ``alpha-core``. Recording the manifest key ensures the
|
|
563
|
+
# corresponding table entry can be located and updated.
|
|
564
|
+
sections.setdefault(section, set()).add(dependency.manifest_name)
|
|
565
|
+
return sections
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
# Re-export internal functions used by tests to maintain backward compatibility
|
|
569
|
+
_parse_manifest = bump_toml.parse_manifest
|
|
570
|
+
_select_table = bump_toml.select_table
|
|
571
|
+
_assign_version = bump_toml.assign_version
|
|
572
|
+
_value_matches = bump_toml.value_matches
|
|
573
|
+
_update_dependency_sections = bump_toml.update_dependency_sections
|
|
574
|
+
_update_dependency_table = bump_toml.update_dependency_table
|