Skip to content

Commit

Permalink
ci: validate import statements in modules (#204)
Browse files Browse the repository at this point in the history
* ci: validate import statements in fixes

* ci: run import statement check

* scripts: fix return type

* scripts: fix RuntimeError

* scripts: fix ModuleNotFoundError

* scripts: fix ModuleNotFoundError

* scripts: add protonfixes to PYTHONPATH

* scripts: extend PYTHONPATH

* scripts: log PYTHONPATH

* scripts: fix ModuleNotFoundError

* scripts: fix ModuleNotFoundError

* check_imports: change to module directory

* check_imports: fix PYTHONPATH

* check_imports: fix PYTHONPATH

* check_imports: fix PYTHONPATH

* check_imports: pass PYTHONPATH to subprocess

* check_imports: fix PYTHONPATH to subprocess

* check_imports: fix IndexError

* workflows: rename directories

* workflows: install trio

* check_imports: refactor to use trio

* workflows: remove comma

* workflows: install trio

* check_imports: log success

* workflows: create protonfixes link

* check_imports: temporarily remove PYTHONPATH

* Revert "check_imports: temporarily remove PYTHONPATH"

This reverts commit aa7ad9d.

* workflows: only install trio from pip

* workflows: update name

* check_imports: update print

* check_imports: update comments
  • Loading branch information
R1kaB3rN authored Jan 10, 2025
1 parent 97c5a03 commit 1d2ebf2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/scripts/check_imports.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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

0 comments on commit 1d2ebf2

Please sign in to comment.