# SPDX-License-Identifier: MIT """The S-DSP module imports only the standard library and itself (docs/dsp/interface.md).""" from __future__ import annotations import ast import sys from pathlib import Path DSP = Path(__file__).resolve().parents[2] / "src" / "snes_python" / "dsp" def _imports(path: Path) -> set[str]: found: set[str] = set() for node in ast.walk(ast.parse(path.read_text())): if isinstance(node, ast.ImportFrom) and node.module: found.add(node.module) elif isinstance(node, ast.Import): found.update(alias.name for alias in node.names) return found def test_dsp_imports_nothing_from_the_board(): files = list(DSP.rglob("*.py")) assert files for path in files: for module in _imports(path): top = module.split(".")[0] if top == "snes_python": assert module.startswith("snes_python.dsp"), f"{path.name} imports {module}" else: assert top in sys.stdlib_module_names or top == "__future__", ( f"{path.name} imports {module}" )