-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_typos_config.py
More file actions
63 lines (51 loc) · 2.12 KB
/
Copy pathgenerate_typos_config.py
File metadata and controls
63 lines (51 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env -S uv run python
# /// script
# requires-python = ">=3.13"
# dependencies = []
# ///
"""Generate ``typos.toml`` from the shared en-GB-oxendict dictionary.
The shared dictionary is refreshed into an untracked repository-local cache
only when the authoritative copy is newer. A valid cache remains usable when
the network is unavailable, and ``typos.local.toml`` supplies the narrow
repository-specific policy that must not weaken the estate-wide base.
"""
from pathlib import Path
import typos_rollout as rollout
DEFAULT_BASE_URL = (
"https://raw.githubusercontent.com/leynos/agent-helper-scripts/"
"refs/heads/main/data/typos-oxendict-base.toml"
)
REPOSITORY_ROOT = Path(__file__).resolve().parent.parent
def dictionary_from_cache(repository: Path = REPOSITORY_ROOT) -> rollout.Dictionary:
"""Load the cached shared base merged with local repository policy."""
dictionary = rollout.load_dictionary(repository / ".typos-oxendict-base.toml")
local_overlay = repository / "typos.local.toml"
if local_overlay.exists():
dictionary = rollout.merge_dictionaries(
dictionary,
rollout.load_dictionary(local_overlay),
)
return dictionary
def render_config(repository: Path = REPOSITORY_ROOT) -> str:
"""Render deterministic configuration from the populated local cache."""
return rollout.render_typos_config(dictionary_from_cache(repository))
def main(
output: Path | None = None,
*,
repository: Path = REPOSITORY_ROOT,
source: str | Path = DEFAULT_BASE_URL,
offline: bool = False,
) -> rollout.RefreshResult:
"""Refresh the shared base cache and write the merged configuration."""
result = rollout.refresh_base(
source,
repository / ".typos-oxendict-base.toml",
metadata=repository / ".typos-oxendict-base.json",
offline=offline,
)
destination = output if output is not None else repository / "typos.toml"
rollout.write_config(destination, dictionary_from_cache(repository))
return result
if __name__ == "__main__":
refresh = main()
print(f"{refresh.status}: {REPOSITORY_ROOT / 'typos.toml'}")