-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_pyproject.py
More file actions
43 lines (32 loc) · 1.08 KB
/
sync_pyproject.py
File metadata and controls
43 lines (32 loc) · 1.08 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
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "tomlkit>=0.13.3",
# ]
# ///
"""Sync top-level pyproject.toml."""
from pathlib import Path
import tomlkit
def merge() -> None:
"""Merge ctt output into top-level pyproject.toml."""
ctt_subdir = ".ctt/default"
ctt_pyproject = Path(ctt_subdir) / "pyproject.toml"
ctt_doc = tomlkit.parse(ctt_pyproject.read_text())
tl_pyproject = Path("pyproject.toml")
tl_doc = tomlkit.parse(tl_pyproject.read_text(encoding="utf-8"))
synced_keys = {*ctt_doc["tool"].keys()} - {
"pytest-watcher",
"mypy",
"tox",
"commitizen",
"uv",
}
for key in synced_keys:
tl_doc["tool"][key] = ctt_doc["tool"][key]
per_file_ignores = tl_doc["tool"]["ruff"]["lint"]["per-file-ignores"]
for key in ("tests/*.py",):
per_file_ignores[f"package_template/{key}"] = per_file_ignores[key]
per_file_ignores[f"{ctt_subdir}/{key}"] = per_file_ignores[key]
tl_pyproject.write_text(tomlkit.dumps(tl_doc), encoding="utf-8")
if __name__ == "__main__":
merge()