mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-06 01:53:56 -06:00
fix: write region names in pack READMEs as labels
packreadme title-cased each slug, printing asia-ntsc as Asia Ntsc. region.label() holds the words the site already used, and both read it.
This commit is contained in:
1 parent
00aac8dc72
commit
2f81aa9c0f
4 files changed
+38
-11
No files matched your search
@@ -7750,20 +7750,17 @@ def _distinct_spellings(names: list) -> list[str]:
|
||||
return list(seen.values())
|
||||
|
||||
|
||||
# Region slugs whose words are not the slug title-cased.
|
||||
_REGION_WORDS = {
|
||||
"uk": "UK",
|
||||
"asia-ntsc": "Asia (NTSC)",
|
||||
"asia-pal": "Asia (PAL)",
|
||||
"world": "every region",
|
||||
}
|
||||
# Region slugs whose words are not the slug title-cased, beyond region.LABELS.
|
||||
_REGION_WORDS = {"world": "every region"}
|
||||
|
||||
|
||||
def _region_words(value: object, most: int = 0) -> str:
|
||||
"""A region: value in words. ``most`` caps the regions named, the rest
|
||||
counted: one Saturn BIOS serves seven."""
|
||||
raw = value if isinstance(value, list) else [value] if value else []
|
||||
words = [_REGION_WORDS.get(str(r), str(r).replace("-", " ").title()) for r in raw]
|
||||
from region import label # noqa: PLC0415
|
||||
|
||||
words = [_REGION_WORDS.get(str(r)) or label(str(r)) for r in raw]
|
||||
if most and len(words) > most:
|
||||
words = words[:most] + [f"{len(words) - most} more"]
|
||||
return _said_as_list(words)
|
||||
|
||||
@@ -5,6 +5,7 @@ goes, and which ones the user has to rename."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from region import label as region_label
|
||||
from siteguides import INSTALL_PS1, INSTALL_SH, pack_manual
|
||||
|
||||
def _detect_systems(detect: list[dict]) -> list[str]:
|
||||
@@ -290,9 +291,7 @@ def _build_readme(
|
||||
|
||||
region_info = ""
|
||||
if regions:
|
||||
pretty = ", ".join(
|
||||
" ".join(w.title() for w in slug.split("-")) for slug in regions
|
||||
)
|
||||
pretty = ", ".join(region_label(slug) for slug in regions)
|
||||
region_info = (
|
||||
"PACK TYPE: Region Filtered\n\n"
|
||||
f" Region priority: {pretty}\n\n"
|
||||
|
||||
@@ -107,6 +107,19 @@ ALIASES: dict[str, str] = {
|
||||
}
|
||||
|
||||
|
||||
# Slugs a person does not write title-cased: "Asia Ntsc" read as machine text.
|
||||
LABELS: dict[str, str] = {
|
||||
"uk": "UK",
|
||||
"asia-ntsc": "Asia (NTSC)",
|
||||
"asia-pal": "Asia (PAL)",
|
||||
}
|
||||
|
||||
|
||||
def label(slug: str) -> str:
|
||||
"""A region slug in words: north-america as North America."""
|
||||
return LABELS.get(slug) or " ".join(word.title() for word in slug.split("-"))
|
||||
|
||||
|
||||
def unknown_region_message(raw: str, aliases: dict[str, str], regions: frozenset[str]) -> str:
|
||||
"""What to type instead: the closest spellings, then every short form.
|
||||
|
||||
|
||||
@@ -1452,5 +1452,23 @@ class UsaRegionServesTheAmericas(unittest.TestCase):
|
||||
self.assertEqual(region.rank(jpn, requested), 1)
|
||||
|
||||
|
||||
class RegionWordsInAPackReadme(unittest.TestCase):
|
||||
"""The pack README title-cased each slug: asia-ntsc read "Asia Ntsc"."""
|
||||
|
||||
def test_the_priority_line_reads_as_written(self):
|
||||
from packreadme import _build_readme # noqa: PLC0415
|
||||
|
||||
readme = _build_readme(
|
||||
"retroarch", "RetroArch", "system", 1, 1,
|
||||
regions=region.parse_requested("us,asia-ntsc,jp"),
|
||||
)
|
||||
self.assertIn("Region priority: North America, Asia (NTSC), Japan", readme)
|
||||
|
||||
def test_every_region_has_a_label(self):
|
||||
for slug in region.REGIONS:
|
||||
with self.subTest(slug=slug):
|
||||
self.assertNotRegex(region.label(slug), r"\bNtsc\b|\bPal\b|\bUk\b")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user