1515import sys
1616import os
1717from pathlib import Path
18+
1819# import subprocess
1920
2021
4041
4142
4243def _get_shortcut_data (target , current = True ):
43- wpgroup = utils .create_winpython_start_menu_folder (
44- current = current
45- )
44+ wpgroup = utils .create_winpython_start_menu_folder (current = current )
4645 wpdir = str (Path (target ).parent )
4746 data = []
4847 for name in os .listdir (wpdir ):
4948 bname , ext = Path (name ).stem , Path (name ).suffix
50- if ext == ' .exe' :
49+ if ext == " .exe" :
5150 data .append (
5251 (
5352 str (Path (wpdir ) / name ),
@@ -60,11 +59,7 @@ def _get_shortcut_data(target, current=True):
6059
6160def register (target , current = True ):
6261 """Register a Python distribution in Windows registry"""
63- root = (
64- winreg .HKEY_CURRENT_USER
65- if current
66- else winreg .HKEY_LOCAL_MACHINE
67- )
62+ root = winreg .HKEY_CURRENT_USER if current else winreg .HKEY_LOCAL_MACHINE
6863
6964 # Extensions
7065 winreg .SetValueEx (
@@ -113,9 +108,9 @@ def register(target, current=True):
113108 )
114109
115110 # Verbs
116- python = str ((Path (target ) / ' python.exe' ).resolve ())
117- pythonw = str ((Path (target ) / ' pythonw.exe' ).resolve ())
118- spyder = str ((Path (target ).parent / ' Spyder.exe' ).resolve ())
111+ python = str ((Path (target ) / " python.exe" ).resolve ())
112+ pythonw = str ((Path (target ) / " pythonw.exe" ).resolve ())
113+ spyder = str ((Path (target ).parent / " Spyder.exe" ).resolve ())
119114
120115 if not Path (spyder ).is_file ():
121116 spyder = f'{ pythonw } " "{ target } \Scripts\spyder'
@@ -134,9 +129,7 @@ def register(target, current=True):
134129 '"%s" "%%1" %%*' % pythonw ,
135130 )
136131 winreg .SetValueEx (
137- winreg .CreateKey (
138- root , KEY_C2 % ("Compiled" , "open" )
139- ),
132+ winreg .CreateKey (root , KEY_C2 % ("Compiled" , "open" )),
140133 "" ,
141134 0 ,
142135 winreg .REG_SZ ,
@@ -147,16 +140,14 @@ def register(target, current=True):
147140 "" ,
148141 0 ,
149142 winreg .REG_SZ ,
150- '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"'
151- % (pythonw , target ),
143+ '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"' % (pythonw , target ),
152144 )
153145 winreg .SetValueEx (
154146 winreg .CreateKey (root , KEY_C2 % ("NoCon" , EWI )),
155147 "" ,
156148 0 ,
157149 winreg .REG_SZ ,
158- '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"'
159- % (pythonw , target ),
150+ '"%s" "%s\Lib\idlelib\idle.pyw" -n -e "%%1"' % (pythonw , target ),
160151 )
161152 winreg .SetValueEx (
162153 winreg .CreateKey (root , KEY_C2 % ("" , EWS )),
@@ -184,27 +175,27 @@ def register(target, current=True):
184175 handler ,
185176 )
186177 # Icons
187- dlls = str (Path (target ) / ' DLLs' )
178+ dlls = str (Path (target ) / " DLLs" )
188179 winreg .SetValueEx (
189180 winreg .CreateKey (root , KEY_I % "" ),
190181 "" ,
191182 0 ,
192183 winreg .REG_SZ ,
193- r' %s\py.ico' % dlls ,
184+ r" %s\py.ico" % dlls ,
194185 )
195186 winreg .SetValueEx (
196187 winreg .CreateKey (root , KEY_I % "NoCon" ),
197188 "" ,
198189 0 ,
199190 winreg .REG_SZ ,
200- r' %s\py.ico' % dlls ,
191+ r" %s\py.ico" % dlls ,
201192 )
202193 winreg .SetValueEx (
203194 winreg .CreateKey (root , KEY_I % "Compiled" ),
204195 "" ,
205196 0 ,
206197 winreg .REG_SZ ,
207- r' %s\pyc.ico' % dlls ,
198+ r" %s\pyc.ico" % dlls ,
208199 )
209200
210201 # Descriptions
@@ -233,32 +224,30 @@ def register(target, current=True):
233224 # PythonCore entries
234225 short_version = utils .get_python_infos (target )[0 ]
235226 long_version = utils .get_python_long_version (target )
236- key_core = (KEY_S1 % short_version ) + r' \%s'
227+ key_core = (KEY_S1 % short_version ) + r" \%s"
237228 winreg .SetValueEx (
238- winreg .CreateKey (root , key_core % ' InstallPath' ),
229+ winreg .CreateKey (root , key_core % " InstallPath" ),
239230 "" ,
240231 0 ,
241232 winreg .REG_SZ ,
242233 target ,
243234 )
244235 winreg .SetValueEx (
245- winreg .CreateKey (
246- root , key_core % r'InstallPath\InstallGroup'
247- ),
236+ winreg .CreateKey (root , key_core % r"InstallPath\InstallGroup" ),
248237 "" ,
249238 0 ,
250239 winreg .REG_SZ ,
251240 "Python %s" % short_version ,
252241 )
253242 winreg .SetValueEx (
254- winreg .CreateKey (root , key_core % ' Modules' ),
243+ winreg .CreateKey (root , key_core % " Modules" ),
255244 "" ,
256245 0 ,
257246 winreg .REG_SZ ,
258247 "" ,
259248 )
260249 winreg .SetValueEx (
261- winreg .CreateKey (root , key_core % ' PythonPath' ),
250+ winreg .CreateKey (root , key_core % " PythonPath" ),
262251 "" ,
263252 0 ,
264253 winreg .REG_SZ ,
@@ -267,7 +256,7 @@ def register(target, current=True):
267256 winreg .SetValueEx (
268257 winreg .CreateKey (
269258 root ,
270- key_core % r' Help\Main Python Documentation' ,
259+ key_core % r" Help\Main Python Documentation" ,
271260 ),
272261 "" ,
273262 0 ,
@@ -276,21 +265,16 @@ def register(target, current=True):
276265 )
277266
278267 # Create start menu entries for all WinPython launchers
279- for path , desc , fname in _get_shortcut_data (
280- target , current = current
281- ):
268+ for path , desc , fname in _get_shortcut_data (target , current = current ):
282269 utils .create_shortcut (path , desc , fname )
283270
271+
284272def unregister (target , current = True ):
285273 """Unregister a Python distribution in Windows registry"""
286274 # Registry entries
287- root = (
288- winreg .HKEY_CURRENT_USER
289- if current
290- else winreg .HKEY_LOCAL_MACHINE
291- )
275+ root = winreg .HKEY_CURRENT_USER if current else winreg .HKEY_LOCAL_MACHINE
292276 short_version = utils .get_python_infos (target )[0 ]
293- key_core = (KEY_S1 % short_version ) + r' \%s'
277+ key_core = (KEY_S1 % short_version ) + r" \%s"
294278 for key in (
295279 # Drop support
296280 KEY_DROP1 % "" ,
@@ -328,12 +312,12 @@ def unregister(target, current=True):
328312 KEY_D % "Compiled" ,
329313 KEY_D % "" ,
330314 # PythonCore
331- key_core % r' InstallPath\InstallGroup' ,
332- key_core % ' InstallPath' ,
333- key_core % ' Modules' ,
334- key_core % ' PythonPath' ,
335- key_core % r' Help\Main Python Documentation' ,
336- key_core % ' Help' ,
315+ key_core % r" InstallPath\InstallGroup" ,
316+ key_core % " InstallPath" ,
317+ key_core % " Modules" ,
318+ key_core % " PythonPath" ,
319+ key_core % r" Help\Main Python Documentation" ,
320+ key_core % " Help" ,
337321 KEY_S1 % short_version ,
338322 KEY_S0 ,
339323 KEY_S ,
@@ -342,23 +326,17 @@ def unregister(target, current=True):
342326 print (key )
343327 winreg .DeleteKey (root , key )
344328 except WindowsError :
345- rootkey = (
346- 'HKEY_CURRENT_USER'
347- if current
348- else 'HKEY_LOCAL_MACHINE'
349- )
329+ rootkey = "HKEY_CURRENT_USER" if current else "HKEY_LOCAL_MACHINE"
350330 print (
351- r' Unable to remove %s\%s' % (rootkey , key ),
331+ r" Unable to remove %s\%s" % (rootkey , key ),
352332 file = sys .stderr ,
353333 )
354334 # Start menu shortcuts
355- for path , desc , fname in _get_shortcut_data (
356- target , current = current
357- ):
335+ for path , desc , fname in _get_shortcut_data (target , current = current ):
358336 if Path (fname ).exists ():
359337 os .remove (fname )
360338
361339
362- if __name__ == ' __main__' :
340+ if __name__ == " __main__" :
363341 register (sys .prefix )
364- unregister (sys .prefix )
342+ unregister (sys .prefix )
0 commit comments