-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathrun-pdoc3.py
More file actions
64 lines (58 loc) · 2.19 KB
/
run-pdoc3.py
File metadata and controls
64 lines (58 loc) · 2.19 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
#!/usr/bin/env python3
"""
Generates the refinery documentation.
"""
import argparse
import os
import warnings
import subprocess
import sys
import shutil
_SAFETY_FLAG = '--current-environment'
_TEMPLATEDIR = os.path.abspath('pdoc3-template')
_DOCUMENTDIR = os.path.abspath('html')
if __name__ == '__main__':
def venv(path):
path = os.path.abspath(path)
if not os.path.isdir(path):
raise argparse.ArgumentTypeError(F'not a directory: {path}')
p = os.path.join(path, 'bin', 'python') if os.name != 'nt' else (
os.path.join(path, 'Scripts', 'python.exe')
)
if not os.path.exists(p):
raise argparse.ArgumentTypeError(F'interpreter not found: {p}')
return p
argp = argparse.ArgumentParser()
where = argp.add_mutually_exclusive_group()
where.add_argument('venv', nargs='?', type=venv, default=None,
help='Specify the virtual environment to use.')
where.add_argument(_SAFETY_FLAG, dest='safety', action='store_true', help=(
'If no virtual environment is specified, you have to provide this '
'flag to force use of the current environment. This flag exists to '
'prevent users from accidentally running this script outside a '
'virtual environment.'
))
args = argp.parse_args()
if args.venv:
virtualized = subprocess.Popen([args.venv, __file__, _SAFETY_FLAG])
sys.exit(virtualized.wait())
elif not args.safety:
argp.error(F'You have to either specify a virtual environment or provide the flag {_SAFETY_FLAG}.')
for second_attempt in (False, True):
try:
from pdoc.cli import main as pdoc3_main
except ImportError:
if second_attempt:
raise
subprocess.check_call(
[sys.executable, '-m', 'pip', 'install', 'pdoc3'])
else:
warnings.filterwarnings('ignore')
sys.argv = [
'pdoc3', '--html', '--force', '--template-dir', _TEMPLATEDIR, 'refinery']
pdoc3_main()
break
shutil.copyfile(
os.path.join(_TEMPLATEDIR, 'FixedSysEx.ttf'),
os.path.join(_DOCUMENTDIR, 'refinery', 'FixedSysEx.ttf')
)