diff --git a/.github/scripts/check_imports.py b/.github/scripts/check_imports.py new file mode 100644 index 00000000..2f789e31 --- /dev/null +++ b/.github/scripts/check_imports.py @@ -0,0 +1,45 @@ +import sys # noqa: D100 +from shutil import which +from trio import Path, run as async_run, open_nursery +from trio.lowlevel import open_process + +EXCLUDES = ('__init__.py', 'default.py') + +PROJECT = Path(__file__).parent.parent.parent + +PROTON_VERB = 'waitforexitandrun' + + +async def run_subproc(py_bin: str, file: Path) -> None: + """Run a module via the Python interpreter""" + path = await file.resolve(strict=True) + proc = await open_process( + [py_bin, str(path), PROTON_VERB], + cwd=str(path.parent), + env={'PYTHONPATH': str(PROJECT.parent)}, + ) + ret = await proc.wait() + + if ret != 0: + err = f'The following file has an invalid import: {file}' + raise RuntimeError(err) + + print(f"File '{file.parent / file.name}' has valid imports") + + +async def main() -> None: + """Validate import statements for files in gamefixes-*. by running them.""" + py_bin = which('python') + + if not py_bin: + sys.exit(1) + + async with open_nursery() as nursery: + for file in await PROJECT.rglob('gamefixes-*/*.py'): + if file.name.startswith(EXCLUDES): + continue + nursery.start_soon(run_subproc, py_bin, file) + + +if __name__ == '__main__': + async_run(main) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37432194..94872b7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,7 @@ jobs: python3 -m pip install --upgrade pip pip install ruff pip install ijson + pip install trio pip install "git+https://github.com/njbooher/steam.git@wsproto#egg=steam[client]" - name: Lint with Shellcheck run: | @@ -39,6 +40,12 @@ jobs: run: | python3 .github/scripts/check_gamefixes.py python3 .github/scripts/check_verbs.py + - name: Validate gamefix imports + run: | + cd .. + ln -s umu-protonfixes protonfixes + cd protonfixes + python3 .github/scripts/check_imports.py - name: Test with unittest run: | python3 protonfixes_test.py