mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-03 14:58:51 -06:00
refactor: one choice of packs with their own root
This commit is contained in:
1 parent
46e6b94171
commit
6f8e2f90c1
3 files changed
+46
-26
No files matched your search
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from model.declarations import declared_root
|
||||
from model.platforms import load_platform_config
|
||||
from model.registry import load_platform_registry
|
||||
from sitegen.install import display_name, platform_display
|
||||
from sitegen.install import platform_display
|
||||
|
||||
|
||||
def extract_targets(platforms_dir: str) -> list[tuple[str, str]]:
|
||||
@@ -35,22 +35,35 @@ def own_root(config: dict) -> str:
|
||||
return tops.pop() if len(tops) == 1 else "bios"
|
||||
|
||||
|
||||
def own_root_packs(platforms_dir: str) -> dict[str, tuple[str, str]]:
|
||||
"""Registry key: (own root folder, where it unzips) for each platform whose
|
||||
pack holds its own top folder.
|
||||
|
||||
A list written from an empty base_destination carries its root in every
|
||||
path, so its pack unzips above the BIOS folder. The guide and the
|
||||
which-pack page both format from this selection.
|
||||
"""
|
||||
registry = load_platform_registry(platforms_dir)
|
||||
packs = {}
|
||||
for key in sorted(registry):
|
||||
folder = registry[key].get("extract_to")
|
||||
if not folder:
|
||||
continue
|
||||
config = load_platform_config(key, platforms_dir)
|
||||
if config.get("base_destination") == "":
|
||||
packs[key] = (own_root(config), folder)
|
||||
return packs
|
||||
|
||||
|
||||
def extract_notes(platforms_dir: str, released_only: bool = False) -> list[str]:
|
||||
"""A pack whose entries carry their own root extracts above the BIOS folder.
|
||||
|
||||
*released_only* keeps the platforms a release publishes a pack for.
|
||||
"""
|
||||
folders = dict(extract_targets(platforms_dir))
|
||||
registry = load_platform_registry(platforms_dir)
|
||||
notes = []
|
||||
for key in sorted(registry):
|
||||
if released_only and registry[key].get("release_pack") is not True:
|
||||
continue
|
||||
config = load_platform_config(key, platforms_dir)
|
||||
display = display_name(config, key)
|
||||
if config.get("base_destination") == "" and display in folders:
|
||||
notes.append(
|
||||
f"The {display} pack holds its own `{own_root(config)}/` folder."
|
||||
f" Unzip it into `{folders[display]}`."
|
||||
)
|
||||
return notes
|
||||
return [
|
||||
f"The {platform_display(key, platforms_dir)} pack holds its own `{root}/` folder."
|
||||
f" Unzip it into `{folder}`."
|
||||
for key, (root, folder) in own_root_packs(platforms_dir).items()
|
||||
if not released_only or registry[key].get("release_pack") is True
|
||||
]
|
||||
@@ -16,11 +16,11 @@ from model.guides import (
|
||||
terminals,
|
||||
install_command,
|
||||
)
|
||||
from model.platforms import load_platform_config
|
||||
from model.registry import load_platform_registry
|
||||
from packs.consumers import FileConsumers
|
||||
from sitegen import markup, steps as sitesteps
|
||||
from sitegen.config import RELEASE_URL
|
||||
from sitegen.extraction import own_root_packs
|
||||
from sitegen.guidepage import NO_ZIP_FAQ, devices_meta, first_screen_words, get_page_link
|
||||
from sitegen.guides import fence, terminal_tabs, trust_box
|
||||
from sitegen.home import group_keys, next_block, runs_on_text, setup_picker
|
||||
@@ -89,16 +89,9 @@ def _pack_cell(name: str, record: dict, prefix: str = "") -> str:
|
||||
|
||||
|
||||
def _own_root_folders(registry: dict) -> dict[str, str]:
|
||||
"""Platforms whose pack holds its own top folder, with where it unzips.
|
||||
|
||||
The same rule as extract_notes: a list written from an empty base
|
||||
destination carries its root in every path."""
|
||||
folders = {}
|
||||
for key, entry in registry.items():
|
||||
config = load_platform_config(key, str(siteinputs.current().platforms))
|
||||
if config.get("base_destination") == "" and entry.get("extract_to"):
|
||||
folders[key] = entry["extract_to"]
|
||||
return folders
|
||||
"""Platforms whose pack holds its own top folder, with where it unzips."""
|
||||
packs = own_root_packs(str(siteinputs.current().platforms))
|
||||
return {key: folder for key, (_root, folder) in packs.items() if key in registry}
|
||||
|
||||
|
||||
def _folder_row(key: str, display: dict[str, str], registry: dict, record: dict,
|
||||
|
||||
@@ -17,7 +17,7 @@ from pathlib import Path
|
||||
|
||||
from model.platforms import load_platform_config
|
||||
from model.registry import load_platform_registry
|
||||
from sitegen.extraction import extract_notes, extract_targets
|
||||
from sitegen.extraction import extract_notes, extract_targets, own_root_packs
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
@@ -49,6 +49,20 @@ class ExtractTargets(unittest.TestCase):
|
||||
self.assertTrue(rooted)
|
||||
self.assertEqual(explained, rooted)
|
||||
|
||||
def test_guide_and_which_pack_unzip_the_same_packs(self):
|
||||
"""The guide's notes and the which-pack rows chose the packs with two
|
||||
copies of one rule: both now format from own_root_packs."""
|
||||
from sitegen import whichpack
|
||||
|
||||
packs = own_root_packs(PLATFORMS)
|
||||
rows = whichpack._own_root_folders(load_platform_registry(PLATFORMS))
|
||||
self.assertEqual(rows, {key: folder for key, (_root, folder) in packs.items()})
|
||||
notes = extract_notes(PLATFORMS)
|
||||
self.assertEqual(len(notes), len(packs))
|
||||
for note, (root, folder) in zip(notes, packs.values()):
|
||||
self.assertIn(f"`{root}/`", note)
|
||||
self.assertTrue(note.endswith(f"Unzip it into `{folder}`."))
|
||||
|
||||
def test_no_generator_keeps_its_own_table(self):
|
||||
"""The which-pack page describes setups per OS, and these two were the
|
||||
per-platform copies of the registry."""
|
||||
|
||||
Reference in new issue
Block a user