-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduties.py
183 lines (147 loc) · 5 KB
/
duties.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
"""Development tasks."""
import os
import sys
from pathlib import Path
from shutil import which
from duty import duty
PY_SRC_PATHS = (Path(_) for _ in ("src", "tests", "duties.py", "docs/macros.py"))
PY_SRC_LIST = tuple(str(_) for _ in PY_SRC_PATHS)
PY_SRC = " ".join(PY_SRC_LIST)
TESTING = os.environ.get("TESTING", "0") in {"1", "true"}
CI = os.environ.get("CI", "0") in {"1", "true", "yes", ""}
WINDOWS = os.name == "nt"
PTY = not WINDOWS and not CI
@duty(pre=["check_docs", "check_dependencies"])
def check(ctx):
"""
Check it all!
Arguments:
ctx: The context instance (passed automatically).
"""
@duty
def check_dependencies(ctx):
"""
Check for vulnerabilities in dependencies.
Arguments:
ctx: The context instance (passed automatically).
"""
nofail = False
safety = which("safety")
if not safety:
pipx = which("pipx")
if pipx:
safety = f"{pipx} run safety"
else:
safety = "safety"
nofail = True
ctx.run(
f"poetry export -f requirements.txt --without-hashes | {safety} check --stdin --full-report",
title="Checking dependencies",
pty=PTY,
nofail=nofail,
)
@duty
def check_docs(ctx):
"""
Check if the documentation builds correctly.
Arguments:
ctx: The context instance (passed automatically).
"""
Path("build/coverage").mkdir(parents=True, exist_ok=True)
Path("build/coverage/index.html").touch(exist_ok=True)
ctx.run("mkdocs build -s", title="Building documentation", pty=PTY)
@duty
def check_types(ctx):
"""
Check that the code is correctly typed.
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run(f"mypy --config-file config/mypy.ini {PY_SRC}", title="Type-checking", pty=PTY)
@duty(silent=True)
def clean(ctx):
"""
Delete temporary files.
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run("rm -rf .coverage*")
ctx.run("rm -rf .mypy_cache")
ctx.run("rm -rf .pytest_cache")
ctx.run("rm -rf tests/.pytest_cache")
ctx.run("rm -rf build")
ctx.run("rm -rf dist")
ctx.run("rm -rf pip-wheel-metadata")
ctx.run("rm -rf site")
ctx.run("find . -type d -name __pycache__ | xargs rm -rf")
ctx.run("find . -name '*.rej' -delete")
@duty
def docs(ctx):
"""
Build the documentation locally.
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run("mkdocs build", title="Building documentation")
@duty
def docs_serve(ctx, host="127.0.0.1", port=8000):
"""
Serve the documentation (localhost:8000).
Arguments:
ctx: The context instance (passed automatically).
host: The host to serve the docs from.
port: The port to serve the docs on.
"""
ctx.run(f"mkdocs serve -a {host}:{port}", title="Serving documentation", capture=False)
@duty
def docs_deploy(ctx):
"""
Deploy the documentation on GitHub pages.
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run("mkdocs gh-deploy", title="Deploying documentation")
@duty
def release(ctx, version):
"""
Release a new Python package.
Arguments:
ctx: The context instance (passed automatically).
version: The new version number to use.
"""
ctx.run(f"poetry version {version}", title=f"Bumping version in pyproject.toml to {version}", pty=PTY)
ctx.run(f'gsed --in-place "s/__version__ = .*/__version__ = \\"{version}\\"/g" src/kmerpapa/__init__.py')
ctx.run("git add pyproject.toml src/kmerpapa/__init__.py", title="Staging files", pty=PTY)
ctx.run(["git", "commit", "-m", f"chore: Prepare release {version}"], title="Committing changes", pty=PTY)
ctx.run(f"git tag v{version}", title="Tagging commit", pty=PTY)
if not TESTING:
ctx.run("git push", title="Pushing commits", pty=False)
ctx.run("git push --tags", title="Pushing tags", pty=False)
ctx.run("poetry build", title="Building dist/wheel", pty=PTY)
ctx.run("poetry publish -u __token__ -p $POETRY_PYPI_TOKEN_PYPI ", title="Publishing version", pty=PTY)
#docs_deploy.run() # type: ignore
@duty(silent=True)
def coverage(ctx):
"""
Report coverage as text and HTML.
Arguments:
ctx: The context instance (passed automatically).
"""
ctx.run("coverage combine .coverage-*", nofail=True)
ctx.run("coverage report --rcfile=config/coverage.ini", capture=False)
ctx.run("coverage html --rcfile=config/coverage.ini")
@duty
def test(ctx, match: str = ""):
"""
Run the test suite.
Arguments:
ctx: The context instance (passed automatically).
match: A pytest expression to filter selected tests.
"""
py_version = f"{sys.version_info.major}{sys.version_info.minor}"
os.environ["COVERAGE_FILE"] = f".coverage-{py_version}"
ctx.run(
["pytest", "-c", "config/pytest.ini", "-n", "auto", "-k", match, "tests"],
title="Running tests",
pty=PTY,
)