10000 Merge pull request #1251 from stonebig/master · winpython/winpython@97e581f · GitHub
[go: up one dir, main page]

Skip to content

Commit 97e581f

Browse files
authored
Merge pull request #1251 from stonebig/master
PEP-514 at last
2 parents a1d06ff + 9a7fecc commit 97e581f

File tree

1 file changed

+83
-10
lines changed

1 file changed

+83
-10
lines changed

winpython/associate.py

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import os
1717
from pathlib import Path
18+
import platform
1819

1920
# import subprocess
2021

@@ -35,11 +36,26 @@
3536
EWS = "Edit with Spyder"
3637

3738
KEY_S = r"Software\Python"
38-
KEY_S0 = KEY_S + r"\PythonCore"
39+
KEY_S0 = KEY_S + r"\WinPython" # was PythonCore before PEP-0514
3940
KEY_S1 = KEY_S0 + r"\%s"
4041

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)
4150

4251
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 []
4359
wpgroup = utils.create_winpython_start_menu_folder(current=current)
4460
wpdir = str(Path(target).parent)
4561
data = []
@@ -221,16 +237,71 @@ def register(target, current=True):
221237
)
222238

223239
# 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")
227286
winreg.SetValueEx(
228-
winreg.CreateKey(root, key_core % "InstallPath"),
287+
regkey,
229288
"",
230289
0,
231290
winreg.REG_SZ,
232-
target,
291+
target + '\\',
233292
)
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+
234305
winreg.SetValueEx(
235306
winreg.CreateKey(root, key_core % r"InstallPath\InstallGroup"),
236307
"",
@@ -330,10 +401,12 @@ def unregister(target, current=True):
330401
r"Unable to remove %s\%s" % (rootkey, key),
331402
file=sys.stderr,
332403
)
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)
337410

338411

339412
if __name__ == "__main__":

0 commit comments

Comments
 (0)
0