60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""Workspace and repository configuration helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from .model import RepositorySpec
|
|
|
|
|
|
META_ROOT = Path(__file__).resolve().parents[3]
|
|
DEFAULT_WORKSPACE_ROOT = META_ROOT.parent
|
|
REPOSITORIES_FILE = META_ROOT / "repositories.json"
|
|
|
|
|
|
def load_repository_specs(*, include_website: bool = False) -> tuple[RepositorySpec, ...]:
|
|
payload = json.loads(REPOSITORIES_FILE.read_text(encoding="utf-8"))
|
|
repositories = payload.get("repositories")
|
|
if not isinstance(repositories, list):
|
|
raise ValueError(f"{REPOSITORIES_FILE} does not contain a repositories list")
|
|
|
|
specs: list[RepositorySpec] = []
|
|
for item in repositories:
|
|
if not isinstance(item, dict):
|
|
continue
|
|
category = str(item.get("category", ""))
|
|
if category == "website" and not include_website:
|
|
continue
|
|
specs.append(
|
|
RepositorySpec(
|
|
name=str(item["name"]),
|
|
category=category,
|
|
subtype=str(item.get("subtype", "")),
|
|
remote=str(item.get("remote", "")),
|
|
path=str(item["path"]),
|
|
)
|
|
)
|
|
return tuple(specs)
|
|
|
|
|
|
def resolve_workspace_root(value: Path | str | None = None) -> Path:
|
|
if value is None:
|
|
return DEFAULT_WORKSPACE_ROOT
|
|
return Path(value).expanduser().resolve()
|
|
|
|
|
|
def resolve_repo_path(spec: RepositorySpec, workspace_root: Path) -> Path:
|
|
path = Path(spec.path)
|
|
if path.is_absolute():
|
|
return path
|
|
return workspace_root / path
|
|
|
|
|
|
def core_root(workspace_root: Path) -> Path:
|
|
return workspace_root / "govoplan-core"
|
|
|
|
|
|
def website_root(workspace_root: Path) -> Path:
|
|
return workspace_root / "addideas-govoplan-website"
|