-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate_docs
executable file
·52 lines (38 loc) · 1.47 KB
/
generate_docs
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
#!/usr/bin/env python3
"""Generate our documentation using pydoc-markdown
PYTHON_ARGCOMPLETE_OK
"""
import os
from pathlib import Path
from subprocess import CalledProcessError
from milc import cli
cli.milc_options(name='generate_docs', author='MILC', version='1.9.0')
@cli.argument('--commit', arg_only=True, action='store_true', help='Commit changes to git.')
@cli.entrypoint('Generate documentation.')
def main(cli):
doc_path = Path('docs')
doc_files = []
for file in Path('milc').glob('**/*.py'):
if file.name == '__init__.py':
continue
# Generate the markdown
module_name = str(file)[5:-3]
module_name = module_name.replace('/', '.')
cmd = ['pydoc-markdown', '-I', 'milc', '-m', module_name]
try:
result = cli.run(cmd, check=True)
except CalledProcessError as e:
cli.log.error('Could not process file %s: %s', file.name, e)
for line in e.stderr.split('\n'):
cli.log.debug(line)
continue
# Write the markdown to a file
filename = f"api_{module_name.replace('.', '_')}.md"
doc_files.append((module_name, filename))
doc_file = doc_path / filename
doc_file.write_text(result.stdout)
if cli.args.commit:
cli.run(['git', 'add', 'docs'], capture_output=False)
cli.run(['git', 'commit', '-m', '[ci] Updated API documentation'], capture_output=False)
if __name__ == '__main__':
cli()