Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: validate import statements in modules #204

Merged
merged 31 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
824d252
ci: validate import statements in fixes
R1kaB3rN Jan 9, 2025
355283a
ci: run import statement check
R1kaB3rN Jan 9, 2025
dbdc101
scripts: fix return type
R1kaB3rN Jan 9, 2025
929b585
scripts: fix RuntimeError
R1kaB3rN Jan 9, 2025
ccd347b
scripts: fix ModuleNotFoundError
R1kaB3rN Jan 9, 2025
adab186
scripts: fix ModuleNotFoundError
R1kaB3rN Jan 9, 2025
8e716e2
scripts: add protonfixes to PYTHONPATH
R1kaB3rN Jan 9, 2025
8b997e9
scripts: extend PYTHONPATH
R1kaB3rN Jan 9, 2025
fa15bd8
scripts: log PYTHONPATH
R1kaB3rN Jan 9, 2025
a324fa4
scripts: fix ModuleNotFoundError
R1kaB3rN Jan 9, 2025
4e48a9a
scripts: fix ModuleNotFoundError
R1kaB3rN Jan 9, 2025
e76d49a
check_imports: change to module directory
R1kaB3rN Jan 9, 2025
9f18175
check_imports: fix PYTHONPATH
R1kaB3rN Jan 9, 2025
e0c6242
check_imports: fix PYTHONPATH
R1kaB3rN Jan 9, 2025
a7ccaac
check_imports: fix PYTHONPATH
R1kaB3rN Jan 9, 2025
f2fb26e
check_imports: pass PYTHONPATH to subprocess
R1kaB3rN Jan 9, 2025
42bed22
check_imports: fix PYTHONPATH to subprocess
R1kaB3rN Jan 9, 2025
2148de3
check_imports: fix IndexError
R1kaB3rN Jan 9, 2025
3ceb4fa
workflows: rename directories
R1kaB3rN Jan 9, 2025
5a9bc62
workflows: install trio
R1kaB3rN Jan 9, 2025
e0d38fe
check_imports: refactor to use trio
R1kaB3rN Jan 9, 2025
4be00bd
workflows: remove comma
R1kaB3rN Jan 9, 2025
dd2fddf
workflows: install trio
R1kaB3rN Jan 9, 2025
9a2d2fd
check_imports: log success
R1kaB3rN Jan 9, 2025
fb05549
workflows: create protonfixes link
R1kaB3rN Jan 9, 2025
aa7ad9d
check_imports: temporarily remove PYTHONPATH
R1kaB3rN Jan 9, 2025
2261068
Revert "check_imports: temporarily remove PYTHONPATH"
R1kaB3rN Jan 9, 2025
98bcf9e
workflows: only install trio from pip
R1kaB3rN Jan 9, 2025
d7cd8b8
workflows: update name
R1kaB3rN Jan 9, 2025
c6d83bd
check_imports: update print
R1kaB3rN Jan 9, 2025
3948048
check_imports: update comments
R1kaB3rN Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading