refactor: one rule for system and maker names

packs.naming.system_display_name names a system in a pack file name,
read by system_tag in place of its copy of the loop. names_manufacturer
spells a maker through model.collection.manufacturer_slug, and
resolve.identity reads the maker folder with ownership.maker_of_relative,
the rule maker_folder applies. No behavior change.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:26 +01:00
1 parent 6b3a588231
commit b679edb133
5 files changed
+27 -24

No files matched your search

+3 -11
View File
@@ -26,7 +26,6 @@ from model.profiles import (
select_emulator_profiles,
)
from model.registry import load_data_dir_registry
from model.systems import MANUFACTURER_PREFIXES
from packs.archive import (
PackRecord,
Placed,
@@ -38,7 +37,9 @@ from packs.archive import (
)
from packs.datatrees import MISSING_DATA_DIRS, pack_data_tree
from packs.extras import emulator_region_drops, emulator_required_spares, expand_agnostic_entries
from packs.naming import bounded_join, bounded_pack_name, file_name_part, pack_narrowings
from packs.naming import (
bounded_join, bounded_pack_name, file_name_part, pack_narrowings, system_display_name,
)
from packs.paths import archive_destination, resolve_destination
from resolve import packfiles as packresolve
from resolve.archives import archive_entry, archive_is_optional
@@ -617,12 +618,3 @@ def generate_system_pack(
shutil.rmtree(scratch, ignore_errors=True)
def system_display_name(system_id: str) -> str:
"""Convert system ID to display name for ZIP naming."""
s = system_id.lower().replace("_", "-")
for prefix in MANUFACTURER_PREFIXES:
if s.startswith(prefix):
s = s[len(prefix) :]
break
parts = s.split("-")
return "_".join(p.title() for p in parts if p)
+11 -8
View File
@@ -86,18 +86,21 @@ def platform_target(
return canonical_target_name([platform_name], target, platforms_dir)
def system_display_name(system_id: str) -> str:
"""A system id as a pack file name writes it, its maker prefix dropped."""
s = system_id.lower().replace("_", "-")
for prefix in MANUFACTURER_PREFIXES:
if s.startswith(prefix):
s = s[len(prefix) :]
break
return "_".join(p.title() for p in s.split("-") if p)
def system_tag(system_filter: list[str] | None) -> str:
"""Filename tag for a pack limited to some systems, empty for all."""
if not system_filter:
return ""
display_parts = []
for sid in system_filter:
s = sid.lower().replace("_", "-")
for prefix in MANUFACTURER_PREFIXES:
if s.startswith(prefix):
s = s[len(prefix) :]
break
display_parts.append("_".join(p.title() for p in s.split("-") if p))
display_parts = [system_display_name(sid) for sid in system_filter]
return "_" + bounded_join(display_parts, system_filter)
+1 -1
View File
@@ -32,7 +32,7 @@ from packs.archive import (
writing_pack,
)
from packs.datatrees import data_directory_members, core_data_trees, pack_markers
from packs.emulatorpack import system_display_name
from packs.naming import system_display_name
from packs.extras import (
ExtraResolver,
collect_emulator_extras,
+2 -2
View File
@@ -20,6 +20,7 @@ from pathlib import Path
from core.paths import BIOS_DIR
from core.hashing import file_digest
from resolve.ownership import maker_of_relative
# A manufacturer directory holding files that genuinely belong to several
@@ -60,8 +61,7 @@ class Duplicate:
def _manufacturer(path: Path, root: Path) -> str:
"""The vendor directory a path sits under, relative to the scanned root."""
parts = path.relative_to(root).parts
return parts[0] if len(parts) > 1 else ""
return maker_of_relative(path.relative_to(root).as_posix()) or ""
def scan(bios_dir: str = BIOS_DIR) -> list[Duplicate]:
+10 -2
View File
@@ -4,6 +4,8 @@ from __future__ import annotations
import re
from model.collection import manufacturer_slug
# bios/Other/<emulator> and bios/Arcade/<emulator or board> file a copy by
# who loads it, not by machine.
@@ -12,7 +14,7 @@ BUCKET_FOLDERS = frozenset({"Other", "Arcade"})
def names_manufacturer(sys_id: str, manufacturer: str) -> bool:
"""Whether a system id names a maker folder: nec-pc-88 names NEC."""
slug = manufacturer.lower().replace(" ", "-")
slug = manufacturer_slug(manufacturer)
return sys_id == slug or sys_id.startswith(f"{slug}-")
@@ -21,7 +23,13 @@ def maker_folder(path: str, bios_dir: str) -> str | None:
prefix = f"{bios_dir.rstrip('/')}/"
if not path.startswith(prefix):
return None
parts = path[len(prefix):].split("/")
return maker_of_relative(path[len(prefix):])
def maker_of_relative(relative: str) -> str | None:
"""The maker folder of a path relative to the BIOS directory, None for a
file sitting at its root."""
parts = relative.split("/")
return parts[0] if len(parts) >= 2 else None