Debian Codegraph @

make.py

raw symbols SCIP
1 #!/usr/bin/env python
2 import os
3 import os.path as op
4 import sys
5 import shutil
6 import webbrowser
7
8 THIS_DIR = op.dirname(op.abspath(__file__))
9 DOC_DIR = op.join(THIS_DIR, 'doc')
10 DIST_DIR = op.join(THIS_DIR, 'dist')
11
12
13 def clean():
14 """Clean up all build & test artifacts, and generated documentation."""
15 dirs = [op.join(DOC_DIR, '_build'),
16 op.join(DOC_DIR, 'api'),
17 DIST_DIR,
18 op.join(THIS_DIR, '_build'),
19 op.join(THIS_DIR, 'pyglet.egg-info'),
20 op.join(THIS_DIR, '.pytest_cache'),
21 op.join(THIS_DIR, '.mypy_cache'),
22 op.join(THIS_DIR, '.ruff_cache')]
23
24 files = [op.join(DOC_DIR, 'internal', 'build.rst')]
25
26 for d in dirs:
27 if not op.exists(d):
28 continue
29 shutil.rmtree(d, ignore_errors=True)
30 print(f" Removed: {d}")
31
32 for f in files:
33 if not op.exists(f):
34 continue
35 try:
36 os.remove(f)
37 print(f" Removed: {f}")
38 except OSError:
39 print(f" Failed to remove: {f}")
40
41
42 def docs():
43 """Generate documentation"""
44 try:
45 import sphinx.cmd.build
46 except ImportError:
47 print("The 'sphinx' package, and several dependencies are required for building documentation. "
48 "See 'doc/requirements.txt' for dependencies, and 'doc/README.md' for more information.")
49 exit(1)
50
51 # Ensure the build director exists:
52 html_dir = op.join(DOC_DIR, '_build', 'html')
53 os.makedirs(op.join(DOC_DIR, '_build', 'html'), exist_ok=True)
54
55 # Should be similar to `sphinx-build` on the CLI:
56 return_code = sphinx.cmd.build.build_main([DOC_DIR, html_dir])
57 if '--open' in sys.argv:
58 if return_code == 0:
59 webbrowser.open('file://' + op.abspath(DOC_DIR) + '/_build/html/index.html')
60 else:
61 print("Skipping --open preview due doc build failure")
62
63 exit(return_code)
64
65
66 def dist():
67 """Create files to distribute pyglet"""
68 try:
69 import flit
70 except ImportError:
71 print("The 'flit' package is required for building pyglet.")
72 exit(1)
73
74 flit.main(['build'])
75
76
77 def _print_usage():
78 print('Usage:', op.basename(sys.argv[0]), '<command>')
79 print(' where commands are:', ', '.join(avail_cmds), "\n")
80 for name, cmd in avail_cmds.items():
81 print(name, '\t', cmd.__doc__)
82
83
84 if __name__ == '__main__':
85 avail_cmds = dict(clean=clean, dist=dist, docs=docs)
86 try:
87 command = avail_cmds[sys.argv[1]]
88 except IndexError:
89 # Invalid number of arguments, just print help
90 _print_usage()
91 except KeyError:
92 print(f"Unknown command: {sys.argv[1]}\n")
93 _print_usage()
94 else:
95 command()