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