• 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    "underpth": {"help": "a python._pth file", "not-in-all": True},
30    "launchers": {"help": "specific launchers"},
31    "appxmanifest": {"help": "an appxmanifest"},
32    "props": {"help": "a python.props file"},
33    "nuspec": {"help": "a python.nuspec file"},
34    "chm": {"help": "the CHM documentation"},
35    "html-doc": {"help": "the HTML documentation"},
36}
37
38
39PRESETS = {
40    "appx": {
41        "help": "APPX package",
42        "options": [
43            "stable",
44            "pip",
45            "pip-user",
46            "distutils",
47            "tcltk",
48            "idle",
49            "venv",
50            "dev",
51            "launchers",
52            "appxmanifest",
53            # XXX: Disabled for now "precompile",
54        ],
55    },
56    "nuget": {
57        "help": "nuget package",
58        "options": [
59            "dev",
60            "tools",
61            "pip",
62            "stable",
63            "distutils",
64            "venv",
65            "props",
66            "nuspec",
67        ],
68    },
69    "iot": {"help": "Windows IoT Core", "options": ["stable", "pip"]},
70    "default": {
71        "help": "development kit package",
72        "options": [
73            "stable",
74            "pip",
75            "distutils",
76            "tcltk",
77            "idle",
78            "tests",
79            "tools",
80            "venv",
81            "dev",
82            "symbols",
83            "chm",
84        ],
85    },
86    "embed": {
87        "help": "embeddable package",
88        "options": ["stable", "zip-lib", "flat-dlls", "underpth", "precompile"],
89    },
90}
91
92
93@public
94def get_argparse_options():
95    for opt, info in OPTIONS.items():
96        help = "When specified, includes {}".format(info["help"])
97        if info.get("not-in-all"):
98            help = "{}. Not affected by --include-all".format(help)
99
100        yield "--include-{}".format(opt), help
101
102    for opt, info in PRESETS.items():
103        help = "When specified, includes default options for {}".format(info["help"])
104        yield "--preset-{}".format(opt), help
105
106
107def ns_get(ns, key, default=False):
108    return getattr(ns, key.replace("-", "_"), default)
109
110
111def ns_set(ns, key, value=True):
112    k1 = key.replace("-", "_")
113    k2 = "include_{}".format(k1)
114    if hasattr(ns, k2):
115        setattr(ns, k2, value)
116    elif hasattr(ns, k1):
117        setattr(ns, k1, value)
118    else:
119        raise AttributeError("no argument named '{}'".format(k1))
120
121
122@public
123def update_presets(ns):
124    for preset, info in PRESETS.items():
125        if ns_get(ns, "preset-{}".format(preset)):
126            for opt in info["options"]:
127                ns_set(ns, opt)
128
129    if ns.include_all:
130        for opt in OPTIONS:
131            if OPTIONS[opt].get("not-in-all"):
132                continue
133            ns_set(ns, opt)
134