-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaggregate_dependencies.py
More file actions
50 lines (32 loc) · 1.16 KB
/
aggregate_dependencies.py
File metadata and controls
50 lines (32 loc) · 1.16 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
#!/usr/bin/env python3
from pathlib import Path
import tomli_w
import tomllib
ROOT = Path(__file__).resolve().parent
PROJECTS_DIR = ROOT / "projects"
ROOT_PYPROJECT = ROOT / "pyproject.toml"
def collect_project_dependencies():
deps = set()
for project_dir in PROJECTS_DIR.iterdir():
pyproject_path = project_dir / "pyproject.toml"
if not pyproject_path.exists():
continue
print(f"Collecting dependencies from {pyproject_path}")
with pyproject_path.open("rb") as f:
data = tomllib.load(f)
project_deps = data.get("project", {}).get("dependencies", [])
deps.update(project_deps)
return sorted(deps)
def update_root_pyproject(dependencies):
with ROOT_PYPROJECT.open("rb") as f:
root_data = tomllib.load(f)
root_data.setdefault("project", {})
root_data["project"]["dependencies"] = dependencies
with ROOT_PYPROJECT.open("wb") as f:
tomli_w.dump(root_data, f)
def main():
deps = collect_project_dependencies()
update_root_pyproject(deps)
print(f"Updated root pyproject.toml with {len(deps)} dependencies.")
if __name__ == "__main__":
main()