mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 06:18:51 -06:00
docs: cite the site modules at their paths
Comments in the workflow, the bootstraps, the installer, the site sources and the tests still named scripts/sitebootstrap.py and the other site modules sitegen/ took over. test_cited_scripts checks that every scripts/ path or -m module a tracked text names exists.
This commit is contained in:
1 parent
e1bad01b82
commit
3fabb52367
21 files changed
+115
-31
No files matched your search
@@ -0,0 +1,84 @@
|
||||
"""Every script a tracked text cites exists at the path or module it gives.
|
||||
|
||||
Comments, messages and pages kept naming scripts/sitebootstrap.py and
|
||||
scripts/region.py long after the code moved into packages, and a reader
|
||||
following one found nothing. A path (`scripts/sitegen/wanted.py`) or a
|
||||
module run with `-m` (`python -m scripts.scraper.arcade.mame_hash_scraper`)
|
||||
must name a file of the tree.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Where a script is cited: the code, the tests, the pages, the workflows,
|
||||
# the site's own sources, the installer and its bootstraps, the platform files
|
||||
# and the unattended jobs.
|
||||
CITING = ("scripts", "tests", "wiki", ".github", "website/src", "installer", "install.sh", "install.ps1",
|
||||
"platforms/*.yml", "platforms/**/*.yml", "automation")
|
||||
|
||||
# Modules that check a checker: the missing names they cite are the point.
|
||||
CHECKER_TESTS = frozenset({"tests/test_cited_scripts.py", "tests/test_doc_pages_tools.py",
|
||||
"tests/test_autorun.py"})
|
||||
|
||||
# A module a guide asks the reader to write (`myplatform_scraper`).
|
||||
PLACEHOLDERS = ("myplatform",)
|
||||
|
||||
SCRIPT_PATH = re.compile(r"(?<![\w/.-])scripts/[\w/.-]*?\.py\b")
|
||||
# `-m scripts.x.y` on a command line, or `"-m", "scripts.x.y"` in an argv list.
|
||||
SCRIPT_MODULE = re.compile(r"-m\b[\"',\s]+(scripts(?:\.\w+)+)(?![.\w])")
|
||||
|
||||
|
||||
def cited(text: str) -> list[tuple[int, str]]:
|
||||
found = []
|
||||
for number, line in enumerate(text.splitlines(), 1):
|
||||
found += [(number, m.group()) for m in SCRIPT_PATH.finditer(line)]
|
||||
found += [(number, m.group(1).replace(".", "/") + ".py") for m in SCRIPT_MODULE.finditer(line)]
|
||||
return found
|
||||
|
||||
|
||||
def exists(path: str) -> bool:
|
||||
file = ROOT / path
|
||||
return file.is_file() or (file.with_suffix("") / "__init__.py").is_file()
|
||||
|
||||
|
||||
def citing_files() -> list[str]:
|
||||
listed = subprocess.run(["git", "ls-files", "--", *CITING], cwd=ROOT, capture_output=True,
|
||||
text=True, check=True).stdout.split()
|
||||
return sorted(set(listed) - CHECKER_TESTS)
|
||||
|
||||
|
||||
class CitedScripts(unittest.TestCase):
|
||||
def test_every_cited_script_exists(self):
|
||||
missing = []
|
||||
for name in citing_files():
|
||||
path = ROOT / name
|
||||
if not path.is_file():
|
||||
continue
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
except UnicodeDecodeError:
|
||||
continue
|
||||
missing += [f"{name}:{number}: {script}" for number, script in cited(text)
|
||||
if not exists(script) and not any(word in script for word in PLACEHOLDERS)]
|
||||
self.assertEqual(missing, [])
|
||||
|
||||
def test_the_check_reads_both_spellings(self):
|
||||
text = ('# built by scripts/sitebootstrap.py\n'
|
||||
'python -m scripts.scraper.mame_hash_scraper --dry-run\n'
|
||||
'[sys.executable, "-m", "scripts.scraper.game_dat_importer"]\n')
|
||||
self.assertEqual(cited(text), [(1, "scripts/sitebootstrap.py"),
|
||||
(2, "scripts/scraper/mame_hash_scraper.py"),
|
||||
(3, "scripts/scraper/game_dat_importer.py")])
|
||||
self.assertFalse(any(exists(script) for _, script in cited(text)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -287,7 +287,7 @@ class TheArchives(unittest.TestCase):
|
||||
|
||||
def test_the_site_serves_each_and_the_release_none(self):
|
||||
"""Each archive carries install.py: the site serves it from its own
|
||||
commit (sitehandheld.py), and the release steps never build one."""
|
||||
commit (sitegen/handheld.py), and the release steps never build one."""
|
||||
text = (REPO_ROOT / "wiki" / "release-process.md").read_text(encoding="utf-8")
|
||||
self.assertNotIn("scripts/build_port.py", text)
|
||||
installer = (REPO_ROOT / "wiki" / "installer.md").read_text(encoding="utf-8")
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
verify.py and generate_pack.py must reach the same verdict on the same file:
|
||||
a pack and a coverage report that disagree describe different collections.
|
||||
The rule used to rest on both files spelling out `mode == "existence"` in
|
||||
their own words. Routing both through scripts/nativemode.py single-sources
|
||||
their own words. Routing both through scripts/resolve/nativemode.py single-sources
|
||||
it, and these tests make the agreement checkable instead of reviewable.
|
||||
"""
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""The installer demos of the README and the site (scripts/demovariants.py).
|
||||
"""The installer demos of the README and the site (scripts/sitegen/demovariants.py).
|
||||
|
||||
The home page and Get your files score 98 to 100 on a phone: a video must
|
||||
cost nothing before it is on screen, keep still under reduced motion, and say
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""The drawn steps of the install box (scripts/sitesteps.py).
|
||||
"""The drawn steps of the install box (scripts/sitegen/steps.py).
|
||||
|
||||
Each drawing file says in words what it shows, for one opened on its own:
|
||||
a title and a desc the SVG names. On the page the images are alt="" and the
|
||||
|
||||
Reference in new issue
Block a user