forked from xflr6/graphviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-docs.py
More file actions
executable file
·72 lines (53 loc) · 1.97 KB
/
build-docs.py
File metadata and controls
executable file
·72 lines (53 loc) · 1.97 KB
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
#!/usr/bin/env python3
"""Build the docs with https://www.sphinx-doc.org."""
import pathlib
import sys
import webbrowser
import sphinx.cmd.build
SOURCE = pathlib.Path('docs')
TARGET = SOURCE / '_build'
RESULT = TARGET / 'index.html'
BROWSER_OPEN = '--open'
SKIP_OPEN_RESULT = '--no-open'
DEFAULT_ARGS = [BROWSER_OPEN, '-W', '-n', '-v', str(SOURCE), str(TARGET)]
OPEN_RESULT = BROWSER_OPEN in DEFAULT_ARGS
print('run', [pathlib.Path(__file__).name] + sys.argv[1:])
args = sys.argv[1:]
if not args:
args = DEFAULT_ARGS
if SKIP_OPEN_RESULT in args:
open_result = None
args = [a for a in args
for name, value in [a.partition('=')[::2]]
if name not in (SKIP_OPEN_RESULT, BROWSER_OPEN)]
elif any(a.partition('=')[0] == BROWSER_OPEN for a in args):
open_result = RESULT
values = {value for a in args
for name, value in [a.partition('=')[::2]]
if name == BROWSER_OPEN and value}
if values:
if len(values) != 1:
raise ValueError(f'conflicting {BROWSER_OPEN}: {values}')
(value,) = values
if value:
open_result = open_result.parent / value
args = [a for a in args if a.partition('=')[0] != BROWSER_OPEN]
else:
open_result = RESULT if 'doctest' not in args else None
if not args: # no pytest args given
args = [a for a in DEFAULT_ARGS
if a != SKIP_OPEN_RESULT and a.partition('=')[0] != BROWSER_OPEN]
if args == ['-b', 'doctest']:
args += ['-W', str(SOURCE), str(SOURCE / '_doctest')]
print(f'sphinx.cmd.build.main({args})')
if (returncode := sphinx.cmd.build.main(args)):
print('', f'FAILED: returncode {returncode!r}', sep='\n')
sys.exit(returncode)
if 'doctest' not in args:
print('', f'index: {RESULT}', sep='\n')
print(f'assert {RESULT!r}.stat().st_size')
assert RESULT.stat().st_size, f'non-empty {RESULT}'
print('', 'PASSED.', sep='\n')
if open_result:
print(f'webbrowser.open({open_result!r})')
webbrowser.open(open_result)