Skip to content

Commit

Permalink
Add linting workflow, install Poetry, run pre-push script
Browse files Browse the repository at this point in the history
Added a linting workflow, installed Poetry for dependency management, and implemented a pre-push script to run static analysis and linting checks on the source code.
  • Loading branch information
isFakeAccount committed Apr 1, 2024
1 parent ddee709 commit 4e9d1ca
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Linting

on:
push:
branches:
- "*"

jobs:
linting:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v3

- name: Install Poetry
run: pip install poetry

- name: Install dependencies and build package
run: |
poetry install
- name: Run pre-push script
run: poetry run python pre_push.py
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"program": "${workspaceFolder}/pre_push.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["--static"]
}
]
}
46 changes: 42 additions & 4 deletions pre_push.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Run static analysis on the project."""

from __future__ import annotations

import argparse
import sys
from subprocess import CalledProcessError, check_call

Expand Down Expand Up @@ -28,18 +30,31 @@ def do_process(args: list[str], shell: bool = False, cwd: str = ".") -> bool:


def run_static() -> bool:
"""Run the static tests.
"""Run static analysis on the source code.
Returns a statuscode of 0 if everything ran correctly. Otherwise, it will return
statuscode 1
:returns: True if static analysis processes were successful, False otherwise.
:rtype: bool
"""
success = True
success &= do_process(["mypy", "src"])
success &= do_process(["pyright"])

return success


def run_linting() -> bool:
"""Run linting checks on the source code.
:returns: True if all linting processes were successful, False otherwise.
:rtype: bool
"""
success = True
success &= do_process(["black", "src"])
success &= do_process(["ruff", "check", "src", "--fix"])
success &= do_process(["docstrfmt", "."])

return success


Expand All @@ -49,10 +64,33 @@ def main() -> int:
Run static and lint on code
"""

parser = argparse.ArgumentParser(description="Run static and/or unit-tests")
parser.add_argument(
"-s",
"--static",
action="store_true",
help="Do not run static tests (black/flake8/pydocstyle/sphinx-build)",
default=False,
)

parser.add_argument(
"-l",
"--linting",
action="store_true",
default=True,
help="Run the linting",
)

args = parser.parse_args()
success = True
try:
if success:
if args.static:
success &= run_static()

if args.linting:
success &= run_linting()

except KeyboardInterrupt:
return int(not False)
return int(not success)
Expand Down

0 comments on commit 4e9d1ca

Please sign in to comment.