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 DISPLAY_TAG = f"{XY_TAG}-dev{TAG_ARCH}" if VER_SUFFIX else XY_ARCH_TAG
85 # Tag used for PEP 514 registration
86 SYS_WINVER = XY_TAG + (TAG_ARCH if TAG_ARCH != '-64' else '')
87
88 DISPLAY_SUFFIX = ", ".join(i for i in DISPLAY_TAGS if i)
89 if DISPLAY_SUFFIX:
90 DISPLAY_SUFFIX = f" ({DISPLAY_SUFFIX})"
91 DISPLAY_VERSION = f"{XYZ_VERSION}{VER_SUFFIX}{DISPLAY_SUFFIX}"
92
93 STD_RUN_FOR = []
94 STD_ALIAS = []
95 STD_PEP514 = []
96 STD_START = []
97 STD_UNINSTALL = []
98
99 # The list of 'py install <TAG>' tags that will match this runtime.
100 # Architecture should always be included here because PyManager will add it.
101 INSTALL_TAGS = [
102 FULL_ARCH_TAG,
103 XY_ARCH_TAG,
104 X_ARCH_TAG,
105 # X_TAG and XY_TAG doesn't include VER_SUFFIX, so create -dev versions
106 f"{XY_TAG}-dev{TAG_ARCH}" if XY_TAG and VER_SUFFIX else "",
107 f"{X_TAG}-dev{TAG_ARCH}" if X_TAG and VER_SUFFIX else "",
108 ]
109
110 # Generate run-for entries for each target.
111 # Again, include architecture because PyManager will add it.
112 for base in [
113 {"target": TARGET},
114 {"target": TARGETW, "windowed": 1},
115 ]:
116 if not base["target"]:
117 continue
118 STD_RUN_FOR.append({**base, "tag": FULL_ARCH_TAG})
119 if XY_TAG:
120 STD_RUN_FOR.append({**base, "tag": XY_ARCH_TAG})
121 if X_TAG:
122 STD_RUN_FOR.append({**base, "tag": X_ARCH_TAG})
123 if VER_SUFFIX:
124 STD_RUN_FOR.extend([
125 {**base, "tag": f"{XY_TAG}-dev{TAG_ARCH}" if XY_TAG else ""},
126 {**base, "tag": f"{X_TAG}-dev{TAG_ARCH}" if X_TAG else ""},
127 ])
128
129 # Generate alias entries for each target. We need both arch and non-arch
130 # versions as well as windowed/non-windowed versions to make sure that all
131 # necessary aliases are created.
132 for prefix, base in (
133 (ALIAS_PREFIX, {"target": TARGET}),
134 (ALIAS_WPREFIX, {"target": TARGETW, "windowed": 1}),
135 ):
136 if not prefix:
137 continue
138 if not base["target"]:
139 continue
140 if XY_TAG:
141 STD_ALIAS.extend([
142 {**base, "name": f"{prefix}{XY_TAG}.exe"},
143 {**base, "name": f"{prefix}{XY_ARCH_TAG}.exe"},
144 ])
145 if X_TAG:
146 STD_ALIAS.extend([
147 {**base, "name": f"{prefix}{X_TAG}.exe"},
148 {**base, "name": f"{prefix}{X_ARCH_TAG}.exe"},
149 ])
150
151 if SYS_WINVER:
152 STD_PEP514.append({
153 "kind": "pep514",
154 "Key": rf"{COMPANY}\{SYS_WINVER}",
155 "DisplayName": f"{DISPLAY_NAME} {DISPLAY_VERSION}",
156 "SupportUrl": "https://www.python.org/",
157 "SysArchitecture": SYS_ARCH,
158 "SysVersion": VER_DOT,
159 "Version": FULL_VERSION,
160 "InstallPath": {
161 "_": "%PREFIX%",
162 "ExecutablePath": f"%PREFIX%{TARGET}",
163 # WindowedExecutablePath is added below
164 },
165 "Help": {
166 "Online Python Documentation": {
167 "_": f"https://docs.python.org/{VER_DOT}/"
168 },
169 },
170 })
171
172 STD_START.append({
173 "kind": "start",
174 "Name": f"{DISPLAY_NAME} {VER_DOT}{DISPLAY_SUFFIX}",
175 "Items": [
176 {
177 "Name": f"{DISPLAY_NAME} {VER_DOT}{DISPLAY_SUFFIX}",
178 "Target": f"%PREFIX%{TARGET}",
179 "Icon": f"%PREFIX%{TARGET}",
180 },
181 {
182 "Name": f"{DISPLAY_NAME} {VER_DOT} Online Documentation",
183 "Icon": r"%SystemRoot%\System32\SHELL32.dll",
184 "IconIndex": 13,
185 "Target": f"https://docs.python.org/{VER_DOT}/",
186 },
187 # IDLE and local documentation items are added below
188 ],
189 })
190
191 if TARGETW and STD_PEP514:
192 STD_PEP514[0]["InstallPath"]["WindowedExecutablePath"] = f"%PREFIX%{TARGETW}"
193
194 if ns.include_idle:
195 STD_START[0]["Items"].append({
196 "Name": f"IDLE (Python {VER_DOT}{DISPLAY_SUFFIX})",
197 "Target": f"%PREFIX%{TARGETW or TARGET}",
198 "Arguments": r'"%PREFIX%Lib\idlelib\idle.pyw"',
199 "Icon": r"%PREFIX%Lib\idlelib\Icons\idle.ico",
200 "IconIndex": 0,
201 })
202 STD_START[0]["Items"].append({
203 "Name": f"PyDoc (Python {VER_DOT}{DISPLAY_SUFFIX})",
204 "Target": f"%PREFIX%{TARGET}",
205 "Arguments": "-m pydoc -b",
206 "Icon": r"%PREFIX%Lib\idlelib\Icons\idle.ico",
207 "IconIndex": 0,
208 })
209 if STD_PEP514:
210 STD_PEP514[0]["InstallPath"]["IdlePath"] = f"%PREFIX%Lib\\idlelib\\idle.pyw"
211
212 if ns.include_html_doc:
213 STD_PEP514[0]["Help"]["Main Python Documentation"] = {
214 "_": rf"%PREFIX%Doc\html\index.html",
215 }
216 STD_START[0]["Items"].append({
217 "Name": f"{DISPLAY_NAME} {VER_DOT} Manuals{DISPLAY_SUFFIX}",
218 "Target": r"%PREFIX%Doc\html\index.html",
219 })
220 elif ns.include_chm:
221 STD_PEP514[0]["Help"]["Main Python Documentation"] = {
222 "_": rf"%PREFIX%Doc\{PYTHON_CHM_NAME}",
223 }
224 STD_START[0]["Items"].append({
225 "Name": f"{DISPLAY_NAME} {VER_DOT} Manuals{DISPLAY_SUFFIX}",
226 "Target": "%WINDIR%hhc.exe",
227 "Arguments": rf"%PREFIX%Doc\{PYTHON_CHM_NAME}",
228 })
229
230 STD_UNINSTALL.append({
231 "kind": "uninstall",
232 # Other settings will pick up sensible defaults
233 "Publisher": "Python Software Foundation",
234 "HelpLink": f"https://docs.python.org/{VER_DOT}/",
235 })
236
237 data = {
238 "schema": 1,
239 "id": f"{COMPANY.lower()}-{ID_TAG}",
240 "sort-version": FULL_VERSION,
241 "company": COMPANY,
242 "tag": DISPLAY_TAG,
243 "install-for": _not_empty(INSTALL_TAGS),
244 "run-for": _not_empty(STD_RUN_FOR, "tag"),
245 "alias": _not_empty(STD_ALIAS, "name"),
246 "shortcuts": [
247 *STD_PEP514,
248 *STD_START,
249 *STD_UNINSTALL,
250 ],
251 "display-name": f"{DISPLAY_NAME} {DISPLAY_VERSION}",
252 "executable": rf".\{TARGET}",
253 "url": f"{URL_BASE}{XYZ_VERSION}/{FILE_PREFIX}{FULL_VERSION}{FILE_SUFFIX}.zip"
254 }
255
256 return data