This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_docs.py
90 lines (78 loc) · 2.23 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
79
80
81
82
83
84
85
86
87
88
89
90
import sys, os
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"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 / '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'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__]
if name == 'docs':
out = ''
else:
out = name
coll = Collection.from_module(
self,
name=name,
config={"sphinx": {
"source": name,
"target": f"output/html/{out}"
}},
)
coll.__doc__ = f"Tasks for building {help_part}"
coll["build"].__doc__ = f"Build {help_part}"
return coll
# Usage doc/API site (published as e.g. docs.myproject.org)
docs = _site("docs", "the main site.")
write = _site("write", "the main site.")
# ns = Collection(docs, write)