forked from pyglet/pyglet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
executable file
·71 lines (58 loc) · 1.94 KB
/
make.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
#!/usr/bin/env python
import os
import os.path as op
import sys
import shutil
import webbrowser
from subprocess import call
THIS_DIR = op.dirname(op.abspath(__file__))
DOC_DIR = op.join(THIS_DIR, 'doc')
DIST_DIR = op.join(THIS_DIR, 'dist')
def clean():
"""Clean up all build & test artifacts, and generated documentation."""
dirs = [op.join(DOC_DIR, '_build'),
op.join(DOC_DIR, 'api'),
DIST_DIR,
op.join(THIS_DIR, '_build'),
op.join(THIS_DIR, 'pyglet.egg-info'),
op.join(THIS_DIR, '.pytest_cache'),
op.join(THIS_DIR, '.mypy_cache')]
files = [op.join(DOC_DIR, 'internal', 'build.rst')]
for d in dirs:
print(' Removing:', d)
shutil.rmtree(d, ignore_errors=True)
for f in files:
print(' Removing:', f)
try:
os.remove(f)
except OSError:
pass
def docs():
"""Generate documentation"""
make_bin = 'make.exe' if sys.platform == 'win32' else 'make'
html_dir = op.join(DOC_DIR, '_build', 'html')
if not op.exists(html_dir):
os.makedirs(op.join(DOC_DIR, '_build', 'html'))
call([make_bin, 'html'], cwd=DOC_DIR)
if '--open' in sys.argv:
webbrowser.open('file://' + op.abspath(DOC_DIR) + '/_build/html/index.html')
def dist():
"""Create files to distribute pyglet"""
call(['python', '-m', 'build'])
def _print_usage():
print('Usage:', op.basename(sys.argv[0]), '<command>')
print(' where commands are:', ', '.join(avail_cmds), "\n")
for name, cmd in avail_cmds.items():
print(name, '\t', cmd.__doc__)
if __name__ == '__main__':
avail_cmds = dict(clean=clean, dist=dist, docs=docs)
try:
command = avail_cmds[sys.argv[1]]
except IndexError:
# Invalid number of arguments, just print help
_print_usage()
except KeyError:
print(f"Unknown command: {sys.argv[1]}\n")
_print_usage()
else:
command()