varar-config 0.5.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.
varar_config/__init__.py
ADDED
varar_config/config.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Mapping
|
|
7
|
+
|
|
8
|
+
_KNOWN_KEYS = {"$schema", "docs", "steps", "snippets", "scannerPlugins"}
|
|
9
|
+
_KNOWN_DOCS_KEYS = {"include", "exclude"}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True)
|
|
13
|
+
class VarConfig:
|
|
14
|
+
docs_include: tuple[str, ...] = ()
|
|
15
|
+
docs_exclude: tuple[str, ...] = ()
|
|
16
|
+
steps: tuple[str, ...] = ()
|
|
17
|
+
snippets: Mapping[str, str] = field(default_factory=dict)
|
|
18
|
+
scanner_plugins: tuple[str, ...] = ()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _string_tuple(value: object, key: str, path: Path) -> tuple[str, ...]:
|
|
22
|
+
if value is None:
|
|
23
|
+
return ()
|
|
24
|
+
if not isinstance(value, list) or not all(isinstance(v, str) for v in value):
|
|
25
|
+
raise ValueError(f"{path}: '{key}' must be an array of strings")
|
|
26
|
+
return tuple(value)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def read_varar_config(root: str | Path) -> VarConfig:
|
|
30
|
+
"""Read ``<root>/varar.config.json``.
|
|
31
|
+
|
|
32
|
+
Missing file -> empty config (tools no-op; matches every other port).
|
|
33
|
+
Malformed JSON, wrong types, or unknown keys -> ``ValueError`` starting
|
|
34
|
+
with the file path — a typo'd config must fail loudly, never silently
|
|
35
|
+
discover nothing. See conformance/config/README.md for the shared rules.
|
|
36
|
+
"""
|
|
37
|
+
path = Path(root) / "varar.config.json"
|
|
38
|
+
if not path.is_file():
|
|
39
|
+
return VarConfig()
|
|
40
|
+
try:
|
|
41
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
42
|
+
except json.JSONDecodeError as e:
|
|
43
|
+
raise ValueError(f"{path}: invalid JSON: {e}") from e
|
|
44
|
+
if not isinstance(data, dict):
|
|
45
|
+
raise ValueError(f"{path}: top level must be an object")
|
|
46
|
+
unknown = set(data) - _KNOWN_KEYS
|
|
47
|
+
if unknown:
|
|
48
|
+
raise ValueError(f"{path}: unknown key(s): {', '.join(sorted(unknown))}")
|
|
49
|
+
docs = data.get("docs")
|
|
50
|
+
if docs is None:
|
|
51
|
+
docs = {}
|
|
52
|
+
if not isinstance(docs, dict):
|
|
53
|
+
raise ValueError(f"{path}: 'docs' must be an object")
|
|
54
|
+
unknown_docs = set(docs) - _KNOWN_DOCS_KEYS
|
|
55
|
+
if unknown_docs:
|
|
56
|
+
raise ValueError(f"{path}: unknown docs key(s): {', '.join(sorted(unknown_docs))}")
|
|
57
|
+
snippets = data.get("snippets")
|
|
58
|
+
if snippets is None:
|
|
59
|
+
snippets = {}
|
|
60
|
+
if not isinstance(snippets, dict) or not all(
|
|
61
|
+
isinstance(k, str) and isinstance(v, str) for k, v in snippets.items()
|
|
62
|
+
):
|
|
63
|
+
raise ValueError(f"{path}: 'snippets' must be an object of strings")
|
|
64
|
+
return VarConfig(
|
|
65
|
+
docs_include=_string_tuple(docs.get("include"), "docs.include", path),
|
|
66
|
+
docs_exclude=_string_tuple(docs.get("exclude"), "docs.exclude", path),
|
|
67
|
+
steps=_string_tuple(data.get("steps"), "steps", path),
|
|
68
|
+
snippets=dict(snippets),
|
|
69
|
+
scanner_plugins=_string_tuple(data.get("scannerPlugins"), "scannerPlugins", path),
|
|
70
|
+
)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
varar_config/__init__.py,sha256=jnbdba7_ZAt2uPjtTrUpozQ5OOQ6TfL0inrEClwL5kk,107
|
|
2
|
+
varar_config/config.py,sha256=SYJTeAnCBwJt0RM3-EyiSmeRyDpCpIPRclQew4iJIqA,2729
|
|
3
|
+
varar_config-0.5.0.dist-info/METADATA,sha256=ih1J3HKSJOv2PaFmQXVxPzKfrybmNesRhePKvMQnACc,182
|
|
4
|
+
varar_config-0.5.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
5
|
+
varar_config-0.5.0.dist-info/RECORD,,
|