Files
libretro/scripts/generate_site.py
T
Abdessamad Derraz cf03dcb2ef refactor: share CLI options and default paths
core.paths holds the default database, platforms, emulators and bios paths, core.cli declares the options built on them (add_repo_inputs) and the --emulator/--system modes verify and generate_pack share. model.targets.target_scope answers --target for a command line, model.profiles.no_profile_for_systems the system with no emulator. tests/sources.declared_options reads the options a script declares through either form.
2026-11-20 18:28:46 +01:00

81 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Generate the site from database.json, platform configs, and emulator profiles.
The pages, navigation and data files are written into the Astro Starlight
project in website/, which builds the site.
Reads the same data sources as verify.py and generate_pack.py to produce
a complete documentation site. Zero manual content.
Usage:
python scripts/generate_site.py
python scripts/generate_site.py --db database.json --platforms-dir platforms
"""
from __future__ import annotations
import argparse
import os
import sys
from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from core.cli import add_repo_inputs, require_directory
from core.artifacts import ArtifactLockBusy, artifact_lock
from sitegen.build import generate_site
from sitegen.config import STARLIGHT_CONTENT, STARLIGHT_DIR
from sitegen.parts import PUBLISHED_PARTS_FILE
# Main
def main() -> None:
parser = argparse.ArgumentParser(
allow_abbrev=False,
description="Generate the documentation site from project data"
)
add_repo_inputs(parser, "db", "platforms", "emulators")
parser.add_argument(
"--site-dir", default=STARLIGHT_DIR,
help="the Astro Starlight project the site is written into (default: %(default)s)",
)
parser.add_argument(
"--docs-dir", default=None,
help="directory the pages are written to (default: the project's "
"content collection, src/content/docs)",
)
args = parser.parse_args()
if args.docs_dir is None:
args.docs_dir = str(Path(args.site_dir) / STARLIGHT_CONTENT)
# Before any write: the public assets and the bootstraps went out first,
# and a mistyped folder stopped the run only after them.
require_directory(args.emulators_dir, "--emulators-dir")
require_directory(args.platforms_dir, "--platforms-dir")
try:
# Two runs over one docs/ delete each other's pages and scratch
# files in the sweep, so the second is refused instead.
import contextlib
from model.registry import load_data_dir_registry
from core.artifacts import repository_output_lock
from packs.datadirs import hold_data_dirs
# The coverage pages resolve against data/, held while they are read.
# Whatever --docs-dir says, website/src/data and wiki/ are written.
with artifact_lock(args.docs_dir), \
repository_output_lock(str(PUBLISHED_PARTS_FILE)), \
contextlib.ExitStack() as held:
hold_data_dirs(held, load_data_dir_registry(args.platforms_dir))
generate_site(args)
except ArtifactLockBusy as exc:
print(f"ERROR: {exc}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
from core.cli import run_cli
run_cli(main)