Debian Codegraph @

PC/layout/support/pymanager.py

raw
1 from .constants import *
2
3 URL_BASE = "https://www.python.org/ftp/python/"
4
5 XYZ_VERSION = f"{VER_MAJOR}.{VER_MINOR}.{VER_MICRO}"
6 WIN32_VERSION = f"{VER_MAJOR}.{VER_MINOR}.{VER_MICRO}.{VER_FIELD4}"
7 FULL_VERSION = f"{VER_MAJOR}.{VER_MINOR}.{VER_MICRO}{VER_SUFFIX}"
8
9
10 def _not_empty(n, key=None):
11 result = []
12 for i in n:
13 if key:
14 i_l = i[key]
15 else:
16 i_l = i
17 if not i_l:
18 continue
19 result.append(i)
20 return result
21
22
23 def calculate_install_json(ns, *, for_embed=False, for_test=False):
24 TARGET = "python.exe"
25 TARGETW = "pythonw.exe"
26
27 SYS_ARCH = {
28 "win32": "32bit",
29 "amd64": "64bit",
30 "arm64": "64bit", # Unfortunate, but this is how it's spec'd
31 }[ns.arch]
32 TAG_ARCH = {
33 "win32": "-32",
34 "amd64": "-64",
35 "arm64": "-arm64",
36 }[ns.arch]
37
38 COMPANY = "PythonCore"
39 DISPLAY_NAME = "Python"
40 TAG_SUFFIX = ""
41 ALIAS_PREFIX = "python"
42 ALIAS_WPREFIX = "pythonw"
43 FILE_PREFIX = "python-"
44 FILE_SUFFIX = f"-{ns.arch}"
45 DISPLAY_TAGS = [{
46 "win32": "32-bit",
47 "amd64": "",
48 "arm64": "ARM64",
49 }[ns.arch]]
50
51 if for_test:
52 # Packages with the test suite come under a different Company
53 COMPANY = "PythonTest"
54 DISPLAY_TAGS.append("with tests")
55 FILE_SUFFIX = f"-test-{ns.arch}"
56 if for_embed:
57 # Embeddable distro comes under a different Company
58 COMPANY = "PythonEmbed"
59 TARGETW = None
60 ALIAS_PREFIX = None
61 ALIAS_WPREFIX = None
62 DISPLAY_TAGS.append("embeddable")
63 # Deliberately name the file differently from the existing distro
64 # so we can republish old versions without replacing files.
65 FILE_SUFFIX = f"-embeddable-{ns.arch}"
66 if ns.include_freethreaded:
67 # Free-threaded distro comes with a tag suffix
68 TAG_SUFFIX = "t"
69 TARGET = f"python{VER_MAJOR}.{VER_MINOR}t.exe"
70 TARGETW = f"pythonw{VER_MAJOR}.{VER_MINOR}t.exe"
71 DISPLAY_TAGS.append("free-threaded")
72 FILE_SUFFIX = f"t-{ns.arch}"
73
74 FULL_TAG = f"{VER_MAJOR}.{VER_MINOR}.{VER_MICRO}{VER_SUFFIX}{TAG_SUFFIX}"
75 FULL_ARCH_TAG = f"{FULL_TAG}{TAG_ARCH}"
76 XY_TAG = f"{VER_MAJOR}.{VER_MINOR}{TAG_SUFFIX}"
77 XY_ARCH_TAG = f"{XY_TAG}{TAG_ARCH}"
78 X_TAG = f"{VER_MAJOR}{TAG_SUFFIX}"
79 X_ARCH_TAG = f"{X_TAG}{TAG_ARCH}"
80
81 # Tag used in runtime ID (for side-by-side install/updates)
82 ID_TAG = XY_ARCH_TAG
83 # Tag shown in 'py list' output.
84 # gh-139810: We only include '-dev' here for prereleases, even though it
85 # works for final releases too.
86 DISPLAY_TAG = f"{XY_TAG}-dev{TAG_ARCH}" if VER_SUFFIX else XY_ARCH_TAG
87 # Tag used for PEP 514 registration
88 SYS_WINVER = XY_TAG + (TAG_ARCH if TAG_ARCH != '-64' else '')
89
90 DISPLAY_SUFFIX = ", ".join(i for i in DISPLAY_TAGS if i)
91 if DISPLAY_SUFFIX:
92 DISPLAY_SUFFIX = f" ({DISPLAY_SUFFIX})"
93 DISPLAY_VERSION = f"{XYZ_VERSION}{VER_SUFFIX}{DISPLAY_SUFFIX}"
94
95 STD_RUN_FOR = []
96 STD_ALIAS = []
97 STD_PEP514 = []
98 STD_START = []
99 STD_UNINSTALL = []
100
101 # The list of 'py install <TAG>' tags that will match this runtime.
102 # Architecture should always be included here because PyManager will add it.
103 INSTALL_TAGS = [
104 FULL_ARCH_TAG,
105 XY_ARCH_TAG,
106 X_ARCH_TAG,
107 # gh-139810: The -dev tags are always included so that the latest
108 # release is chosen, no matter whether it's prerelease or final.
109 f"{XY_TAG}-dev{TAG_ARCH}" if XY_TAG else "",
110 f"{X_TAG}-dev{TAG_ARCH}" if X_TAG else "",
111 ]
112
113 # Generate run-for entries for each target.
114 # Again, include architecture because PyManager will add it.
115 for base in [
116 {"target": TARGET},
117 {"target": TARGETW, "windowed": 1},
118 ]:
119 if not base["target"]:
120 continue
121 STD_RUN_FOR.extend([
122 {**base, "tag": FULL_ARCH_TAG},
123 {**base, "tag": f"{XY_TAG}-dev{TAG_ARCH}" if XY_TAG else ""},
124 {**base, "tag": f"{X_TAG}-dev{TAG_ARCH}" if X_TAG else ""},
125 ])
126 if XY_TAG:
127 STD_RUN_FOR.append({**base, "tag": XY_ARCH_TAG})
128 if X_TAG:
129 STD_RUN_FOR.append({**base, "tag": X_ARCH_TAG})
130
131 # Generate alias entries for each target. We need both arch and non-arch
132 # versions as well as windowed/non-windowed versions to make sure that all
133 # necessary aliases are created.
134 for prefix, base in (
135 (ALIAS_PREFIX, {"target": TARGET}),
136 (ALIAS_WPREFIX, {"target": TARGETW, "windowed": 1}),
137 ):
138 if not prefix:
139 continue
140 if not base["target"]:
141 continue
142 if XY_TAG:
143 STD_ALIAS.extend([
144 {**base, "name": f"{prefix}{XY_TAG}.exe"},
145 {**base, "name": f"{prefix}{XY_ARCH_TAG}.exe"},
146 ])
147 if X_TAG:
148 STD_ALIAS.extend([
149 {**base, "name": f"{prefix}{X_TAG}.exe"},
150 {**base, "name": f"{prefix}{X_ARCH_TAG}.exe"},
151 ])
152
153 if SYS_WINVER:
154 STD_PEP514.append({
155 "kind": "pep514",
156 "Key": rf"{COMPANY}\{SYS_WINVER}",
157 "DisplayName": f"{DISPLAY_NAME} {DISPLAY_VERSION}",
158 "SupportUrl": "https://www.python.org/",
159 "SysArchitecture": SYS_ARCH,
160 "SysVersion": VER_DOT,
161 "Version": FULL_VERSION,
162 "InstallPath": {
163 "_": "%PREFIX%",
164 "ExecutablePath": f"%PREFIX%{TARGET}",
165 # WindowedExecutablePath is added below
166 },
167 "Help": {
168 "Online Python Documentation": {
169 "_": f"https://docs.python.org/{VER_DOT}/"
170 },
171 },
172 })
173
174 STD_START.append({
175 "kind": "start",
176 "Name": f"{DISPLAY_NAME} {VER_DOT}{DISPLAY_SUFFIX}",
177 "Items": [
178 {
179 "Name": f"{DISPLAY_NAME} {VER_DOT}{DISPLAY_SUFFIX}",
180 "Target": f"%PREFIX%{TARGET}",
181 "Icon": f"%PREFIX%{TARGET}",
182 },
183 {
184 "Name": f"{DISPLAY_NAME} {VER_DOT} Online Documentation",
185 "Icon": r"%SystemRoot%\System32\SHELL32.dll",
186 "IconIndex": 13,
187 "Target": f"https://docs.python.org/{VER_DOT}/",
188 },
189 # IDLE and local documentation items are added below
190 ],
191 })
192
193 if TARGETW and STD_PEP514:
194 STD_PEP514[0]["InstallPath"]["WindowedExecutablePath"] = f"%PREFIX%{TARGETW}"
195
196 if ns.include_idle:
197 STD_START[0]["Items"].append({
198 "Name": f"IDLE (Python {VER_DOT}{DISPLAY_SUFFIX})",
199 "Target": f"%PREFIX%{TARGETW or TARGET}",
200 "Arguments": r'"%PREFIX%Lib\idlelib\idle.pyw"',
201 "Icon": r"%PREFIX%Lib\idlelib\Icons\idle.ico",
202 "IconIndex": 0,
203 })
204 STD_START[0]["Items"].append({
205 "Name": f"PyDoc (Python {VER_DOT}{DISPLAY_SUFFIX})",
206 "Target": f"%PREFIX%{TARGET}",
207 "Arguments": "-m pydoc -b",
208 "Icon": r"%PREFIX%Lib\idlelib\Icons\idle.ico",
209 "IconIndex": 0,
210 })
211 if STD_PEP514:
212 STD_PEP514[0]["InstallPath"]["IdlePath"] = f"%PREFIX%Lib\\idlelib\\idle.pyw"
213
214 if ns.include_html_doc:
215 STD_PEP514[0]["Help"]["Main Python Documentation"] = {
216 "_": rf"%PREFIX%Doc\html\index.html",
217 }
218 STD_START[0]["Items"].append({
219 "Name": f"{DISPLAY_NAME} {VER_DOT} Manuals{DISPLAY_SUFFIX}",
220 "Target": r"%PREFIX%Doc\html\index.html",
221 })
222 elif ns.include_chm:
223 STD_PEP514[0]["Help"]["Main Python Documentation"] = {
224 "_": rf"%PREFIX%Doc\{PYTHON_CHM_NAME}",
225 }
226 STD_START[0]["Items"].append({
227 "Name": f"{DISPLAY_NAME} {VER_DOT} Manuals{DISPLAY_SUFFIX}",
228 "Target": "%WINDIR%hhc.exe",
229 "Arguments": rf"%PREFIX%Doc\{PYTHON_CHM_NAME}",
230 })
231
232 STD_UNINSTALL.append({
233 "kind": "uninstall",
234 # Other settings will pick up sensible defaults
235 "Publisher": "Python Software Foundation",
236 "HelpLink": f"https://docs.python.org/{VER_DOT}/",
237 })
238
239 data = {
240 "schema": 1,
241 "id": f"{COMPANY.lower()}-{ID_TAG}",
242 "sort-version": FULL_VERSION,
243 "company": COMPANY,
244 "tag": DISPLAY_TAG,
245 "install-for": _not_empty(INSTALL_TAGS),
246 "run-for": _not_empty(STD_RUN_FOR, "tag"),
247 "alias": _not_empty(STD_ALIAS, "name"),
248 "shortcuts": [
249 *STD_PEP514,
250 *STD_START,
251 *STD_UNINSTALL,
252 ],
253 "display-name": f"{DISPLAY_NAME} {DISPLAY_VERSION}",
254 "executable": rf".\{TARGET}",
255 "url": f"{URL_BASE}{XYZ_VERSION}/{FILE_PREFIX}{FULL_VERSION}{FILE_SUFFIX}.zip"
256 }
257
258 return data