-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy path_docs.py
78 lines (65 loc) · 2.09 KB
/
_docs.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
import sys
from pathlib import Path
from shutil import rmtree
from invoke import Collection, task
@task(name="clean")
def _clean(c):
output = Path(c.sphinx.target)
if output.exists():
print(f"delete {output}")
rmtree(output)
@task(
default=True,
help={
"opts": "Extra sphinx-build options/args",
"nitpick": "Build with stricter warnings/errors enabled",
"source": "Source directory; overrides config setting",
"target": "Output directory; overrides config setting",
},
)
def build(c, opts=None, language=None, source=None, target=None, nitpick=False):
"""
Build the project's Sphinx docs.
"""
if opts is None:
opts = ""
source = source or c.sphinx.source
target = target or c.sphinx.target
if language:
opts = f"-D language={language}"
target = f"{target}/{language}"
if nitpick:
opts += " -n -W -T"
cmd = f"pipenv run sphinx-build {opts} {source} {target}"
c.run(cmd)
@task
def update(c, language="en"):
"""Update the POT file and invoke the `sphinx-intl` `update` command
Only used with `invoke intl.update`
"""
opts = "-b gettext"
target = Path(c.sphinx.target).parent / "output/gettext"
if language == "en":
_clean(c)
build(c, target=target, opts=opts)
else:
if not Path(target).exists():
build(c, target=target, opts=opts)
c.run(f"pipenv run sphinx-intl update -p {target} -l {language}")
# for DIR in ['pages', 'posts', 'shop']:
# rmtree(f'locales/{language}/LC_MESSAGES/{DIR}/')
def _site(name, help_part):
self = sys.modules[__name__]
coll = Collection.from_module(
self,
name=name,
config={"sphinx": {"source": name, "target": "output"}},
)
coll.__doc__ = f"Tasks for building {help_part}"
coll["build"].__doc__ = f"Build {help_part}"
return coll
# Sites
intl = _site("intl", "the translations sub-site.")
site = _site("site", "the main site.")
bundle = _site("bundle", "package documentation bundle.")
ns = Collection(intl, site, bundle)