15
15
import sys
16
16
import os
17
17
from pathlib import Path
18
+
18
19
# import subprocess
19
20
20
21
40
41
41
42
42
43
def _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 )
46
45
wpdir = str (Path (target ).parent )
47
46
data = []
48
47
for name in os .listdir (wpdir ):
49
48
bname , ext = Path (name ).stem , Path (name ).suffix
50
- if ext == ' .exe' :
49
+ if ext == " .exe" :
51
50
data .append (
52
51
(
53
52
str (Path (wpdir ) / name ),
@@ -60,11 +59,7 @@ def _get_shortcut_data(target, current=True):
60
59
61
60
def register (target , current = True ):
62
61
"""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
68
63
69
64
# Extensions
70
65
winreg .SetValueEx (
@@ -113,9 +108,9 @@ def register(target, current=True):
113
108
)
114
109
115
110
# 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 ())
119
114
120
115
if not Path (spyder ).is_file ():
121
116
spyder = f'{ pythonw } " "{ target } \Scripts\spyder'
@@ -134,9 +129,7 @@ def register(target, current=True):
134
129
'"%s" "%%1" %%*' % pythonw ,
135
130
)
136
131
winreg .SetValueEx (
137
- winreg .CreateKey (
138
- root , KEY_C2 % ("Compiled" , "open" )
139
- ),
132
+ winreg .CreateKey (root , KEY_C2 % ("Compiled" , "open" )),
140
133
"" ,
141
134
0 ,
142
135
winreg .REG_SZ ,
@@ -147,16 +140,14 @@ def register(target, current=True):
147
140
"" ,
148
141
0 ,
149
142
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 ),
152
144
)
153
145
winreg .SetValueEx (
154
146
winreg .CreateKey (root , KEY_C2 % ("NoCon" , EWI )),
155
147
"" ,
156
148
0 ,
157
149
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 ),
160
151
)
161
152
winreg .SetValueEx (
162
153
winreg .CreateKey (root , KEY_C2 % ("" , EWS )),
@@ -184,27 +175,27 @@ def register(target, current=True):
184
175
handler ,
185
176
)
186
177
# Icons
187
- dlls = str (Path (target ) / ' DLLs' )
178
+ dlls = str (Path (target ) / " DLLs" )
188
179
winreg .SetValueEx (
189
180
winreg .CreateKey (root , KEY_I % "" ),
190
181
"" ,
191
182
0 ,
192
183
winreg .REG_SZ ,
193
- r' %s\py.ico' % dlls ,
184
+ r" %s\py.ico" % dlls ,
194
185
)
195
186
winreg .SetValueEx (
196
187
winreg .CreateKey (root , KEY_I % "NoCon" ),
197
188
"" ,
198
189
0 ,
199
190
winreg .REG_SZ ,
200
- r' %s\py.ico' % dlls ,
191
+ r" %s\py.ico" % dlls ,
201
192
)
202
193
winreg .SetValueEx (
203
194
winreg .CreateKey (root , KEY_I % "Compiled" ),
204
195
"" ,
205
196
0 ,
206
197
winreg .REG_SZ ,
207
- r' %s\pyc.ico' % dlls ,
198
+ r" %s\pyc.ico" % dlls ,
208
199
)
209
200
210
201
# Descriptions
@@ -233,32 +224,30 @@ def register(target, current=True):
233
224
# PythonCore entries
234
225
short_version = utils .get_python_infos (target )[0 ]
235
226
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"
237
228
winreg .SetValueEx (
238
- winreg .CreateKey (root , key_core % ' InstallPath' ),
229
+ winreg .CreateKey (root , key_core % " InstallPath" ),
239
230
"" ,
240
231
0 ,
241
232
winreg .REG_SZ ,
242
233
target ,
243
234
)
244
235
winreg .SetValueEx (
245
- winreg .CreateKey (
246
- root , key_core % r'InstallPath\InstallGroup'
247
- ),
236
+ winreg .CreateKey (root , key_core % r"InstallPath\InstallGroup" ),
248
237
"" ,
249
238
0 ,
250
239
winreg .REG_SZ ,
251
240
"Python %s" % short_version ,
252
241
)
253
242
winreg .SetValueEx (
254
- winreg .CreateKey (root , key_core % ' Modules' ),
243
+ winreg .CreateKey (root , key_core % " Modules" ),
255
244
"" ,
256
245
0 ,
257
246
winreg .REG_SZ ,
258
247
"" ,
259
248
)
260
249
winreg .SetValueEx (
261
- winreg .CreateKey (root , key_core % ' PythonPath' ),
250
+ winreg .CreateKey (root , key_core % " PythonPath" ),
262
251
"" ,
263
252
0 ,
264
253
winreg .REG_SZ ,
@@ -267,7 +256,7 @@ def register(target, current=True):
267
256
winreg .SetValueEx (
268
257
winreg .CreateKey (
269
258
root ,
270
- key_core % r' Help\Main Python Documentation' ,
259
+ key_core % r" Help\Main Python Documentation" ,
271
260
),
272
261
"" ,
273
262
0 ,
@@ -276,21 +265,16 @@ def register(target, current=True):
276
265
)
277
266
278
267
# 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 ):
282
269
utils .create_shortcut (path , desc , fname )
283
270
271
+
284
272
def unregister (target , current = True ):
285
273
"""Unregister a Python distribution in Windows registry"""
286
274
# 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
292
276
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"
294
278
for key in (
295
279
# Drop support
296
280
KEY_DROP1 % "" ,
@@ -328,12 +312,12 @@ def unregister(target, current=True):
328
312
KEY_D % "Compiled" ,
329
313
KEY_D % "" ,
330
314
# 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" ,
337
321
KEY_S1 % short_version ,
338
322
KEY_S0 ,
339
323
KEY_S ,
@@ -342,23 +326,17 @@ def unregister(target, current=True):
342
326
print (key )
343
327
winreg .DeleteKey (root , key )
344
328
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"
350
330
print (
351
- r' Unable to remove %s\%s' % (rootkey , key ),
331
+ r" Unable to remove %s\%s" % (rootkey , key ),
352
332
file = sys .stderr ,
353
333
)
354
334
# 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 ):
358
336
if Path (fname ).exists ():
359
337
os .remove (fname )
360
338
361
339
362
- if __name__ == ' __main__' :
340
+ if __name__ == " __main__" :
363
341
register (sys .prefix )
364
- unregister (sys .prefix )
342
+ unregister (sys .prefix )
0 commit comments