-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtasks.py
More file actions
123 lines (96 loc) · 2.63 KB
/
tasks.py
File metadata and controls
123 lines (96 loc) · 2.63 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"""
Project Tasks that can be invoked using using the program "invoke" or "inv"
"""
from __future__ import annotations
import os
from typing import TYPE_CHECKING
from invoke import task
if TYPE_CHECKING:
from invoke import Context
# disable the check for unused-arguments to ignore unused ctx parameter in tasks
# pylint: disable=unused-argument
IS_WINDOWS = os.name == "nt"
if IS_WINDOWS:
# setting 'shell' is a work around for issue #345 of invoke
RUN_ARGS = {"pty": False, "shell": r"C:\Windows\System32\cmd.exe"}
else:
RUN_ARGS = {"pty": True}
def get_files() -> str:
"""
Get the files to run analysis on
"""
files = [
"dploy",
"tests",
"tasks.py",
]
files_string = " ".join(files)
return files_string
@task
def setup(ctx: Context) -> None:
"""
Install python requirements
"""
ctx.run("uv sync", **RUN_ARGS)
@task
def clean(ctx: Context) -> None:
"""
Clean repository using git
"""
ctx.run("git clean --interactive", **RUN_ARGS)
@task
def lint(ctx: Context) -> None:
"""
Run pylint, ruff, and ty on this module
"""
cmds = ["pylint --output-format=parseable", "ruff check", "ty check"]
base_cmd = "uv run {cmd} {files}"
for cmd in cmds:
ctx.run(base_cmd.format(cmd=cmd, files=get_files()), **RUN_ARGS)
@task
def reformat_check(ctx: Context) -> None:
"""
Run formatting check
"""
cmd = "ruff format --check"
base_cmd = "uv run {cmd} {files}"
ctx.run(base_cmd.format(cmd=cmd, files=get_files()), **RUN_ARGS)
@task
def reformat(ctx: Context) -> None:
"""
Run formatting
"""
cmd = "ruff format"
base_cmd = "uv run {cmd} {files}"
ctx.run(base_cmd.format(cmd=cmd, files=get_files()), **RUN_ARGS)
@task
def metrics(ctx: Context) -> None:
"""
Run radon code metrics on this module
"""
cmd = "uv run radon {metric} --min B {files}"
metrics_to_run = ["cc", "mi"]
for metric in metrics_to_run:
ctx.run(cmd.format(metric=metric, files=get_files()), **RUN_ARGS)
@task()
def test(ctx: Context) -> None:
"""
Test Task
"""
cmd = "uv run pytest --cov-report term-missing --cov=dploy --color=no"
ctx.run(cmd, **RUN_ARGS)
# pylint: disable=redefined-builtin
@task(test, lint, reformat_check, metrics)
def all(ctx: Context) -> None:
"""
Run all CI tasks: test, lint, reformat_check, and metrics
"""
@task(clean)
def build(ctx: Context) -> None:
"""
Task to build an executable using pyinstaller
"""
cmd = "uv run pyinstaller -n dploy --onefile " + os.path.join(
"dploy", "__main__.py"
)
ctx.run(cmd, **RUN_ARGS)