-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
84 lines (63 loc) · 1.94 KB
/
tasks.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
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
import json
import os
from invoke import task
CWD = os.path.abspath(os.path.dirname(__file__))
@task
def linters(c):
"""Run linters"""
cmd = "poetry run ruff check cwtch"
c.run(cmd)
@task
def tests(c):
"""Run tests"""
cmd = (
"poetry run coverage run --data-file=artifacts/.coverage --source cwtch "
"-m pytest -v --maxfail=1 --benchmark-columns=min,max,mean,stddev,median,ops tests/ && "
"poetry run coverage json --data-file=artifacts/.coverage -o artifacts/coverage.json && "
"poetry run coverage report --data-file=artifacts/.coverage -m"
)
c.run(cmd)
@task
def generate_coverage_gist(c):
with open("artifacts/coverage.json") as f:
data = json.load(f)
percent = int(data["totals"]["percent_covered_display"])
if percent >= 90:
color = "brightgreen"
elif percent >= 75:
color = "green"
elif percent >= 50:
color = "yellow"
else:
color = "red"
data = {
"description": "Cwtch shields.io coverage json data",
"files": {
"coverage.json": {
"content": json.dumps(
{
"schemaVersion": 1,
"label": "coverage",
"message": f"{percent}%",
"color": color,
}
)
},
},
}
with open("artifacts/shields_io_coverage_gist_data.json", "w") as f:
f.write(json.dumps(data))
@task
def build_docs(c):
"""Build documentation"""
cmd = "poetry run mkdocs build -f docs/mkdocs.yml"
c.run(cmd)
cmd = "poetry run mkdocs build -f docs/en/mkdocs.yml -d ../site/en/"
c.run(cmd)
cmd = "poetry run mkdocs build -f docs/ru/mkdocs.yml -d ../site/ru/"
c.run(cmd)
@task
def run_docs(c):
"""Run HTTP server with documentation localy"""
cmd = "poetry run python -m http.server -d docs/site"
c.run(cmd)