Skip to content

Commit ac5ab70

Browse files
committed
modernize code
1 parent 1f5b007 commit ac5ab70

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

winpython/associate.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414

1515
import sys
1616
import os
17-
import os.path as osp
17+
# import os.path as osp
1818
from pathlib import Path
19-
import subprocess
19+
# import subprocess
2020

2121

2222
# Local imports
23-
from winpython.py3compat import winreg
23+
# from winpython.py3compat import winreg
24+
import winreg
2425
from winpython import utils
2526

2627
KEY_C = r"Software\Classes\%s"
@@ -47,7 +48,8 @@ def _get_shortcut_data(target, current=True):
4748
wpdir = str(Path(target).parent)
4849
data = []
4950
for name in os.listdir(wpdir):
50-
bname, ext = osp.splitext(name)
51+
# bname, ext = osp.splitext(name)
52+
bname, ext = Path(name).stem, Path(name).suffix
5153
if ext == '.exe':
5254
data.append(
5355
(
@@ -117,18 +119,24 @@ def register(target, current=True):
117119

118120
# Verbs
119121
# python = osp.abspath(osp.join(target, 'python.exe'))
120-
python = osp.abspath(str(Path(target) / 'python.exe'))
122+
# python = osp.abspath(str(Path(target) / 'python.exe'))
123+
python = str((Path(target) / 'python.exe').resolve())
121124
# pythonw = osp.abspath(osp.join(target, 'pythonw.exe'))
122-
pythonw = osp.abspath(str(Path(target) / 'pythonw.exe'))
123-
spyder = osp.abspath(
124-
# osp.join(target, os.pardir, 'Spyder.exe')
125-
str(Path(target).parent / 'Spyder.exe')
126-
)
127-
if not osp.isfile(spyder):
128-
spyder = '%s" "%s\Scripts\spyder' % (
129-
pythonw,
130-
target,
131-
)
125+
#pythonw = osp.abspath(str(Path(target) / 'pythonw.exe'))
126+
pythonw = str((Path(target) / 'pythonw.exe').resolve())
127+
#spyder = osp.abspath(
128+
# # osp.join(target, os.pardir, 'Spyder.exe')
129+
# str(Path(target).parent / 'Spyder.exe')
130+
#)
131+
spyder = str((Path(target).parent / 'Spyder.exe').resolve())
132+
133+
# if not osp.isfile(spyder):
134+
if not Path(spyder).is_file():
135+
#spyder = '%s" "%s\Scripts\spyder' % (
136+
# pythonw,
137+
# target,
138+
#)
139+
spyder = f'{pythonw}" "{target}\Scripts\spyder'
132140
winreg.SetValueEx(
133141
winreg.CreateKey(root, KEY_C2 % ("", "open")),
134142
"",
@@ -366,7 +374,8 @@ def unregister(target, current=True):
366374
for path, desc, fname in _get_shortcut_data(
367375
target, current=current
368376
):
369-
if osp.exists(fname):
377+
# if osp.exists(fname):
378+
if Path(fname).exists():
370379
os.remove(fname)
371380

372381

0 commit comments

Comments
 (0)