-
Notifications
You must be signed in to change notification settings - Fork 24
/
fabfile.py
52 lines (39 loc) · 1.3 KB
/
fabfile.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
from os import environ
from os.path import abspath
from typing import Any
import fabric
def regen_apidoc(ctx: Any, src: str, dest: str, is_nspkg: bool = False) -> None:
ctx.run(f"rm -rf {dest}", replace_env=False, pty=True)
nsopt = " --implicit-namespaces" if is_nspkg else ""
if "READTHEDOCS" in environ:
cmd = "sphinx-apidoc"
else:
cmd = "./env/bin/sphinx-apidoc"
ctx.run(
f"{cmd} -o {dest} -f{nsopt} -e -M {src}",
replace_env=False,
pty=True,
)
@fabric.task
def regen_all_api(ctx):
regen_apidoc(ctx, "src/puresnmp", "doc/api")
regen_apidoc(ctx, "src/puresnmp_plugins", "doc/plugins_api", True)
@fabric.task
def doc(ctx):
regen_all_api(ctx)
opts = {
"builddir": "_build",
"sphinx": abspath("env/bin/sphinx-build"),
"apidoc": abspath("env/bin/sphinx-apidoc"),
}
cmd = "{sphinx} -b html -d {builddir}/doctrees . {builddir}/html"
with ctx.cd("doc"):
ctx.run(cmd.format(**opts), replace_env=False, pty=True)
@fabric.task
def develop(ctx):
"""
Set up a development environment
"""
ctx.run("[ -d env ] || python3 -m venv env", replace_env=False)
ctx.run("./env/bin/pip install -U pip", replace_env=False)
ctx.run("./env/bin/pip install -e .[dev,test]", replace_env=False)