|
15 | 15 | import sys
|
16 | 16 | import os
|
17 | 17 | from pathlib import Path
|
| 18 | +import platform |
18 | 19 |
|
19 | 20 | # import subprocess
|
20 | 21 |
|
|
35 | 36 | EWS = "Edit with Spyder"
|
36 | 37 |
|
37 | 38 | KEY_S = r"Software\Python"
|
38 |
| -KEY_S0 = KEY_S + r"\PythonCore" |
| 39 | +KEY_S0 = KEY_S + r"\WinPython" # was PythonCore before PEP-0514 |
39 | 40 | KEY_S1 = KEY_S0 + r"\%s"
|
40 | 41 |
|
| 42 | +def _remove_start_menu_folder(target, current=True): |
| 43 | + "remove menu Folder for target WinPython" |
| 44 | + import importlib.util |
| 45 | + win32com_exists = importlib.util.find_spec('win32com') is not None |
| 46 | + |
| 47 | + # we return nothing if no win32com package |
| 48 | + if win32com_exists: |
| 49 | + utils.remove_winpython_start_menu_folder(current=current) |
41 | 50 |
|
42 | 51 | def _get_shortcut_data(target, current=True):
|
| 52 | + "get windows menu access, if win32com exists otherwise nothing" |
| 53 | + import importlib.util |
| 54 | + win32com_exists = importlib.util.find_spec('win32com') is not None |
| 55 | + |
| 56 | + # we return nothing if no win32com package |
| 57 | + if not win32com_exists: |
| 58 | + return [] |
43 | 59 | wpgroup = utils.create_winpython_start_menu_folder(current=current)
|
44 | 60 | wpdir = str(Path(target).parent)
|
45 | 61 | data = []
|
@@ -221,16 +237,71 @@ def register(target, current=True):
|
221 | 237 | )
|
222 | 238 |
|
223 | 239 | # PythonCore entries
|
224 |
| - short_version = utils.get_python_infos(target)[0] |
225 |
| - long_version = utils.get_python_long_version(target) |
226 |
| - key_core = (KEY_S1 % short_version) + r"\%s" |
| 240 | + python_infos = utils.get_python_infos(target) # ('3.11', 64) |
| 241 | + short_version = python_infos[0] # 3.11 from ('3.11', 64) |
| 242 | + long_version = utils.get_python_long_version(target) # 3.11.5 |
| 243 | + key_core = (KEY_S1 % short_version) + r"\%s" # Winpython\3.11 |
| 244 | + |
| 245 | + # PEP-0514 additions, with standard Python practice |
| 246 | + SupportUrl="https://winpython.github.io" |
| 247 | + SysArchitecture = platform.architecture()[0] # '64bit' |
| 248 | + SysVersion = '.'.join(platform.python_version_tuple()[:2]) # '3.11' |
| 249 | + Version = platform.python_version() # '3.11.5' |
| 250 | + |
| 251 | + # But keep consistent with past possibilities until more alignement |
| 252 | + SysArchitecture = f'{python_infos[1]}bit' # '64bit' |
| 253 | + SysVersion = short_version |
| 254 | + Version = long_version |
| 255 | + |
| 256 | + DisplayName = f'Python {Version} ({SysArchitecture})' |
| 257 | + key_short = (KEY_S1 % short_version) # WinPython\3.11 |
| 258 | + key_keys={'DisplayName':DisplayName, |
| 259 | + 'SupportUrl':SupportUrl, |
| 260 | + 'SysVersion':SysVersion, |
| 261 | + 'SysArchitecture':SysArchitecture, |
| 262 | + 'Version':Version} |
| 263 | + |
| 264 | + regkey = winreg.CreateKey(root, key_short) |
| 265 | + # see https://www.programcreek.com/python/example/106949/winreg.CreateKey |
| 266 | + # winreg.SetValueEx(key, '', reg.REG_SZ, '') |
| 267 | + for k, v in key_keys.items(): |
| 268 | + winreg.SetValueEx( |
| 269 | + regkey, |
| 270 | + k, |
| 271 | + 0, |
| 272 | + winreg.REG_SZ, |
| 273 | + v, |
| 274 | + ) |
| 275 | + winreg.CloseKey(regkey) |
| 276 | + |
| 277 | + # pep-0514 additions at InstallPathLevel |
| 278 | + ExecutablePath = python |
| 279 | + WindowedExecutablePath = pythonw |
| 280 | + |
| 281 | + key_short = key_core % "InstallPath" # WinPython\3.11\InstallPath |
| 282 | + key_keys={'ExecutablePath':ExecutablePath, |
| 283 | + 'WindowedExecutablePath':WindowedExecutablePath} |
| 284 | + |
| 285 | + regkey = winreg.CreateKey(root, key_core % "InstallPath") |
227 | 286 | winreg.SetValueEx(
|
228 |
| - winreg.CreateKey(root, key_core % "InstallPath"), |
| 287 | + regkey, |
229 | 288 | "",
|
230 | 289 | 0,
|
231 | 290 | winreg.REG_SZ,
|
232 |
| - target, |
| 291 | + target + '\\', |
233 | 292 | )
|
| 293 | + for k, v in key_keys.items(): |
| 294 | + winreg.SetValueEx( |
| 295 | + regkey, |
| 296 | + k, |
| 297 | + 0, |
| 298 | + winreg.REG_SZ, |
| 299 | + v, |
| 300 | + ) |
| 301 | + winreg.CloseKey(regkey) |
| 302 | + |
| 303 | + |
| 304 | + |
234 | 305 | winreg.SetValueEx(
|
235 | 306 | winreg.CreateKey(root, key_core % r"InstallPath\InstallGroup"),
|
236 | 307 | "",
|
@@ -330,10 +401,12 @@ def unregister(target, current=True):
|
330 | 401 | r"Unable to remove %s\%s" % (rootkey, key),
|
331 | 402 | file=sys.stderr,
|
332 | 403 | )
|
333 |
| - # Start menu shortcuts |
334 |
| - for path, desc, fname in _get_shortcut_data(target, current=current): |
335 |
| - if Path(fname).exists(): |
336 |
| - os.remove(fname) |
| 404 | + # remove menu shortcuts |
| 405 | + _remove_start_menu_folder(target, current=current) |
| 406 | + |
| 407 | + #for path, desc, fname in _get_shortcut_data(target, current=current): |
| 408 | + # if Path(fname).exists(): |
| 409 | + # os.remove(fname) |
337 | 410 |
|
338 | 411 |
|
339 | 412 | if __name__ == "__main__":
|
|
0 commit comments