throughline-compose 0.1.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.
- throughline_compose/__init__.py +15 -0
- throughline_compose/cli.py +173 -0
- throughline_compose/resolve.py +120 -0
- throughline_compose/resolver.py +83 -0
- throughline_compose/sources.py +108 -0
- throughline_compose/union.py +185 -0
- throughline_compose-0.1.0.dist-info/METADATA +147 -0
- throughline_compose-0.1.0.dist-info/RECORD +13 -0
- throughline_compose-0.1.0.dist-info/WHEEL +5 -0
- throughline_compose-0.1.0.dist-info/entry_points.txt +2 -0
- throughline_compose-0.1.0.dist-info/licenses/LICENSE +201 -0
- throughline_compose-0.1.0.dist-info/licenses/NOTICE +12 -0
- throughline_compose-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) 2026 Time Back Solutions Limited
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""throughline-compose — compose one requirements graph from many reusable sources.
|
|
4
|
+
|
|
5
|
+
Builds on ``throughline`` as an unmodified library (SR-0004): it prepares a union
|
|
6
|
+
``Project`` from the declared sources and runs throughline's own ``validate``,
|
|
7
|
+
``Index``, and ``fingerprint`` over it. The ``tl-compose`` CLI is a strict superset
|
|
8
|
+
of ``tl`` (SR-0003) — it forwards local commands to throughline unchanged and
|
|
9
|
+
overrides only the union-aware ones.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
__version__ = "0.0.1"
|
|
14
|
+
|
|
15
|
+
__all__ = ["__version__"]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Copyright (c) 2026 Time Back Solutions Limited
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""The ``tl-compose`` entry point.
|
|
4
|
+
|
|
5
|
+
Design intent (SR-0003): ``tl-compose`` is a strict superset of ``tl``. Every
|
|
6
|
+
local-graph command is forwarded to throughline's CLI unchanged; the union-aware
|
|
7
|
+
command ``check`` is layered on top. When a project declares no ``[[sources]]``,
|
|
8
|
+
``check`` too is a pure pass-through, so ``tl-compose`` over an ordinary project
|
|
9
|
+
behaves exactly like ``tl``.
|
|
10
|
+
|
|
11
|
+
`check` composes the consumer with its declared sources into one union graph
|
|
12
|
+
(union.py), runs the *unchanged* core validator over it (SR-0004), and translates
|
|
13
|
+
findings back into ``<namespace>:<UID>`` vocabulary before printing.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import sys
|
|
18
|
+
from importlib.metadata import PackageNotFoundError, version as _pkg_version
|
|
19
|
+
|
|
20
|
+
from throughline.cli import build_parser, cmd_check, cmd_docs
|
|
21
|
+
from throughline.storage import ProjectError, load_project
|
|
22
|
+
from throughline.validate import ERROR, validate
|
|
23
|
+
|
|
24
|
+
from .resolve import ResolveError, resolve_source
|
|
25
|
+
from .resolver import UnionResolver
|
|
26
|
+
from .sources import SourceError, parse_sources
|
|
27
|
+
from .union import ComposeError, build_union, translate_finding
|
|
28
|
+
|
|
29
|
+
OK, FINDINGS, USAGE = 0, 1, 2
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _err(msg: str) -> int:
|
|
33
|
+
print(f"tl-compose: {msg}", file=sys.stderr)
|
|
34
|
+
return USAGE
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _pkg(name: str) -> str:
|
|
38
|
+
try:
|
|
39
|
+
return _pkg_version(name)
|
|
40
|
+
except PackageNotFoundError: # pragma: no cover - running from a source tree
|
|
41
|
+
return "0.0.0+unknown"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _version_string() -> str:
|
|
45
|
+
# tl-compose is its own front door; report its version and the throughline core
|
|
46
|
+
# it composes over, not throughline's (build_parser wires `--version` to `tl`).
|
|
47
|
+
return f"tl-compose {_pkg('throughline-compose')} (throughline {_pkg('throughline')})"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _load_sources(sources, root) -> dict:
|
|
51
|
+
"""Resolve and load each declared source into a namespace -> Project map.
|
|
52
|
+
Raises :class:`ResolveError` / :class:`ProjectError` for the caller to
|
|
53
|
+
report; a source that will not load is named in the composer's vocabulary."""
|
|
54
|
+
loaded = {}
|
|
55
|
+
for s in sources:
|
|
56
|
+
src_dir = resolve_source(s, root)
|
|
57
|
+
try:
|
|
58
|
+
loaded[s.namespace] = load_project(src_dir)
|
|
59
|
+
except ProjectError as e:
|
|
60
|
+
where = f"{s.url}@{s.ref}" if s.is_remote else s.path
|
|
61
|
+
raise ProjectError(f"source '{s.namespace}' at {where}: {e}") from e
|
|
62
|
+
return loaded
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _compose_check(args) -> int:
|
|
66
|
+
from pathlib import Path
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
consumer = load_project(args.path)
|
|
70
|
+
except ProjectError as e:
|
|
71
|
+
return _err(str(e))
|
|
72
|
+
try:
|
|
73
|
+
sources = parse_sources(consumer)
|
|
74
|
+
except SourceError as e:
|
|
75
|
+
return _err(str(e))
|
|
76
|
+
|
|
77
|
+
# No sources declared: this is a plain throughline project. Defer to the core
|
|
78
|
+
# check verbatim so the superset holds exactly (SR-0003).
|
|
79
|
+
if not sources:
|
|
80
|
+
return cmd_check(args)
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
loaded = _load_sources(sources, Path(args.path))
|
|
84
|
+
except (ResolveError, ProjectError) as e:
|
|
85
|
+
return _err(str(e))
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
union = build_union(consumer, loaded)
|
|
89
|
+
except ComposeError as e:
|
|
90
|
+
return _err(str(e))
|
|
91
|
+
|
|
92
|
+
findings = validate(union.project, strict=args.strict)
|
|
93
|
+
pattern = union.pattern()
|
|
94
|
+
findings = [translate_finding(f, union, pattern) for f in findings]
|
|
95
|
+
|
|
96
|
+
if getattr(args, "format", "text") == "json":
|
|
97
|
+
import json
|
|
98
|
+
print(json.dumps([f.to_dict() for f in findings], indent=2))
|
|
99
|
+
return FINDINGS if any(f.severity == ERROR for f in findings) else OK
|
|
100
|
+
|
|
101
|
+
for f in sorted(findings, key=lambda x: (x.severity != ERROR, x.uid)):
|
|
102
|
+
print(f)
|
|
103
|
+
sys.stdout.flush()
|
|
104
|
+
errs = sum(1 for f in findings if f.severity == ERROR)
|
|
105
|
+
warns = len(findings) - errs
|
|
106
|
+
if not getattr(args, "quiet", False):
|
|
107
|
+
names = ", ".join(
|
|
108
|
+
f"{s.namespace} ({s.url}@{s.ref})" if s.is_remote
|
|
109
|
+
else f"{s.namespace} ({s.path})"
|
|
110
|
+
for s in sources)
|
|
111
|
+
print(f"\ntl-compose check · {len(sources)} source(s) composed: {names}",
|
|
112
|
+
file=sys.stderr)
|
|
113
|
+
tally = f"\n{errs} error(s), {warns} warning(s)"
|
|
114
|
+
if not getattr(args, "quiet", False) and errs == 0:
|
|
115
|
+
tally += " — composed graph is sound" + (" (strict)" if args.strict else "")
|
|
116
|
+
print(tally, file=sys.stderr)
|
|
117
|
+
return FINDINGS if any(f.severity == ERROR for f in findings) else OK
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _compose_docs(args) -> int:
|
|
121
|
+
"""Inject the consumer's documents, resolving tl:matrix target cells over the
|
|
122
|
+
union of the consumer and its declared sources (SR-0110). Injection is over
|
|
123
|
+
the *local* consumer project — counts, tables and rows are byte-identical to
|
|
124
|
+
``tl docs`` — but a namespace-qualified matrix target can render the borrowed
|
|
125
|
+
clause's own reference number. With no sources declared this is a pure
|
|
126
|
+
pass-through to core ``tl docs`` (SR-0003)."""
|
|
127
|
+
from pathlib import Path
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
consumer = load_project(args.path)
|
|
131
|
+
except ProjectError as e:
|
|
132
|
+
return _err(str(e))
|
|
133
|
+
try:
|
|
134
|
+
sources = parse_sources(consumer)
|
|
135
|
+
except SourceError as e:
|
|
136
|
+
return _err(str(e))
|
|
137
|
+
|
|
138
|
+
if not sources:
|
|
139
|
+
return cmd_docs(args)
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
loaded = _load_sources(sources, Path(args.path))
|
|
143
|
+
except (ResolveError, ProjectError) as e:
|
|
144
|
+
return _err(str(e))
|
|
145
|
+
|
|
146
|
+
return cmd_docs(args, resolver=UnionResolver(consumer, loaded))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def main(argv: list[str] | None = None) -> int:
|
|
150
|
+
parser = build_parser()
|
|
151
|
+
parser.prog = "tl-compose"
|
|
152
|
+
for action in parser._actions:
|
|
153
|
+
if "--version" in action.option_strings:
|
|
154
|
+
action.version = _version_string()
|
|
155
|
+
args = parser.parse_args(argv)
|
|
156
|
+
if getattr(args, "cmd", None) == "check":
|
|
157
|
+
try:
|
|
158
|
+
return _compose_check(args)
|
|
159
|
+
except KeyboardInterrupt: # pragma: no cover
|
|
160
|
+
return USAGE
|
|
161
|
+
if getattr(args, "cmd", None) == "docs":
|
|
162
|
+
try:
|
|
163
|
+
return _compose_docs(args)
|
|
164
|
+
except KeyboardInterrupt: # pragma: no cover
|
|
165
|
+
return USAGE
|
|
166
|
+
try:
|
|
167
|
+
return args.func(args)
|
|
168
|
+
except KeyboardInterrupt: # pragma: no cover
|
|
169
|
+
return USAGE
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
if __name__ == "__main__":
|
|
173
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Copyright (c) 2026 Time Back Solutions Limited
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Resolve a declared source to a local directory (SR-0006).
|
|
4
|
+
|
|
5
|
+
A ``path`` source resolves to a directory relative to the consumer project. A
|
|
6
|
+
``url`` + ``ref`` source is fetched from its git origin at the pinned ref into a
|
|
7
|
+
cache that lives *outside* any project tree — a shared, per-user store keyed by
|
|
8
|
+
origin URL and ref, so a consumer's own item scan never ingests a resolved source
|
|
9
|
+
(the reason a resolved source must not live under the project root, per SR-0006).
|
|
10
|
+
|
|
11
|
+
Resolution is idempotent and offline after the first fetch: a source already
|
|
12
|
+
present in the cache at the pinned ref is reused, never refetched.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import hashlib
|
|
17
|
+
import os
|
|
18
|
+
import re
|
|
19
|
+
import shutil
|
|
20
|
+
import subprocess
|
|
21
|
+
import tempfile
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
from .sources import Source
|
|
25
|
+
|
|
26
|
+
_SLUG_RE = re.compile(r"[^A-Za-z0-9._-]+")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ResolveError(Exception):
|
|
30
|
+
"""A source could not be resolved — bad path, or a git fetch that failed."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def cache_root() -> Path:
|
|
34
|
+
"""The per-user source cache, outside any project tree (SR-0006).
|
|
35
|
+
|
|
36
|
+
Honours ``TL_COMPOSE_CACHE`` for tests and CI; otherwise ``XDG_CACHE_HOME`` or
|
|
37
|
+
``~/.cache``.
|
|
38
|
+
"""
|
|
39
|
+
override = os.environ.get("TL_COMPOSE_CACHE")
|
|
40
|
+
if override:
|
|
41
|
+
return Path(override)
|
|
42
|
+
base = os.environ.get("XDG_CACHE_HOME") or str(Path.home() / ".cache")
|
|
43
|
+
return Path(base) / "throughline-compose" / "sources"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _slug(text: str) -> str:
|
|
47
|
+
return _SLUG_RE.sub("-", text).strip("-") or "x"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _cache_dir(url: str, ref: str) -> Path:
|
|
51
|
+
# Key by (url, ref). A short hash guarantees uniqueness; a readable slug of the
|
|
52
|
+
# url's last segment and the ref makes the directory legible on disk.
|
|
53
|
+
digest = hashlib.sha256(url.encode("utf-8")).hexdigest()[:16]
|
|
54
|
+
tail = _slug(url.rstrip("/").rsplit("/", 1)[-1].removesuffix(".git"))
|
|
55
|
+
return cache_root() / f"{tail}-{digest}@{_slug(ref)}"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _git(*args: str, cwd: Path | None = None) -> subprocess.CompletedProcess:
|
|
59
|
+
try:
|
|
60
|
+
return subprocess.run(
|
|
61
|
+
["git", *args],
|
|
62
|
+
cwd=str(cwd) if cwd else None,
|
|
63
|
+
capture_output=True, text=True,
|
|
64
|
+
)
|
|
65
|
+
except FileNotFoundError as e: # pragma: no cover - git absent
|
|
66
|
+
raise ResolveError("git is not installed; it is required to fetch url sources") from e
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _fetch(url: str, ref: str, dest: Path) -> None:
|
|
70
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
71
|
+
tmp = Path(tempfile.mkdtemp(prefix=".fetch-", dir=dest.parent))
|
|
72
|
+
try:
|
|
73
|
+
# --branch accepts a tag or branch name; a bare commit SHA needs a second
|
|
74
|
+
# step, so fall back to a full clone + checkout when the pinned clone fails.
|
|
75
|
+
r = _git("clone", "--depth", "1", "--branch", ref, url, str(tmp))
|
|
76
|
+
if r.returncode != 0:
|
|
77
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
78
|
+
tmp = Path(tempfile.mkdtemp(prefix=".fetch-", dir=dest.parent))
|
|
79
|
+
r = _git("clone", url, str(tmp))
|
|
80
|
+
if r.returncode != 0:
|
|
81
|
+
raise ResolveError(
|
|
82
|
+
f"could not clone {url}: {r.stderr.strip() or 'git clone failed'}")
|
|
83
|
+
co = _git("checkout", ref, cwd=tmp)
|
|
84
|
+
if co.returncode != 0:
|
|
85
|
+
raise ResolveError(
|
|
86
|
+
f"ref '{ref}' not found in {url}: "
|
|
87
|
+
f"{co.stderr.strip() or 'git checkout failed'}")
|
|
88
|
+
# Publish atomically: dest only ever appears fully materialised.
|
|
89
|
+
os.replace(tmp, dest)
|
|
90
|
+
finally:
|
|
91
|
+
if tmp.exists():
|
|
92
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def resolve_source(source: Source, consumer_root: Path) -> Path:
|
|
96
|
+
"""Return the local directory a source composes from.
|
|
97
|
+
|
|
98
|
+
``path`` sources resolve relative to ``consumer_root``; ``url`` sources are
|
|
99
|
+
fetched (once) into the per-user cache.
|
|
100
|
+
"""
|
|
101
|
+
if not source.is_remote:
|
|
102
|
+
assert source.path is not None
|
|
103
|
+
local = (consumer_root / source.path).resolve()
|
|
104
|
+
if not local.is_dir():
|
|
105
|
+
raise ResolveError(
|
|
106
|
+
f"source '{source.namespace}' path does not exist: {local}")
|
|
107
|
+
return local
|
|
108
|
+
|
|
109
|
+
assert source.url is not None and source.ref is not None
|
|
110
|
+
dest = _cache_dir(source.url, source.ref)
|
|
111
|
+
if dest.is_dir() and (dest / "throughline.toml").is_file():
|
|
112
|
+
return dest # already resolved at this pinned ref — idempotent, offline
|
|
113
|
+
if dest.exists(): # partial/corrupt leftover
|
|
114
|
+
shutil.rmtree(dest, ignore_errors=True)
|
|
115
|
+
_fetch(source.url, source.ref, dest)
|
|
116
|
+
if not (dest / "throughline.toml").is_file():
|
|
117
|
+
raise ResolveError(
|
|
118
|
+
f"source '{source.namespace}' at {source.url}@{source.ref} is not a "
|
|
119
|
+
"throughline project (no throughline.toml)")
|
|
120
|
+
return dest
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Copyright (c) 2026 Time Back Solutions Limited
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""A target resolver backed by a consumer's declared sources (SR-0110 seam).
|
|
4
|
+
|
|
5
|
+
``tl-compose docs`` injects over the *local* consumer project, exactly as ``tl
|
|
6
|
+
docs`` does, so counts, tables and matrix rows stay byte-identical. The one seam
|
|
7
|
+
is the target *cell* of a tl:matrix: a consumer clause that links to a borrowed
|
|
8
|
+
standard by a namespace-qualified target (``asvs:SR-0227``) can then render that
|
|
9
|
+
target's own reference number instead of a UID the reader cannot look up.
|
|
10
|
+
|
|
11
|
+
Core injection resolves target liveness and attributes through an optional
|
|
12
|
+
:class:`throughline.inject.TargetResolver` (SR-0110). This resolver overrides it
|
|
13
|
+
so a namespace-qualified target resolves against the loaded source for that
|
|
14
|
+
namespace; an unqualified target falls through to the consumer project, so
|
|
15
|
+
behaviour over local links is identical to the core default.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import re
|
|
20
|
+
|
|
21
|
+
from throughline import is_namespace_qualified
|
|
22
|
+
from throughline.inject import TargetResolver, _render_item
|
|
23
|
+
|
|
24
|
+
_NS_SPLIT = re.compile(r"^([a-z][a-z0-9_-]*):(.+)$")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class UnionResolver(TargetResolver):
|
|
28
|
+
"""Resolve tl:matrix target cells over a consumer plus its sources."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, consumer, sources: dict) -> None:
|
|
31
|
+
super().__init__(consumer)
|
|
32
|
+
self._sources = sources # namespace -> loaded source Project
|
|
33
|
+
|
|
34
|
+
def _delegate(self, uid: str) -> "TargetResolver | None":
|
|
35
|
+
"""A resolver over the source project owning ``uid``, or ``None`` when
|
|
36
|
+
``uid`` is not a namespace-qualified reference to a declared source."""
|
|
37
|
+
if not is_namespace_qualified(uid):
|
|
38
|
+
return None
|
|
39
|
+
m = _NS_SPLIT.match(uid)
|
|
40
|
+
src = self._sources.get(m.group(1))
|
|
41
|
+
return TargetResolver(src) if src is not None else None
|
|
42
|
+
|
|
43
|
+
def present(self, uid: str) -> bool:
|
|
44
|
+
d = self._delegate(uid)
|
|
45
|
+
return d.present(_local(uid)) if d else super().present(uid)
|
|
46
|
+
|
|
47
|
+
def attr(self, uid: str, name: str):
|
|
48
|
+
d = self._delegate(uid)
|
|
49
|
+
return d.attr(_local(uid), name) if d else super().attr(uid, name)
|
|
50
|
+
|
|
51
|
+
def link_display(self, uid: str) -> str:
|
|
52
|
+
"""Enrich a borrowed clause's link display with its own reference number
|
|
53
|
+
(SR-0113): ``asvs:SR-0172`` reads ``asvs:SR-0172 (V7.1.1)`` when the source
|
|
54
|
+
clause carries a ``source_ref``. A local target is the bare UID as before."""
|
|
55
|
+
if not is_namespace_qualified(uid):
|
|
56
|
+
return super().link_display(uid)
|
|
57
|
+
ref = self.attr(uid, "source_ref")
|
|
58
|
+
return f"{uid} ({ref})" if ref else uid
|
|
59
|
+
|
|
60
|
+
def block(self, uid: str) -> str | None:
|
|
61
|
+
"""The borrowed clause's own full block (SR-0114): render the source item a
|
|
62
|
+
namespace-qualified target names, from its source project. Returns ``None``
|
|
63
|
+
for a local target or a source that cannot render it, so ``tl:sourced``
|
|
64
|
+
mirrors only the external clauses a source backs."""
|
|
65
|
+
src = self._source_for(uid)
|
|
66
|
+
if src is None:
|
|
67
|
+
return None
|
|
68
|
+
local = _local(uid)
|
|
69
|
+
if src.get(local) is None:
|
|
70
|
+
return None
|
|
71
|
+
return _render_item(src, local, TargetResolver(src))
|
|
72
|
+
|
|
73
|
+
def _source_for(self, uid: str):
|
|
74
|
+
"""The loaded source project owning a namespace-qualified ``uid``, or None."""
|
|
75
|
+
if not is_namespace_qualified(uid):
|
|
76
|
+
return None
|
|
77
|
+
return self._sources.get(_NS_SPLIT.match(uid).group(1))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _local(uid: str) -> str:
|
|
81
|
+
"""The source-local UID of a namespace-qualified reference (``asvs:SR-0227``
|
|
82
|
+
→ ``SR-0227``)."""
|
|
83
|
+
return _NS_SPLIT.match(uid).group(2)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Copyright (c) 2026 Time Back Solutions Limited
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Declared external sources (SR-0001, SR-0002, SR-0006).
|
|
4
|
+
|
|
5
|
+
A consuming project names the throughline sources it composes in an array of
|
|
6
|
+
``[[sources]]`` tables in its ``throughline.toml``. Each entry binds an
|
|
7
|
+
importer-chosen *namespace* (SR-0001) to a standalone throughline source whose UIDs
|
|
8
|
+
are its own (SR-0002). Clauses are then referenced from the consumer as
|
|
9
|
+
``<namespace>:<UID>``.
|
|
10
|
+
|
|
11
|
+
A source is located one of two ways (SR-0006):
|
|
12
|
+
|
|
13
|
+
- ``url`` + ``ref`` — a git origin pinned to an edition (normally a tag). The
|
|
14
|
+
durable, shareable form; resolved into a per-user cache by ``resolve.py``.
|
|
15
|
+
- ``path`` — a local directory, for developing a source and its consumer side by
|
|
16
|
+
side.
|
|
17
|
+
|
|
18
|
+
The two are mutually exclusive; a ``url`` without a ``ref`` is rejected so a
|
|
19
|
+
dependency can never silently track a moving default. This module is pure config
|
|
20
|
+
parsing — it does not fetch or load anything.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import re
|
|
25
|
+
from dataclasses import dataclass
|
|
26
|
+
|
|
27
|
+
# The namespace grammar mirrors the core's namespace-qualified reference token
|
|
28
|
+
# (throughline SR-0107): a lowercase name a reference can carry before the colon.
|
|
29
|
+
_NAMESPACE_RE = re.compile(r"^[a-z][a-z0-9_-]*$")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SourceError(ValueError):
|
|
33
|
+
"""A malformed or ambiguous ``[[sources]]`` declaration — fail fast (SR-0005)."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class Source:
|
|
38
|
+
namespace: str
|
|
39
|
+
path: str | None = None
|
|
40
|
+
url: str | None = None
|
|
41
|
+
ref: str | None = None
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def is_remote(self) -> bool:
|
|
45
|
+
return self.url is not None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_sources(project) -> list[Source]:
|
|
49
|
+
"""Read the ``[[sources]]`` array from a loaded consumer project's config.
|
|
50
|
+
|
|
51
|
+
Returns an empty list when none are declared — a project with no sources is
|
|
52
|
+
an ordinary throughline project and ``tl-compose`` behaves exactly like ``tl``
|
|
53
|
+
over it (SR-0003).
|
|
54
|
+
"""
|
|
55
|
+
raw = project.config.get("sources", [])
|
|
56
|
+
if not isinstance(raw, list):
|
|
57
|
+
raise SourceError("[[sources]] must be an array of tables")
|
|
58
|
+
out: list[Source] = []
|
|
59
|
+
seen: set[str] = set()
|
|
60
|
+
for i, entry in enumerate(raw):
|
|
61
|
+
if not isinstance(entry, dict):
|
|
62
|
+
raise SourceError(f"[[sources]] entry {i} is not a table")
|
|
63
|
+
|
|
64
|
+
ns = entry.get("namespace")
|
|
65
|
+
if not ns or not isinstance(ns, str):
|
|
66
|
+
raise SourceError(f"[[sources]] entry {i} is missing a 'namespace'")
|
|
67
|
+
if not _NAMESPACE_RE.match(ns):
|
|
68
|
+
raise SourceError(
|
|
69
|
+
f"namespace '{ns}' is not a valid namespace name "
|
|
70
|
+
"(lowercase letter, then letters/digits/-/_)")
|
|
71
|
+
if ns in seen:
|
|
72
|
+
raise SourceError(
|
|
73
|
+
f"namespace '{ns}' is declared twice — a namespace binds one source")
|
|
74
|
+
|
|
75
|
+
path = entry.get("path")
|
|
76
|
+
url = entry.get("url")
|
|
77
|
+
ref = entry.get("ref")
|
|
78
|
+
|
|
79
|
+
has_path = bool(path)
|
|
80
|
+
has_url = bool(url)
|
|
81
|
+
if has_path and has_url:
|
|
82
|
+
raise SourceError(
|
|
83
|
+
f"source '{ns}' declares both 'path' and 'url' — they are mutually "
|
|
84
|
+
"exclusive (SR-0006)")
|
|
85
|
+
if not has_path and not has_url:
|
|
86
|
+
raise SourceError(
|
|
87
|
+
f"source '{ns}' must declare either a 'path' or a 'url'")
|
|
88
|
+
|
|
89
|
+
if has_path:
|
|
90
|
+
if not isinstance(path, str):
|
|
91
|
+
raise SourceError(f"source '{ns}' has a non-string 'path'")
|
|
92
|
+
if ref:
|
|
93
|
+
raise SourceError(
|
|
94
|
+
f"source '{ns}' declares a 'ref' with a local 'path' — a ref "
|
|
95
|
+
"only pins a 'url' (SR-0006)")
|
|
96
|
+
src = Source(namespace=ns, path=path)
|
|
97
|
+
else:
|
|
98
|
+
if not isinstance(url, str):
|
|
99
|
+
raise SourceError(f"source '{ns}' has a non-string 'url'")
|
|
100
|
+
if not ref or not isinstance(ref, str):
|
|
101
|
+
raise SourceError(
|
|
102
|
+
f"source '{ns}' has a 'url' but no 'ref' — pin the edition with "
|
|
103
|
+
"a git tag, branch, or commit (SR-0006)")
|
|
104
|
+
src = Source(namespace=ns, url=url, ref=ref)
|
|
105
|
+
|
|
106
|
+
seen.add(ns)
|
|
107
|
+
out.append(src)
|
|
108
|
+
return out
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Copyright (c) 2026 Time Back Solutions Limited
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Build one throughline graph from a consumer plus its declared sources (SR-0004).
|
|
4
|
+
|
|
5
|
+
The core throughline validator is reused *unchanged* (SR-0004): rather than teach
|
|
6
|
+
`tl` about namespaces, `tl-compose` folds every source's items into a single union
|
|
7
|
+
:class:`~throughline.model.Project` and runs the ordinary `validate` over it. The
|
|
8
|
+
one trick is identity. A source's UIDs are its own (SR-0002), so two sources — or a
|
|
9
|
+
source and the consumer — may both hold ``SR-0001``. Before merging, each borrowed
|
|
10
|
+
UID is *mangled* to a synthetic prefix derived from its namespace (``gds:SR-0001``
|
|
11
|
+
→ ``GDSSR-0001``), so the union has globally-unique, grammar-valid UIDs. Every
|
|
12
|
+
namespace-qualified reference (SR-0001) and every source-internal reference is
|
|
13
|
+
rewritten to the mangled form, so the graph resolves with no colons left.
|
|
14
|
+
|
|
15
|
+
Findings from the core are then translated back: mangled UIDs in a finding's target
|
|
16
|
+
and message become their original ``<namespace>:<UID>`` form, so the composer reads
|
|
17
|
+
diagnostics in the vocabulary they wrote.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import re
|
|
22
|
+
from dataclasses import dataclass, replace
|
|
23
|
+
|
|
24
|
+
from throughline import is_external, is_namespace_qualified
|
|
25
|
+
from throughline.model import Item, Project, Register
|
|
26
|
+
from throughline.uid import UID_RE, parse_uid
|
|
27
|
+
|
|
28
|
+
# The prefix a mangled UID may occupy: core UID grammar (throughline SR-0001).
|
|
29
|
+
_PREFIX_RE = re.compile(r"^[A-Z][A-Z0-9]{1,15}$")
|
|
30
|
+
# Split a namespace-qualified reference into (namespace, uid).
|
|
31
|
+
_NS_REF_RE = re.compile(r"^([a-z][a-z0-9_-]*):(.+)$")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ComposeError(Exception):
|
|
35
|
+
"""Composition cannot proceed — an unbound namespace, a UID that will not
|
|
36
|
+
mangle to a legal prefix, or a synthetic-prefix clash. Fail fast (SR-0005)."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class Union:
|
|
41
|
+
project: Project # merged graph, governed by consumer schema
|
|
42
|
+
owners: dict[str, tuple[str, str]] # synthetic prefix -> (namespace, source prefix)
|
|
43
|
+
|
|
44
|
+
def qualified(self, uid: str) -> str:
|
|
45
|
+
"""Reconstruct the original ``<namespace>:<UID>`` for any union UID whose
|
|
46
|
+
prefix is a mangled one — including a reference to a source clause that
|
|
47
|
+
does *not* exist, so a dangling cross-source link reads in the composer's
|
|
48
|
+
own vocabulary. A consumer-local UID is returned unchanged."""
|
|
49
|
+
m = UID_RE.match(uid)
|
|
50
|
+
if m and m.group(1) in self.owners:
|
|
51
|
+
namespace, src_prefix = self.owners[m.group(1)]
|
|
52
|
+
return f"{namespace}:{src_prefix}-{m.group(2)}"
|
|
53
|
+
return uid
|
|
54
|
+
|
|
55
|
+
def pattern(self) -> re.Pattern | None:
|
|
56
|
+
"""A regex matching any mangled UID token, for message translation."""
|
|
57
|
+
if not self.owners:
|
|
58
|
+
return None
|
|
59
|
+
prefixes = "|".join(re.escape(p) for p in
|
|
60
|
+
sorted(self.owners, key=len, reverse=True))
|
|
61
|
+
return re.compile(rf"(?:{prefixes})-[0-9]+")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _sanitize_ns(namespace: str) -> str:
|
|
65
|
+
"""The uppercase, alphanumeric-only stem a namespace contributes to a mangled
|
|
66
|
+
prefix. A namespace starts with a lowercase letter (sources.py), so the stem
|
|
67
|
+
always starts with a letter and is a legal prefix head."""
|
|
68
|
+
return re.sub(r"[^A-Z0-9]", "", namespace.upper())
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class _Mangler:
|
|
72
|
+
"""Deterministic, collision-checked mapping from ``(namespace, source UID)`` to
|
|
73
|
+
a unique, grammar-valid union UID. Only the prefix changes; the number is
|
|
74
|
+
preserved verbatim so the width and value survive."""
|
|
75
|
+
|
|
76
|
+
def __init__(self) -> None:
|
|
77
|
+
# synthetic prefix -> (namespace, source prefix) that owns it, to catch two
|
|
78
|
+
# distinct (namespace, prefix) pairs colliding on one synthetic prefix.
|
|
79
|
+
self.owners: dict[str, tuple[str, str]] = {}
|
|
80
|
+
|
|
81
|
+
def prefix(self, namespace: str, src_prefix: str) -> str:
|
|
82
|
+
syn = _sanitize_ns(namespace) + src_prefix
|
|
83
|
+
if not _PREFIX_RE.match(syn):
|
|
84
|
+
raise ComposeError(
|
|
85
|
+
f"namespace '{namespace}' + prefix '{src_prefix}' mangles to "
|
|
86
|
+
f"'{syn}', which is not a legal UID prefix (max 16 chars) — "
|
|
87
|
+
"import the source under a shorter namespace")
|
|
88
|
+
owner = self.owners.setdefault(syn, (namespace, src_prefix))
|
|
89
|
+
if owner != (namespace, src_prefix):
|
|
90
|
+
raise ComposeError(
|
|
91
|
+
f"namespaces '{owner[0]}' and '{namespace}' both mangle prefix "
|
|
92
|
+
f"'{src_prefix}' to '{syn}' — import one under a distinct namespace")
|
|
93
|
+
return syn
|
|
94
|
+
|
|
95
|
+
def uid(self, namespace: str, uid: str) -> str:
|
|
96
|
+
m = UID_RE.match(uid)
|
|
97
|
+
if not m:
|
|
98
|
+
return uid # malformed target — leave for the core to flag as dangling
|
|
99
|
+
pfx, num = m.group(1), m.group(2)
|
|
100
|
+
return f"{self.prefix(namespace, pfx)}-{num}"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _rewrite_target(target: str, current_ns: str | None,
|
|
104
|
+
namespaces: set[str], mangler: _Mangler) -> str:
|
|
105
|
+
"""Map one link target into union space.
|
|
106
|
+
|
|
107
|
+
- External pointers (URLs, paths, anchors — SR-0031) stay opaque.
|
|
108
|
+
- A namespace-qualified ``ns:UID`` resolves to that namespace's mangled UID;
|
|
109
|
+
an undeclared namespace is a fail-fast :class:`ComposeError`.
|
|
110
|
+
- A bare UID inside a *source* item is a source-internal reference and mangles
|
|
111
|
+
into that source's namespace; inside the *consumer* it is a local UID and is
|
|
112
|
+
left untouched.
|
|
113
|
+
"""
|
|
114
|
+
if is_external(target):
|
|
115
|
+
return target
|
|
116
|
+
if is_namespace_qualified(target):
|
|
117
|
+
m = _NS_REF_RE.match(target)
|
|
118
|
+
ns, uid = m.group(1), m.group(2)
|
|
119
|
+
if ns not in namespaces:
|
|
120
|
+
raise ComposeError(
|
|
121
|
+
f"reference '{target}' names namespace '{ns}', which is not a "
|
|
122
|
+
"declared [[sources]] namespace")
|
|
123
|
+
return mangler.uid(ns, uid)
|
|
124
|
+
if current_ns is not None:
|
|
125
|
+
return mangler.uid(current_ns, target)
|
|
126
|
+
return target
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _rewrite_links(item: Item, current_ns: str | None,
|
|
130
|
+
namespaces: set[str], mangler: _Mangler) -> Item:
|
|
131
|
+
new_links = [replace(link, target=_rewrite_target(
|
|
132
|
+
link.target, current_ns, namespaces, mangler)) for link in item.links]
|
|
133
|
+
return replace(item, links=new_links)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def build_union(consumer: Project, sources: dict[str, Project]) -> Union:
|
|
137
|
+
"""Fold ``sources`` (namespace -> loaded source project) into ``consumer`` and
|
|
138
|
+
return the merged :class:`Union`. The union is governed by the *consumer's*
|
|
139
|
+
schema — the consumer decides which types, links and statuses are legal for
|
|
140
|
+
the composed graph."""
|
|
141
|
+
namespaces = set(sources)
|
|
142
|
+
mangler = _Mangler()
|
|
143
|
+
|
|
144
|
+
union = Project(path=consumer.path, config=consumer.config)
|
|
145
|
+
|
|
146
|
+
# Consumer items keep their own UIDs; only their ns-qualified references are
|
|
147
|
+
# rewritten. Copy registers so the loaded consumer objects stay untouched.
|
|
148
|
+
for prefix, reg in consumer.registers.items():
|
|
149
|
+
items = {uid: _rewrite_links(it, None, namespaces, mangler)
|
|
150
|
+
for uid, it in reg.items.items()}
|
|
151
|
+
union.registers[prefix] = replace(reg, items=items)
|
|
152
|
+
|
|
153
|
+
# Each source's items are mangled into namespace-derived prefixes and merged.
|
|
154
|
+
for namespace, source in sources.items():
|
|
155
|
+
for reg in source.registers.values():
|
|
156
|
+
for uid, it in reg.items.items():
|
|
157
|
+
mangled_uid = mangler.uid(namespace, uid)
|
|
158
|
+
mangled_prefix = parse_uid(mangled_uid)[0]
|
|
159
|
+
rewritten = _rewrite_links(it, namespace, namespaces, mangler)
|
|
160
|
+
merged = replace(rewritten, uid=mangled_uid,
|
|
161
|
+
_register_prefix=mangled_prefix)
|
|
162
|
+
target = union.registers.get(mangled_prefix)
|
|
163
|
+
if target is None:
|
|
164
|
+
if mangled_prefix in consumer.registers:
|
|
165
|
+
raise ComposeError(
|
|
166
|
+
f"source '{namespace}' mangles to prefix "
|
|
167
|
+
f"'{mangled_prefix}', which the consumer already uses — "
|
|
168
|
+
"import the source under a distinct namespace")
|
|
169
|
+
target = Register(prefix=mangled_prefix,
|
|
170
|
+
title=f"{namespace}:{reg.prefix}")
|
|
171
|
+
union.registers[mangled_prefix] = target
|
|
172
|
+
target.items[mangled_uid] = merged
|
|
173
|
+
|
|
174
|
+
return Union(project=union, owners=mangler.owners)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def translate_finding(finding, union: Union, pattern: re.Pattern | None):
|
|
178
|
+
"""Rewrite a core :class:`~throughline.validate.Finding` back into namespace
|
|
179
|
+
vocabulary: its ``uid`` and any mangled UID token in its ``message`` become the
|
|
180
|
+
original ``<namespace>:<UID>``. Returns a shallow copy; the original is
|
|
181
|
+
untouched."""
|
|
182
|
+
message = finding.message
|
|
183
|
+
if pattern is not None:
|
|
184
|
+
message = pattern.sub(lambda m: union.qualified(m.group(0)), message)
|
|
185
|
+
return replace(finding, uid=union.qualified(finding.uid), message=message)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: throughline-compose
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Compose one requirements graph from many reusable throughline sources: importer-assigned namespaces, source-native UIDs, and a union checked by throughline's own validator. Ships the tl-compose CLI, a strict superset of tl.
|
|
5
|
+
Author: Time Back Solutions Limited
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/rhodium-org/throughline-compose
|
|
8
|
+
Project-URL: Repository, https://github.com/rhodium-org/throughline-compose
|
|
9
|
+
Project-URL: Issues, https://github.com/rhodium-org/throughline-compose/issues
|
|
10
|
+
Keywords: requirements,requirements-management,traceability,composition,git-native,idd,intent-driven-development,throughline
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: throughline>=0.5.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# throughline-compose
|
|
30
|
+
|
|
31
|
+
**Compose one requirements graph from many reusable
|
|
32
|
+
[throughline](https://github.com/rhodium-org/throughline) sources** — a house style
|
|
33
|
+
guide, a platform standard, a regulatory baseline — alongside the requirements you
|
|
34
|
+
write yourself, and work the combined graph as one.
|
|
35
|
+
|
|
36
|
+
This repository is itself a throughline project: its own design is captured as a
|
|
37
|
+
grounded IDD spine of
|
|
38
|
+
<!-- tl:count type == 'user_requirement' -->
|
|
39
|
+
3
|
|
40
|
+
<!-- tl:end --> user requirements and
|
|
41
|
+
<!-- tl:count type == 'system_requirement' -->
|
|
42
|
+
7
|
|
43
|
+
<!-- tl:end --> system requirements under [`vision/`](vision), [`goals/`](goals),
|
|
44
|
+
[`user-requirements/`](user-requirements),
|
|
45
|
+
[`system-requirements/`](system-requirements), and [`non-goals/`](non-goals), and
|
|
46
|
+
published to [`docs/spec.md`](docs/spec.md). The graph is gated by `tl-compose check
|
|
47
|
+
--strict` and the document by `tl-compose docs --check`; these two counts are
|
|
48
|
+
rendered from the live spine by the `tl:count` directive, so they cannot drift.
|
|
49
|
+
|
|
50
|
+
> **Status: alpha.** The composition engine is built. `tl-compose check` composes the
|
|
51
|
+
> declared `[[sources]]` into a union graph and validates it, and `tl-compose docs`
|
|
52
|
+
> renders the published document over that same union, resolving borrowed
|
|
53
|
+
> (`namespace:UID`) targets ([SR-0007](system-requirements/SR-0007.yml)). Each source
|
|
54
|
+
> resolves from either a local `path` or a pinned git `url` + `ref` into a per-user
|
|
55
|
+
> cache ([SR-0006](system-requirements/SR-0006.yml)). Still pending: the
|
|
56
|
+
> `tl-compose source add/update/pin` subcommands for managing source declarations from
|
|
57
|
+
> the CLI (today you edit the `[[sources]]` tables by hand).
|
|
58
|
+
|
|
59
|
+
## The idea
|
|
60
|
+
|
|
61
|
+
A team should be able to adopt standard requirement sets *by reference*, not by
|
|
62
|
+
copy-paste, and receive upstream revisions without ever forking. Two identity rules
|
|
63
|
+
make that safe:
|
|
64
|
+
|
|
65
|
+
- **Imported items keep their source-native UID** ([SR-0002](system-requirements/SR-0002.yml)).
|
|
66
|
+
Composition never renumbers or copies. Canonical identity is the pair
|
|
67
|
+
`(source-namespace, UID)`, so the same `SR-0001` may legitimately exist in two
|
|
68
|
+
sources without collision — the immutable-UID rule is never violated.
|
|
69
|
+
- **The composer controls the namespaces** ([SR-0001](system-requirements/SR-0001.yml)).
|
|
70
|
+
The consumer's own `throughline.toml` binds each source to a short name it chooses
|
|
71
|
+
(`import X as Y`). A qualified reference like `gds:SR-0001` denotes a borrowed item;
|
|
72
|
+
a bare UID is always local. Renaming a namespace is a local-only change with a
|
|
73
|
+
bounded blast radius.
|
|
74
|
+
|
|
75
|
+
## Declaring sources
|
|
76
|
+
|
|
77
|
+
A consumer names the sources it composes in an array of `[[sources]]` tables in its
|
|
78
|
+
own `throughline.toml`. Each entry binds a `namespace` to one source, located either
|
|
79
|
+
by a pinned git `url` or by a local `path` ([SR-0006](system-requirements/SR-0006.yml)):
|
|
80
|
+
|
|
81
|
+
```toml
|
|
82
|
+
# Adopt a published standard by reference, pinned to an edition.
|
|
83
|
+
[[sources]]
|
|
84
|
+
namespace = "asvs"
|
|
85
|
+
url = "https://github.com/rhodium-org/standard-asvs"
|
|
86
|
+
ref = "v4.0.3" # a git tag (normal form), branch, or commit SHA
|
|
87
|
+
|
|
88
|
+
# Develop a source and its consumer side by side.
|
|
89
|
+
[[sources]]
|
|
90
|
+
namespace = "house-style"
|
|
91
|
+
path = "../house-style" # a directory relative to this project
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- **`url` + `ref` is the durable, shareable form.** The `ref` pins the exact edition
|
|
95
|
+
— normally a release tag, but any git ref (branch or commit SHA) works. `tl-compose`
|
|
96
|
+
fetches the source from its origin on first use into a per-user cache that lives
|
|
97
|
+
*outside* any project tree (`$TL_COMPOSE_CACHE`, else `$XDG_CACHE_HOME`, else
|
|
98
|
+
`~/.cache/throughline-compose/sources/`), keyed by `(url, ref)`. Resolution is
|
|
99
|
+
idempotent and offline thereafter: a source already cached at the pinned ref is
|
|
100
|
+
reused, never refetched. Nothing is vendored into your repo, so your own item scan
|
|
101
|
+
never ingests a borrowed graph.
|
|
102
|
+
- **`path` is for local development.** A directory, relative to the consumer, for
|
|
103
|
+
working on a source alongside the project that consumes it.
|
|
104
|
+
- **The two are mutually exclusive, and a `url` must carry a `ref`.** Declaring both
|
|
105
|
+
`path` and `url`, or a `url` with no `ref`, is rejected at check time — a dependency
|
|
106
|
+
can never silently track a moving default. (A `ref` alongside a `path` is likewise
|
|
107
|
+
rejected: a ref only pins a `url`.)
|
|
108
|
+
|
|
109
|
+
Moving to a new upstream edition is a one-line change to the `ref`; the borrowed graph
|
|
110
|
+
is never edited. See [`rhodium-org/idd-example`](https://github.com/rhodium-org/idd-example)
|
|
111
|
+
for a complete worked consumer that adopts `standard-asvs` this way.
|
|
112
|
+
|
|
113
|
+
## One tool, one set of guarantees
|
|
114
|
+
|
|
115
|
+
In a composed project you drive everything through **`tl-compose`**, never `tl`
|
|
116
|
+
directly ([UR-0002](user-requirements/UR-0002.yml)). The architecture keeps that
|
|
117
|
+
honest:
|
|
118
|
+
|
|
119
|
+
- **`tl-compose` is a strict superset of `tl`** ([SR-0003](system-requirements/SR-0003.yml)).
|
|
120
|
+
Local-graph commands are forwarded to the throughline library unchanged; the
|
|
121
|
+
union-aware `check` and `docs` are overridden to compose, validate, and render the
|
|
122
|
+
combined graph. (The `source` subcommands for editing declarations are the remaining
|
|
123
|
+
superset surface — see the status note above.) The core command set is obtained
|
|
124
|
+
programmatically, so the two surfaces cannot drift apart.
|
|
125
|
+
- **Composition reuses throughline unchanged** ([SR-0004](system-requirements/SR-0004.yml)).
|
|
126
|
+
It merges the sources into one in-memory `Project` and runs throughline's existing
|
|
127
|
+
`validate`, `Index`, and `fingerprint` over that union — no second validation
|
|
128
|
+
engine. A composed graph is exactly as sound as a native one.
|
|
129
|
+
- **Bare `tl check` fails fast on unresolved cross-source refs**
|
|
130
|
+
([SR-0005](system-requirements/SR-0005.yml)). If you run core `tl` in a composed
|
|
131
|
+
repo by habit, a namespace-qualified reference it cannot resolve makes it stop and
|
|
132
|
+
point you at `tl-compose` — never a false clean result. Free external references (a
|
|
133
|
+
URL, a linked standard) stay opaque, as intended.
|
|
134
|
+
|
|
135
|
+
Composition deliberately lives here, not in the throughline core
|
|
136
|
+
([NG-0001](non-goals/NG-0001.yml)) — the core stays a single-purpose, offline tool
|
|
137
|
+
over one graph, consumed here as a library.
|
|
138
|
+
|
|
139
|
+
## Working here
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
pip install . # pulls throughline transitively; installs tl and tl-compose
|
|
143
|
+
tl-compose context # agent brief, generated from throughline.toml
|
|
144
|
+
tl-compose check --strict # gate the whole graph
|
|
145
|
+
tl-compose docs --check # gate published-document freshness
|
|
146
|
+
tl-compose docs # regenerate docs/spec.md from the graph
|
|
147
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
throughline_compose/__init__.py,sha256=EenkGGkr26g91lfe1elyNVwvCd20hMEUHGdBXfbRSmk,625
|
|
2
|
+
throughline_compose/cli.py,sha256=1UCOgGUlxBCrHZkB9_ZqHucjeMXRnEpTNjxihWZ5gUQ,6173
|
|
3
|
+
throughline_compose/resolve.py,sha256=R3qbd17bsu9zcY4wEPIcICNDnAriZwOjh4e6p_VQFQQ,4757
|
|
4
|
+
throughline_compose/resolver.py,sha256=zO6WuACWouZabj2EYMR5eNxP5IXWleexFLxhLzRuFic,3640
|
|
5
|
+
throughline_compose/sources.py,sha256=hU5v-_ItlFH-F9FsrjF3LcMi-dB4WkBl-Io8ZEFBspM,4153
|
|
6
|
+
throughline_compose/union.py,sha256=MSnYuOIstEfzSr29LITDeGknNU764HZt5hd-8AOJpHI,8851
|
|
7
|
+
throughline_compose-0.1.0.dist-info/licenses/LICENSE,sha256=_Zc5I-iUut1YEYW8UD2_NaMhBTPmCNfyXQG2113H-6M,11357
|
|
8
|
+
throughline_compose-0.1.0.dist-info/licenses/NOTICE,sha256=I4wJH0vg9C_6HTaTAhoCodnPw7Wc_MhfdCZC4q6JWU8,523
|
|
9
|
+
throughline_compose-0.1.0.dist-info/METADATA,sha256=gTXCx8VnX_HjXHs5ftPuBCmbmL2TnRU4aG5UEv7RHRs,7847
|
|
10
|
+
throughline_compose-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
11
|
+
throughline_compose-0.1.0.dist-info/entry_points.txt,sha256=xMJpVHrQH9ExiL1Zx1kA5pqEKDCRpZUoyZwlAUIdX4Y,60
|
|
12
|
+
throughline_compose-0.1.0.dist-info/top_level.txt,sha256=4ehGfSKMF-MJ3Mn3Gy0ATp8jBfCqd9nBqnEpCr7fMbs,20
|
|
13
|
+
throughline_compose-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Time Back Solutions Limited
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
throughline-compose
|
|
2
|
+
Copyright 2026 Time Back Solutions Limited
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Time Back Solutions Limited.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0. See the LICENSE file for the
|
|
7
|
+
full terms.
|
|
8
|
+
|
|
9
|
+
throughline-compose builds on throughline (https://pypi.org/project/throughline/),
|
|
10
|
+
which it consumes as an unmodified library. It adds source composition — namespace
|
|
11
|
+
declaration, pinning, fetching, and union merging — over that library and reuses
|
|
12
|
+
throughline's validator without forking it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
throughline_compose
|