-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpoetry_scripts.py
executable file
·57 lines (41 loc) · 1.86 KB
/
poetry_scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import subprocess
import sys
from typing import List
def execute(name: str, command: List[str], failure_message: str) -> None:
"""
Execute a command with output sent to the console. If exit code is non-zero will exit with non-zero and
display the provided failure message.
"""
print("--------------------------------------------------------------------------------")
print(f"Running task: {name} ({command})")
print("--------------------------------------------------------------------------------")
completed_process = subprocess.run(command)
if completed_process.returncode != 0:
print("FAILURE")
print(failure_message)
sys.exit(1)
# The following section defines individual methods to run specific sub-tasks, used by poetry
# hooks given in the pyproject.toml file. Add new tasks to qa() below as well.
def test() -> None:
execute("tests", ["pytest", "tests", "--cov-fail-under", "100"], "Please fix the failing test.")
def format_check() -> None:
execute("format", ["isort", "--check-only", "."], 'Import ordering incorrect. Run "poetry run isort ." to fix.')
execute("format", ["black", "--check", "."], 'Running "poetry run black ." will fix most issues.')
def format_fix() -> None:
execute("format", ["isort", "."], "isort formatting failed. Address issues manually.")
execute("format", ["black", "."], "black formatting failed. Address issues manually.")
def lint() -> None:
execute("lint", ["flake8"], "Address any remaining flake8 issues manually.")
def type_check() -> None:
execute(
"type_check", ["mypy", "."], 'Mypy check failed. See above for errors, run "poetry run mypy ." to confirm fix.'
)
# This routine runs all the defined tasks in order
def qa() -> None:
format_fix()
type_check()
lint()
test()
if __name__ == "__main__":
qa()