-
Notifications
You must be signed in to change notification settings - Fork 21
/
tasks.py
129 lines (95 loc) · 2.77 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
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
124
125
126
127
128
129
from invoke import task
poetry_pypi_testing = "testpypi"
# Use the minimum python version required by the package
default_python_bin = "python3.8"
_NOT_GRAPHICAL = " -m 'not graphical'"
# If the most currently activated python version is desired, use 'inv install -p latest'
@task
def install(c, python=default_python_bin):
if python == "latest":
# don't do anything here: poetry will use the default python version
pass
else:
c.run("poetry env use {}".format(python))
c.run("poetry install")
@task
def rm_venv(c):
c.run("rm -rf .venv")
# Use this to change quickly python version
@task(rm_venv)
def reinstall(c, python=default_python_bin):
install(c, python)
@task
def build(c):
c.run("poetry build")
@task(build)
def publish_coverage(c):
c.run("poetry run coveralls")
@task(build)
def publish_test(c):
c.run(f"poetry publish -r {poetry_pypi_testing}")
@task(build)
def publish(c):
c.run("poetry publish")
@task()
def test(c, full=False, s=False, t=False):
marks = ""
capture = ""
if t:
marks = " -m 'runthis'"
elif not full:
marks = _NOT_GRAPHICAL
if s:
capture = " -s"
c.run(f"poetry run pytest{capture}{marks}", pty=True)
@task()
def test_spec(c, full=False):
marks = ""
if not full:
marks = _NOT_GRAPHICAL
c.run(f"poetry run pytest -p no:sugar --spec{marks}", pty=True)
@task()
def clear_cassettes(c):
c.run("rm -rf tests/cassettes")
print("Cleared!")
@task()
def test_cov(c, full=False):
c.run("mkdir -p coverage")
marks = ""
if not full:
marks = _NOT_GRAPHICAL
c.run(f"poetry run pytest --cov=pymailtm --cov-report annotate:coverage/cov_annotate --cov-report "
f"html:coverage/cov_html{marks}", pty=True)
@task(test_cov)
def html_cov(c):
c.run("xdg-open coverage/cov_html/index.html")
@task
def run(c, n=False, l=False):
if l:
c.run("poetry run pymailtm -l", pty=True)
elif n:
c.run("poetry run pymailtm -n", pty=True)
else:
c.run("poetry run pymailtm", pty=True)
#
# ACT
#
act_dev_ctx = "act-pymailtm-dev"
act_prod_ctx = "act-pymailtm-prod"
act_secrets_file = ".secrets"
@task
def act_prod(c, cmd=""):
if cmd == "":
c.run("act -W .github/workflows/prod.yml", pty=True)
elif cmd == "shell":
c.run(f"docker exec --env-file {act_secrets_file} -it {act_prod_ctx} bash", pty=True)
elif cmd == "clean":
c.run(f"docker rm -f {act_prod_ctx}", pty=True)
@task
def act_dev(c, cmd=""):
if cmd == "":
c.run("act -W .github/workflows/dev.yml", pty=True)
elif cmd == "shell":
c.run(f"docker exec --env-file {act_secrets_file} -it {act_dev_ctx} bash", pty=True)
elif cmd == "clean":
c.run(f"docker rm -f {act_dev_ctx}", pty=True)