Debian Codegraph @

PC/layout/support/options.py

raw
1 """
2 List of optional components.
3 """
4
5 __author__ = "Steve Dower <[email protected]>"
6 __version__ = "3.8"
7
8
9 __all__ = []
10
11
12 def public(f):
13 __all__.append(f.__name__)
14 return f
15
16
17 OPTIONS = {
18 "stable": {"help": "stable ABI stub"},
19 "pip": {"help": "pip"},
20 "pip-user": {"help": "pip.ini file for default --user"},
21 "tcltk": {"help": "Tcl, Tk and tkinter"},
22 "idle": {"help": "Idle"},
23 "tests": {"help": "test suite"},
24 "tools": {"help": "tools"},
25 "venv": {"help": "venv"},
26 "dev": {"help": "headers and libs"},
27 "symbols": {"help": "symbols"},
28 "underpth": {"help": "a python._pth file", "not-in-all": True},
29 "launchers": {"help": "specific launchers"},
30 "appxmanifest": {"help": "an appxmanifest"},
31 "props": {"help": "a python.props file"},
32 "nuspec": {"help": "a python.nuspec file"},
33 "chm": {"help": "the CHM documentation"},
34 "html-doc": {"help": "the HTML documentation"},
35 "freethreaded": {"help": "freethreaded binaries", "not-in-all": True},
36 "alias": {"help": "aliased python.exe entry-point binaries"},
37 "alias3": {"help": "aliased python3.exe entry-point binaries"},
38 "alias3x": {"help": "aliased python3.x.exe entry-point binaries"},
39 "install-json": {"help": "a PyManager __install__.json file"},
40 "install-embed-json": {"help": "a PyManager __install__.json file for embeddable distro"},
41 "install-test-json": {"help": "a PyManager __install__.json for the test distro"},
42 }
43
44
45 PRESETS = {
46 "appx": {
47 "help": "APPX package",
48 "options": [
49 "stable",
50 "pip",
51 "tcltk",
52 "idle",
53 "venv",
54 "dev",
55 "launchers",
56 "appxmanifest",
57 "alias",
58 "alias3x",
59 # XXX: Disabled for now "precompile",
60 ],
61 },
62 "nuget": {
63 "help": "nuget package",
64 "options": [
65 "dev",
66 "pip",
67 "stable",
68 "venv",
69 "props",
70 "nuspec",
71 "alias",
72 ],
73 },
74 "iot": {"help": "Windows IoT Core", "options": ["alias", "stable", "pip"]},
75 "default": {
76 "help": "development kit package",
77 "options": [
78 "stable",
79 "pip",
80 "tcltk",
81 "idle",
82 "tests",
83 "venv",
84 "dev",
85 "symbols",
86 "html-doc",
87 "alias",
88 ],
89 },
90 "embed": {
91 "help": "embeddable package",
92 "options": [
93 "alias",
94 "stable",
95 "zip-lib",
96 "flat-dlls",
97 "underpth",
98 "precompile",
99 ],
100 },
101 "pymanager": {
102 "help": "PyManager package",
103 "options": [
104 "stable",
105 "pip",
106 "tcltk",
107 "idle",
108 "venv",
109 "dev",
110 "html-doc",
111 "install-json",
112 ],
113 },
114 "pymanager-test": {
115 "help": "PyManager test package",
116 "options": [
117 "stable",
118 "pip",
119 "tcltk",
120 "idle",
121 "venv",
122 "dev",
123 "html-doc",
124 "symbols",
125 "tests",
126 "install-test-json",
127 ],
128 },
129 }
130
131
132 @public
133 def get_argparse_options():
134 for opt, info in OPTIONS.items():
135 help = "When specified, includes {}".format(info["help"])
136 if info.get("not-in-all"):
137 help = "{}. Not affected by --include-all".format(help)
138
139 yield "--include-{}".format(opt), help
140
141 for opt, info in PRESETS.items():
142 help = "When specified, includes default options for {}".format(info["help"])
143 yield "--preset-{}".format(opt), help
144
145
146 def ns_get(ns, key, default=False):
147 return getattr(ns, key.replace("-", "_"), default)
148
149
150 def ns_set(ns, key, value=True):
151 k1 = key.replace("-", "_")
152 k2 = "include_{}".format(k1)
153 if hasattr(ns, k2):
154 setattr(ns, k2, value)
155 elif hasattr(ns, k1):
156 setattr(ns, k1, value)
157 else:
158 raise AttributeError("no argument named '{}'".format(k1))
159
160
161 @public
162 def update_presets(ns):
163 for preset, info in PRESETS.items():
164 if ns_get(ns, "preset-{}".format(preset)):
165 for opt in info["options"]:
166 ns_set(ns, opt)
167
168 if ns.include_all:
169 for opt in OPTIONS:
170 if OPTIONS[opt].get("not-in-all"):
171 continue
172 ns_set(ns, opt)