Coverage for packages/workshop/src/livery/workshop/_tasks.py: 86%

Measured by coverage.py 7.16.2 on CPython 3.14 while the suites of tests, packages/workshop, packages/extensions/ty, packages/extensions/ruff, packages/extensions/python, packages/extensions/pytest, packages/extensions/pyrefly, packages/extensions/nanobind, packages/extensions/mypy, packages/extensions/mkdocstrings, packages/extensions/lfs, packages/extensions/docs, packages/extensions/cpp, packages/extensions/coverage, packages/extensions/conan, packages/extensions/cmake, packages/extensions/claude, packages/extensions/clang-tidy, packages/extensions/clang-format, packages/extensions/changelog, packages/extensions/basedpyright ran.

1"""The base's verbs: what importing the workshop's plugin entry registers first.
2
3The plugin entry ([livery.workshop._mount][]) imports this module, then
4mounts the extensions the contract lists, each through ``plugin()``
5under its own name. Importing this module registers the base's tree
6alone (the quality family, the content sync): mounting the further
7extensions from inside this import would deliver their tasks under the
8base's identity.
9
10Tasks assume the working directory is the workspace root; ``fm`` is
11invoked there.
12"""
13
14from __future__ import annotations
15
16from livery.footman import Invocation, fail, pre_tasks, task
17from livery.workshop import ( # noqa: F401
18 _ci_tasks,
19 _clean,
20 _commit,
21 _devenv,
22 _e2e,
23 _env_tasks,
24 _graph,
25 _issue_tasks,
26 _new_project,
27 _provenance,
28 _quality,
29 _release,
30 _release_driver,
31 _run,
32 _scale,
33 _shell,
34 _speed_tasks,
35 _store_tasks,
36 _submit,
37 _sync,
38 _templates,
39 _tool_tasks,
40 _update,
41 _update_driver,
42 _workflow_tasks,
43)
44
45# Importing registers each module's tasks with footman.
46from livery.workshop import _steps as _steps_module
47
48
49@task
50def extensions() -> None:
51 """Print the workspace's extensions in mount order.
52
53 The lists are the whole of discovery: what shapes this repository
54 is exactly what it prints, and the instance's own files always
55 win last. The extensions a package's set holds come first, each
56 with the packages whose sets hold it, then ``[workspace]
57 extensions``.
58 """
59 from livery.workshop._extensions import (
60 describe_extensions,
61 missing_list,
62 workspace_root,
63 )
64
65 root = workspace_root()
66 if root is None:66 ↛ 67line 66 didn't jump to line 67 because the condition on line 66 was never true
67 print(" no workspace: no workshop.toml above the working directory")
68 return
69 if why := missing_list(root):69 ↛ 70line 69 didn't jump to line 70 because the condition on line 69 was never true
70 fail(why)
71
72 try:
73 lines = describe_extensions()
74 except RuntimeError as error:
75 fail(str(error))
76 for line in lines:
77 print(line)
78 print(" ... then the instance's own files, which always win")
79
80
81@pre_tasks
82def link_task_names(inv: Invocation) -> None:
83 """Link task names to the contract's ``[workspace] docs-url``, when it sets one.
84
85 A configured ``docs-url`` comes first, and an extension that links
86 task names to pages of its own leaves this key's template in place.
87 The contract is read raw, as the mount reads it: the hook runs on
88 every command, ``fm sync`` among them, so a template footman cannot
89 fill is named on stderr and links nothing, and the command goes on.
90 """
91 import tomllib
92
93 from livery.workshop._extensions import _note, _workspace_table, workspace_root
94
95 root = workspace_root()
96 if inv.docs_url is not None or root is None:
97 return
98 try:
99 workspace = _workspace_table(root) or {}
100 except (OSError, tomllib.TOMLDecodeError):
101 return
102 template = workspace.get("docs-url")
103 if not isinstance(template, str):
104 # Absent, or a value the contract's judge refuses by name.
105 return
106 try:
107 inv.docs_url = template
108 except ValueError as error:
109 _note(f"workshop.toml [workspace] docs-url: {error}; no task links")
110
111
112# The phase verbs, generated from the steps registered above: every
113# module that registers a step was imported first.
114_steps_module.generate_verbs()