-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rudimentary CI (just formatting checks for now)
- Loading branch information
Showing
5 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: CI | ||
on: [push] | ||
env: | ||
PYTHON_VER: python3.9 # 3.9 is default on Amazon Linux 2023 | ||
|
||
jobs: | ||
Lint-Python: | ||
runs-on: ubuntu-22.04 # latest at time of writing | ||
steps: | ||
- name: Checkout Sources | ||
uses: actions/checkout@v4 | ||
|
||
- name: Lint | ||
run: $PYTHON_VER -m pip install -r scripts/requirements.txt | ||
run: $PYTHON_VER -m scripts/lint-python.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
from pathlib import Path | ||
import subprocess | ||
import sys | ||
|
||
PARSER = argparse.ArgumentParser( | ||
description="Check formatting and type hints in python scripts") | ||
|
||
|
||
def run(cmd_args: list[str]): | ||
print(f'> {subprocess.list2cmdline(cmd_args)}') | ||
result = subprocess.run(cmd_args) | ||
if result.returncode != 0: | ||
exit('FAILED') | ||
|
||
|
||
def get_script_dirs() -> list[str]: | ||
dirs = [] | ||
root = Path(__file__).parent.parent | ||
|
||
# add this scripts/ dir | ||
dirs.append(root.joinpath('scripts')) | ||
|
||
# add each runner's scripts/ dir | ||
for runner_child in root.joinpath('runners').iterdir(): | ||
if runner_child.is_dir(): | ||
runner_scripts = runner_child.joinpath('scripts') | ||
if runner_scripts.is_dir(): | ||
dirs.append(runner_scripts) | ||
|
||
return [str(i) for i in dirs] | ||
|
||
|
||
def check_formatting(dirs: list[str]): | ||
cmd_args = [sys.executable, '-m', 'autopep8', | ||
'--recursive', '--diff', '--exit-code'] | ||
cmd_args.extend(dirs) | ||
run(cmd_args) | ||
|
||
|
||
def check_typing(dirs: list[str]): | ||
# run mypy on each script dir separately, | ||
# so it doesn't complain about there being multiple build.py files | ||
for dir in dirs: | ||
run([sys.executable, '-m', 'mypy', dir]) | ||
|
||
|
||
if __name__ == '__main__': | ||
args = PARSER.parse_args() | ||
script_dirs = get_script_dirs() | ||
check_formatting(script_dirs) | ||
check_typing(script_dirs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
boto3 | ||
autopep8 # for code formatting | ||
mypy # for type checking |