-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_docs.py
66 lines (56 loc) · 1.6 KB
/
generate_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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import textwrap
from typing import Optional
from pipx.main import __version__
import os
from jinja2 import Environment, FileSystemLoader
def get_help(pipxcmd: Optional[str]) -> str:
if pipxcmd:
cmd = ["pipx", pipxcmd, "--help"]
else:
cmd = ["pipx", "--help"]
helptext = (
subprocess.run(cmd, stdout=subprocess.PIPE, check=True)
.stdout.decode()
.replace(os.path.expanduser("~"), "~")
)
return f"""
```
{" ".join(cmd)}
{helptext}
```
"""
params = {
"usage": get_help(None),
"runpip": get_help("runpip"),
"install": get_help("install"),
"upgrade": get_help("upgrade"),
"upgradeall": get_help("upgrade-all"),
"inject": get_help("inject"),
"uninstall": get_help("uninstall"),
"uninstallall": get_help("uninstall-all"),
"reinstallall": get_help("reinstall-all"),
"list": get_help("list"),
"run": get_help("run"),
"version": __version__,
}
warning = textwrap.dedent(
"""
<!---
Do not edit this file. This file rendered from templates/readme.md.
See Contributing for how to update this file.
--->
"""
).lstrip()
env = Environment(loader=FileSystemLoader("templates"))
with open("README.md", "w") as f:
f.write(warning)
f.write(env.get_template("readme.md").render(**params))
with open("docs/index.md", "w") as f:
f.write(warning)
f.write(env.get_template("index.md").render(**params))
with open("docs/docs.md", "w") as f:
f.write(warning)
f.write(env.get_template("docs.md").render(**params))