• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2List of optional components.
3"""
4
5__author__ = "Steve Dower <steve.dower@python.org>"
6__version__ = "3.8"
7
8
9__all__ = []
10
11
12def public(f):
13    __all__.append(f.__name__)
14    return f
15
16
17OPTIONS = {
18    "stable": {"help": "stable ABI stub"},
19    "pip": {"help": "pip"},
20    "pip-user": {"help": "pip.ini file for default --user"},
21    "distutils": {"help": "distutils"},
22    "tcltk": {"help": "Tcl, Tk and tkinter"},
23    "idle": {"help": "Idle"},
24    "tests": {"help": "test suite"},
25    "tools": {"help": "tools"},
26    "venv": {"help": "venv"},
27    "dev": {"help": "headers and libs"},
28    "symbols": {"help": "symbols"},
29    "bdist-wininst": {"help": "bdist_wininst support"},
30    "underpth": {"help": "a python._pth file", "not-in-all": True},
31    "launchers": {"help": "specific launchers"},
32    "appxmanifest": {"help": "an appxmanifest"},
33    "props": {"help": "a python.props file"},
34    "nuspec": {"help": "a python.nuspec file"},
35    "chm": {"help": "the CHM documentation"},
36    "html-doc": {"help": "the HTML documentation"},
37}
38
39
40PRESETS = {
41    "appx": {
42        "help": "APPX package",
43        "options": [
44            "stable",
45            "pip",
46            "pip-user",
47            "distutils",
48            "tcltk",
49            "idle",
50            "venv",
51            "dev",
52            "launchers",
53            "appxmanifest",
54            # XXX: Disabled for now "precompile",
55        ],
56    },
57    "nuget": {
58        "help": "nuget package",
59        "options": [
60            "dev",
61            "tools",
62            "pip",
63            "stable",
64            "distutils",
65            "venv",
66            "props",
67            "nuspec",
68        ],
69    },
70    "iot": {"help": "Windows IoT Core", "options": ["stable", "pip"]},
71    "default": {
72        "help": "development kit package",
73        "options": [
74            "stable",
75            "pip",
76            "distutils",
77            "tcltk",
78            "idle",
79            "tests",
80            "tools",
81            "venv",
82            "dev",
83            "symbols",
84            "bdist-wininst",
85            "chm",
86        ],
87    },
88    "embed": {
89        "help": "embeddable package",
90        "options": ["stable", "zip-lib", "flat-dlls", "underpth", "precompile"],
91    },
92}
93
94
95@public
96def get_argparse_options():
97    for opt, info in OPTIONS.items():
98        help = "When specified, includes {}".format(info["help"])
99        if info.get("not-in-all"):
100            help = "{}. Not affected by --include-all".format(help)
101
102        yield "--include-{}".format(opt), help
103
104    for opt, info in PRESETS.items():
105        help = "When specified, includes default options for {}".format(info["help"])
106        yield "--preset-{}".format(opt), help
107
108
109def ns_get(ns, key, default=False):
110    return getattr(ns, key.replace("-", "_"), default)
111
112
113def ns_set(ns, key, value=True):
114    k1 = key.replace("-", "_")
115    k2 = "include_{}".format(k1)
116    if hasattr(ns, k2):
117        setattr(ns, k2, value)
118    elif hasattr(ns, k1):
119        setattr(ns, k1, value)
120    else:
121        raise AttributeError("no argument named '{}'".format(k1))
122
123
124@public
125def update_presets(ns):
126    for preset, info in PRESETS.items():
127        if ns_get(ns, "preset-{}".format(preset)):
128            for opt in info["options"]:
129                ns_set(ns, opt)
130
131    if ns.include_all:
132        for opt in OPTIONS:
133            if OPTIONS[opt].get("not-in-all"):
134                continue
135            ns_set(ns, opt)
136