# SPDX-License-Identifier: MIT """Find MAME device sets on ``MAME_ROMPATH`` (bring your own; nothing is copied). ``MAME_ROMPATH`` holds one or more folders separated by ``;``, as MAME's ``-rompath``. The DSP programs are MAME's device sets (``sns_dsp1leg.zip`` ... ``sns_seta11leg.zip``); the ``snes`` driver also needs ``snes.zip``. Callers skip, or stop with a message, when the variable or a set is missing. """ from __future__ import annotations import os from pathlib import Path ENV = "MAME_ROMPATH" def rompath(value: str | None = None) -> str: """The ``;``-separated rompath: ``value`` if given, else ``$MAME_ROMPATH``, else ``""``.""" return value if value is not None else os.environ.get(ENV, "") def rompath_dirs(value: str | None = None) -> list[Path]: """The rompath's folders, in order (empty entries dropped).""" return [Path(part) for part in rompath(value).split(";") if part.strip()] def find_set(name: str, value: str | None = None) -> Path | None: """The first ``.zip`` on the rompath, or ``None``.""" for folder in rompath_dirs(value): path = folder / f"{name}.zip" if path.exists(): return path return None