diff --git a/scripts/generate_readme.py b/scripts/generate_readme.py index 4715d897b..c10b8ab67 100644 --- a/scripts/generate_readme.py +++ b/scripts/generate_readme.py @@ -39,6 +39,7 @@ from resolve.review import LARGE_FILE_ISSUE_URL from model.largefiles import LARGE_FILES_CACHE, load_registered_paths import pr_checks from packs.coverage import verify_platform +from core.paths import REPO_ROOT def _installer_words() -> ModuleType: @@ -46,7 +47,7 @@ def _installer_words() -> ModuleType: README named a line menu the one-liner never opens.""" import importlib.util - path = Path(__file__).resolve().parent.parent / "install.py" + path = REPO_ROOT / "install.py" spec = importlib.util.spec_from_file_location("install", path) if spec is None or spec.loader is None: raise ImportError(f"cannot load {path}") @@ -57,7 +58,7 @@ def _installer_words() -> ModuleType: # The repository's profiles wherever the script is run from: a bare # "emulators" read the working directory, and a run elsewhere counted 0 cores. -_EMULATORS_DIR = str(Path(__file__).resolve().parent.parent / "emulators") +_EMULATORS_DIR = str(REPO_ROOT / "emulators") def compute_coverage( @@ -132,7 +133,7 @@ def compute_coverage( } -_REPO = Path(__file__).resolve().parent.parent +_REPO = REPO_ROOT # The site and the README read the same coverage: the first generator to run # stores it here and the second reads it back, instead of verifying every # platform twice (about a minute of the site build). @@ -451,7 +452,7 @@ def format_size(size: int) -> str: SITE_URL = "https://abdess.github.io/retrobios/" # The installer demo (scripts/make_demo.py): the recording and what it shows. -DEMO_DIR = Path(__file__).resolve().parent.parent / "docs_assets" / "demo" +DEMO_DIR = REPO_ROOT / "docs_assets" / "demo" DEMO_GIF = "docs_assets/demo/install.gif" REPO_PATH = "../.." REPO = "Abdess/retrobios" diff --git a/scripts/generate_site.py b/scripts/generate_site.py index 1c3628f63..3548dfd12 100644 --- a/scripts/generate_site.py +++ b/scripts/generate_site.py @@ -169,6 +169,7 @@ from siterender import ( _icon_name, prime_system_icons, ) +from core.paths import REPO_ROOT yaml = require_yaml() @@ -3547,7 +3548,7 @@ PLATFORM_REFERENCE_BUDGET = 600 # gaps-files-to-source-7.md -> gaps.md. When a budget or a list changes, a # part can fold back or the list shrink, and its address then redirects to # that page instead of ending on the 404 page. -PUBLISHED_PARTS_FILE = (Path(__file__).resolve().parent.parent +PUBLISHED_PARTS_FILE = (REPO_ROOT / "website" / "src" / "data" / "published-parts.json") @@ -5010,7 +5011,7 @@ def generate_files_page() -> str: ]) -_REPO_ROOT = Path(__file__).resolve().parent.parent +_REPO_ROOT = REPO_ROOT def data_directory_members(install_dir: Path = _REPO_ROOT / "install") -> dict[str, dict[str, dict]]: @@ -12444,7 +12445,7 @@ def _build_file_consumers(db: dict, coverages: dict, profiles: dict) -> FileCons consumers = FileConsumers(db, build_zip_contents_index(db)) consumers.add_platforms({name: cov["config"] for name, cov in coverages.items()}) consumers.add_emulators(profiles) - consumers.add_manifests(Path(__file__).resolve().parent.parent / "install") + consumers.add_manifests(REPO_ROOT / "install") return consumers diff --git a/scripts/site_insights.py b/scripts/site_insights.py index e772b3941..10ad8e572 100644 --- a/scripts/site_insights.py +++ b/scripts/site_insights.py @@ -47,8 +47,8 @@ from core.github import github_token from model.database import load_database from model.profiles import load_emulator_profiles from core.cli import run_cli +from core.paths import REPO_ROOT -REPO_ROOT = Path(__file__).resolve().parent.parent CONFIG = Path(os.environ.get("RETROBIOS_CONFIG", Path.home() / ".config" / "retrobios")) SITE_PROPERTY = "https://abdess.github.io/retrobios/" GOATCOUNTER = "https://retrobios.goatcounter.com/api/v0" diff --git a/scripts/site_markdown.py b/scripts/site_markdown.py index 3d7508b14..dd5112499 100644 --- a/scripts/site_markdown.py +++ b/scripts/site_markdown.py @@ -40,6 +40,7 @@ from typing import ClassVar sys.path.insert(0, os.path.dirname(__file__)) from core.cli import run_cli +from core.paths import REPO_ROOT SITE = "https://abdess.github.io" BASE = "/retrobios/" @@ -400,7 +401,7 @@ def page_markdown(html: str, page_url: str) -> str: return converter.markdown() -ROOT = Path(__file__).resolve().parent.parent +ROOT = REPO_ROOT def build_stamp() -> dict[str, str]: diff --git a/scripts/sitecollection.py b/scripts/sitecollection.py index f6b3b6e14..c89492976 100644 --- a/scripts/sitecollection.py +++ b/scripts/sitecollection.py @@ -9,11 +9,8 @@ bios folder comes from siteinputs, never the working directory. from __future__ import annotations import functools -import os -import sys from dataclasses import dataclass -sys.path.insert(0, os.path.dirname(__file__)) import siteinputs from model.composition import GAME_DATA_TOPS from model.profiles import load_emulator_profiles diff --git a/scripts/sitediagrams.py b/scripts/sitediagrams.py index c8e52e3bf..d6ce65398 100644 --- a/scripts/sitediagrams.py +++ b/scripts/sitediagrams.py @@ -43,8 +43,9 @@ sys.path.insert(0, str(Path(__file__).resolve().parent)) import siteinputs import sitemarkup as markup +from core.paths import REPO_ROOT -ROOT = Path(__file__).resolve().parent.parent +ROOT = REPO_ROOT PLACEHOLDER = re.compile(r"(?m)^([ \t]*)[ \t]*$") PLACEHOLDER_ANYWHERE = re.compile(r"") diff --git a/scripts/siteguides.py b/scripts/siteguides.py index e9f948543..91c84cb3c 100644 --- a/scripts/siteguides.py +++ b/scripts/siteguides.py @@ -19,8 +19,9 @@ from pathlib import Path import sitemarkup as markup from model.safeparse import require_yaml from sitebootstrap import PS1_NAME, SH_NAME +from core.paths import REPO_ROOT -PLATFORMS_DIR = Path(__file__).resolve().parent.parent / "platforms" +PLATFORMS_DIR = REPO_ROOT / "platforms" GUIDES_FILE = PLATFORMS_DIR / "_guides.yml" diff --git a/scripts/sitehandheld.py b/scripts/sitehandheld.py index bf177d2ae..3789bb30b 100644 --- a/scripts/sitehandheld.py +++ b/scripts/sitehandheld.py @@ -24,8 +24,8 @@ from pathlib import Path import sitemarkup as markup from core.artifacts import write_bytes_atomic from build_port import ARCHIVES, BATOCERA_ZIP, MUOS_APP, PORT_ZIP, TOOLS_ZIP, build_archive +from core.paths import REPO_ROOT -REPO_ROOT = Path(__file__).resolve().parent.parent # Below the site's root: get/handheld/RetroBIOS.zip. SERVED_DIR = "get/handheld" # The page of the systems no registered platform answers for. It shares diff --git a/scripts/siteinputs.py b/scripts/siteinputs.py index 1df5389c3..57563d596 100644 --- a/scripts/siteinputs.py +++ b/scripts/siteinputs.py @@ -11,7 +11,9 @@ from __future__ import annotations from dataclasses import dataclass from pathlib import Path -ROOT = Path(__file__).resolve().parent.parent +from core.paths import REPO_ROOT + +ROOT = REPO_ROOT @dataclass(frozen=True) diff --git a/scripts/sitemeasurements.py b/scripts/sitemeasurements.py index 33bb2c144..93e302d8e 100644 --- a/scripts/sitemeasurements.py +++ b/scripts/sitemeasurements.py @@ -35,8 +35,9 @@ import measurement_records as mr import sitemarkup as markup from core.artifacts import json_text, write_if_changed from siterender import _escape_tags +from core.paths import REPO_ROOT -ROOT = Path(__file__).resolve().parent.parent +ROOT = REPO_ROOT REPO = "https://github.com/Abdess/retrobios" EXPLORER_PAGE = "measurements.md" METHOD_PAGE = "wiki/measurements.md" diff --git a/scripts/siterender.py b/scripts/siterender.py index ffb34ac61..2b7ec36d0 100644 --- a/scripts/siterender.py +++ b/scripts/siterender.py @@ -5,16 +5,16 @@ from __future__ import annotations import re import urllib.parse from collections.abc import Callable -from pathlib import Path import siteinputs import sitemarkup as markup +from core.paths import REPO_ROOT WIKI_SRC_DIR = "wiki" # manually maintained wiki sources SYSTEM_ICON_BASE = "https://raw.githubusercontent.com/libretro/retroarch-assets/master/xmb/systematic/png" # Local copies of the upstream icons, named as upstream names them. -ICON_DIR = Path(__file__).resolve().parent.parent / "docs_assets" / "system-icons" +ICON_DIR = REPO_ROOT / "docs_assets" / "system-icons" # Icon names the site holds a copy of. A name mapped to False has none. _icon_available: dict[str, bool] = {} @@ -793,7 +793,7 @@ def set_console_sections( _sections_installed = [False] -_REPO_ROOT = Path(__file__).resolve().parent.parent +_REPO_ROOT = REPO_ROOT def _ensure_console_sections() -> None: diff --git a/scripts/sitesources.py b/scripts/sitesources.py index 0bb28b43b..1c6a3512d 100644 --- a/scripts/sitesources.py +++ b/scripts/sitesources.py @@ -26,6 +26,7 @@ from model.sourceref import ( source_ref_values, split_source_ref, ) +from core.paths import REPO_ROOT def _repo_pins(profile: dict, field: str, label: str) -> list[tuple[str, str, str]]: @@ -167,8 +168,8 @@ def _source_permalink(repo: upstream.Repo, pin: str, path: str, # writes SOURCE_PATHS. The pages read that file: the deploy has no tree # cache, and a citation it could not check was linked into whichever # repository the profile declared, 30 of them to a 404. -TREE_CACHE = Path(__file__).resolve().parent.parent / upstream.CACHE_DIR -SOURCE_PATHS = (Path(__file__).resolve().parent.parent +TREE_CACHE = REPO_ROOT / upstream.CACHE_DIR +SOURCE_PATHS = (REPO_ROOT / "website" / "src" / "data" / "source-paths.json") diff --git a/scripts/sitestarlight.py b/scripts/sitestarlight.py index 90695ff1b..515e7ae42 100644 --- a/scripts/sitestarlight.py +++ b/scripts/sitestarlight.py @@ -21,6 +21,8 @@ from dataclasses import dataclass, field from html import unescape from pathlib import Path, PurePosixPath +from core.paths import REPO_ROOT + BASE = "/retrobios/" SITE_URL = "https://abdess.github.io/retrobios/" @@ -336,7 +338,7 @@ def og_section(rel: str, level: str) -> str: # Sharing cards of their own, made by scripts/make_og_cards.py: one per # platform page, titled with the platform's name. -OG_DIR = Path(__file__).resolve().parent.parent / "docs_assets" / "og" +OG_DIR = REPO_ROOT / "docs_assets" / "og" # An emulator page's card is that of the maker of the first system it runs,