index.toml-cli 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.
@@ -0,0 +1,5 @@
1
+ """Command-line entry point for the package index editor."""
2
+
3
+ from .cli import main
4
+
5
+ __all__ = ["main"]
@@ -0,0 +1,10 @@
1
+ """Built-in workspace adapter selection shared by both CLI entry points."""
2
+
3
+ from index_toml_adapter_cargo import CargoWorkspaceAdapter
4
+ from index_toml_adapter_pnpm import PnpmWorkspaceAdapter
5
+ from index_toml_adapter_python import PythonWorkspaceAdapter
6
+
7
+ ADAPTERS = {
8
+ adapter.name: adapter
9
+ for adapter in (PythonWorkspaceAdapter, CargoWorkspaceAdapter, PnpmWorkspaceAdapter)
10
+ }
index_toml_cli/cli.py ADDED
@@ -0,0 +1,90 @@
1
+ """Command line interface for index validation and CRUD."""
2
+
3
+ import argparse
4
+ import json
5
+ from dataclasses import asdict
6
+ from pathlib import Path
7
+
8
+ from filelock import Timeout
9
+ from tomlkit.exceptions import TOMLKitError
10
+
11
+ from index_toml_core import IndexFile
12
+ from index_toml_core.workspace import check_workspace
13
+
14
+ from .adapters import ADAPTERS
15
+
16
+
17
+ def _object(value: str) -> dict:
18
+ try:
19
+ result = json.loads(value)
20
+ except ValueError as error:
21
+ raise argparse.ArgumentTypeError(str(error)) from error
22
+ if not isinstance(result, dict):
23
+ raise argparse.ArgumentTypeError("Expected a JSON object")
24
+ return result
25
+
26
+
27
+ def main(argv: list[str] | None = None) -> int:
28
+ parser = argparse.ArgumentParser(prog="index-toml")
29
+ parser.add_argument("--file", default="pkgs/index.toml")
30
+ commands = parser.add_subparsers(dest="command", required=True)
31
+ commands.add_parser("init")
32
+ commands.add_parser("validate")
33
+ commands.add_parser("show")
34
+ check = commands.add_parser("check", help="compare the index with workspace manifests")
35
+ check.add_argument("--workspace-root", required=True, type=Path)
36
+ check.add_argument("--adapter", required=True, choices=sorted(ADAPTERS))
37
+ check.add_argument("--format", choices=("text", "json"), default="text")
38
+ for kind in ("layer", "package"):
39
+ actions = commands.add_parser(kind).add_subparsers(dest="action", required=True)
40
+ listing = actions.add_parser("list")
41
+ if kind == "package":
42
+ listing.add_argument("--layer")
43
+ for action in ("get", "add", "update", "delete"):
44
+ command = actions.add_parser(action)
45
+ command.add_argument("id")
46
+ if action in ("add", "update"):
47
+ command.add_argument("fields", type=_object, metavar="JSON")
48
+
49
+ options = parser.parse_args(argv)
50
+ index = IndexFile(options.file)
51
+ result = None
52
+ try:
53
+ match options.command:
54
+ case "init":
55
+ index.initialize()
56
+ case "validate":
57
+ index.read()
58
+ result = {"valid": True}
59
+ case "show":
60
+ result = index.read()
61
+ case "check":
62
+ report = check_workspace(index, options.workspace_root, ADAPTERS[options.adapter]())
63
+ if options.format == "json":
64
+ print(json.dumps({
65
+ "adapter": report.adapter, "ecosystem": report.ecosystem,
66
+ "ok": report.ok,
67
+ "differences": [asdict(item) for item in report.differences],
68
+ "diagnostics": [asdict(item) for item in report.diagnostics],
69
+ }, indent=2, ensure_ascii=False))
70
+ elif report.ok:
71
+ print(f"{report.adapter}: workspace matches the index")
72
+ else:
73
+ for item in report.diagnostics:
74
+ print(f"{item.code} {item.manifest}: {item.message}")
75
+ for item in report.differences:
76
+ location = item.manifest or item.actual or item.expected or ""
77
+ print(f"{item.code} {item.package_id or item.identity} ({location}) "
78
+ f"expected={item.expected!r} actual={item.actual!r}")
79
+ return 0 if report.ok else 1
80
+ case kind:
81
+ if options.action == "list":
82
+ result = index.list_layers() if kind == "layer" else index.list_packages(options.layer)
83
+ else:
84
+ method = getattr(index, f"{options.action}_{kind}")
85
+ result = method(options.id, **getattr(options, "fields", {}))
86
+ except (OSError, ValueError, KeyError, TypeError, Timeout, TOMLKitError) as error:
87
+ parser.exit(1, f"index-toml: {error}\n")
88
+ if result is not None:
89
+ print(json.dumps(result, indent=2, ensure_ascii=False))
90
+ return 0
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.3
2
+ Name: index.toml-cli
3
+ Version: 0.1.0
4
+ Summary: Command-line interface for ecosystem-neutral package indexes
5
+ Classifier: Programming Language :: Python :: 3.10
6
+ Classifier: Programming Language :: Python :: 3.11
7
+ Classifier: Programming Language :: Python :: 3.12
8
+ Classifier: Programming Language :: Python :: 3.13
9
+ Classifier: Programming Language :: Python :: 3.14
10
+ Classifier: Programming Language :: Python :: 3.15
11
+ Requires-Dist: filelock>=3.16,<4
12
+ Requires-Dist: index-toml-adapter-cargo>=0.1.0,<0.2
13
+ Requires-Dist: index-toml-adapter-pnpm>=0.1.0,<0.2
14
+ Requires-Dist: index-toml-adapter-python>=0.1.0,<0.2
15
+ Requires-Dist: index-toml-core>=0.1.0,<0.2
16
+ Requires-Dist: tomlkit>=0.13,<1
17
+ Requires-Python: >=3.10, <3.16
18
+ Project-URL: Repository, https://github.com/groupsum/index.toml
@@ -0,0 +1,7 @@
1
+ index_toml_cli/__init__.py,sha256=M1IHcEsh9PvWB7RiXFJmJ4nVoF3h0s9VcWYIN3zG5u4,104
2
+ index_toml_cli/adapters.py,sha256=_nDAW1CWNrnEyUSyCUtlxemRstfT_uGMrsLleZirMGM,385
3
+ index_toml_cli/cli.py,sha256=YG29e7fY84DCLyqE29pSY-jr0aG9lqadpdsUV4sIUJk,3933
4
+ index_toml_cli-0.1.0.dist-info/WHEEL,sha256=3OmCxFA0ffBIsX4x0o8CdfSvZAOvO3mzEG8U_z5TvV4,80
5
+ index_toml_cli-0.1.0.dist-info/entry_points.txt,sha256=MxAKFmAmzcwXr4b3W84ny8m060t2y75BM65bB_CitT8,60
6
+ index_toml_cli-0.1.0.dist-info/METADATA,sha256=JyFyex8p0SnwTCFS2E_icLIfFXiRcZtHpcGKdaWsVQY,793
7
+ index_toml_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.13.8
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ index-toml-cli = index_toml_cli.cli:main
3
+