Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61b464f

Browse files
committed
move a bit to modern Pathlib
1 parent 876f497 commit 61b464f

File tree

7 files changed

+106
-89
lines changed

7 files changed

+106
-89
lines changed

winpython/associate.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,18 @@ def _get_shortcut_data(target, current=True):
4444
current=current
4545
)
4646
# wpdir = osp.join(target, os.pardir)
47-
wpdir = str(Path(target).parent)
47+
wpdir = str(Path(target).parent)
4848
data = []
4949
for name in os.listdir(wpdir):
5050
bname, ext = osp.splitext(name)
5151
if ext == '.exe':
5252
data.append(
5353
(
54-
osp.join(wpdir, name),
54+
# osp.join(wpdir, name),
55+
str(Path(wpdir) / name),
5556
bname,
56-
osp.join(wpgroup, bname),
57+
# osp.join(wpgroup, bname),
58+
str(Path(wpgroup) / bname),
5759
)
5860
)
5961
return data
@@ -114,10 +116,13 @@ def register(target, current=True):
114116
)
115117

116118
# Verbs
117-
python = osp.abspath(osp.join(target, 'python.exe'))
118-
pythonw = osp.abspath(osp.join(target, 'pythonw.exe'))
119+
# python = osp.abspath(osp.join(target, 'python.exe'))
120+
python = osp.abspath(str(Path(target) / 'python.exe'))
121+
# pythonw = osp.abspath(osp.join(target, 'pythonw.exe'))
122+
pythonw = osp.abspath(str(Path(target) / 'pythonw.exe'))
119123
spyder = osp.abspath(
120-
osp.join(target, os.pardir, 'Spyder.exe')
124+
# osp.join(target, os.pardir, 'Spyder.exe')
125+
str(Path(target).parent / 'Spyder.exe')
121126
)
122127
if not osp.isfile(spyder):
123128
spyder = '%s" "%s\Scripts\spyder' % (
@@ -189,7 +194,8 @@ def register(target, current=True):
189194
handler,
190195
)
191196
# Icons
192-
dlls = osp.join(target, 'DLLs')
197+
# dlls = osp.join(target, 'DLLs')
198+
dlls = str(Path(target) / 'DLLs')
193199
winreg.SetValueEx(
194200
winreg.CreateKey(root, KEY_I % ""),
195201
"",
@@ -285,26 +291,6 @@ def register(target, current=True):
285291
target, current=current
286292
):
287293
utils.create_shortcut(path, desc, fname)
288-
# Register the Python ActiveX Scripting client (requires pywin32)
289-
axscript = osp.join(
290-
target,
291-
'Lib',
292-
'site-packages',
293-
'win32comext',
294-
'axscript',
295-
'client',
296-
'pyscript.py',
297-
)
298-
if osp.isfile(axscript):
299-
subprocess.call(
300-
'"%s" "%s"' % (python, axscript), cwd=target
301-
)
302-
else:
303-
print(
304-
'Unable to register ActiveX: please install pywin32',
305-
file=sys.stderr,
306-
)
307-
308294

309295
def unregister(target, current=True):
310296
"""Unregister a Python distribution in Windows registry"""

winpython/config.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import sys
1414
import os.path as osp
15-
15+
from pathlib import Path
1616

1717
def get_module_path(modname):
1818
"""Return module *modname* base path"""
@@ -33,18 +33,21 @@ def get_module_data_path(
3333
return datapath
3434
else:
3535
datapath = get_module_path(modname)
36-
parentdir = osp.join(datapath, osp.pardir)
36+
# parentdir = osp.join(datapath, osp.pardir)
37+
parentdir = str(Path(datapath).parent)
3738
if osp.isfile(parentdir):
3839
# Parent directory is not a directory but the 'library.zip' file:
3940
# this is either a py2exe or a cx_Freeze distribution
4041
datapath = osp.abspath(
41-
osp.join(
42-
osp.join(parentdir, osp.pardir), modname
43-
)
42+
# osp.join(
43+
# osp.join(parentdir, osp.pardir), modname
44+
# )
45+
str(Path(parentdir).parent / modname)
4446
)
4547
if relpath is not None:
4648
datapath = osp.abspath(
47-
osp.join(datapath, relpath)
49+
# osp.join(datapath, relpath)
50+
str(Path(datapath) / relpath)
4851
)
4952
return datapath
5053

winpython/controlpanel.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import os.path as osp
14+
from pathlib import Path
1415
import os
1516
import sys
1617
import platform
@@ -775,19 +776,15 @@ def register_distribution(self):
775776
answer = QMessageBox.warning(
776777
self,
777778
"Register distribution",
779+
"(experimental)",
778780
"This will associate file extensions, icons and "
779781
"Windows explorer's context menu entries ('Edit with IDLE', ...) "
780782
"with selected Python distribution in Windows registry. "
781783
"<br>Shortcuts for all WinPython launchers will be installed "
782784
"in <i>WinPython</i> Start menu group (replacing existing "
783785
"shortcuts)."
784-
"<br>If <i>pywin32</i> is installed (it should be on any "
785-
"WinPython distribution), the Python ActiveX Scripting client "
786-
"will also be registered."
787-
"<br><br><u>Warning</u>: the only way to undo this change is to "
788-
"register another Python distribution to Windows registry."
789-
"<br><br><u>Note</u>: these actions are exactly the same as those "
790-
"performed when installing Python with the official installer "
786+
"<br><br><u>Note</u>: these actions are similar to those performed"
787+
"when installing old Pythons with the official installer before 'py' "
791788
"for Windows.<br><br>Do you want to continue?",
792789
QMessageBox.Yes | QMessageBox.No,
793790
)
@@ -799,14 +796,12 @@ def unregister_distribution(self):
799796
answer = QMessageBox.warning(
800797
self,
801798
"Unregister distribution",
799+
"(experimental)",
802800
"This will remove file extensions associations, icons and "
803801
"Windows explorer's context menu entries ('Edit with IDLE', ...) "
804802
"with selected Python distribution in Windows registry. "
805803
"<br>Shortcuts for all WinPython launchers will be removed "
806804
"from <i>WinPython</i> Start menu group."
807-
"<br>If <i>pywin32</i> is installed (it should be on any "
808-
"WinPython distribution), the Python ActiveX Scripting client "
809-
"will also be unregistered."
810805
"<br><br>Do you want to continue?",
811806
QMessageBox.Yes | QMessageBox.No,
812807
)
@@ -815,11 +810,13 @@ def unregister_distribution(self):
815810

816811
@property
817812
def command_prompt_path(self):
818-
return osp.join(
819-
self.distribution.target,
820-
osp.pardir,
821-
"WinPython Command Prompt.exe",
822-
)
813+
# return osp.join(
814+
# self.distribution.target,
815+
# osp.pardir,
816+
# "WinPython Command Prompt.exe",
817+
# )
818+
return str(Path(self.distribution.target).parent /
819+
"WinPython Command Prompt.exe")
823820

824821
def distribution_changed(self, path):
825822
"""Distribution path has just changed"""

winpython/data/packages.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,3 +3403,6 @@ description = A linear operator implementation, primarily designed for finite-di
34033403
[waitress]
34043404
description = Waitress WSGI server
34053405
3406+
[contourpy]
3407+
description = Python library for calculating contours of 2D quadrilateral grids
3408+

winpython/disthelpers.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
import os
2323
import os.path as osp
24+
from pathlib import Path
2425
import shutil
2526
import traceback
2627
import atexit
@@ -98,7 +99,8 @@ def prepend_modules_to_path(module_base_path):
9899
# Assuming py2exe distribution
99100
return
100101
fnames = [
101-
osp.join(module_base_path, name)
102+
# osp.join(module_base_path, name)
103+
str(Path(module_base_path) / name)
102104
for name in os.listdir(module_base_path)
103105
]
104106
messages = [
@@ -137,9 +139,10 @@ def to_include_files(data_files):
137139
include_files = []
138140
for dest_dir, fnames in data_files:
139141
for source_fname in fnames:
140-
dest_fname = osp.join(
141-
dest_dir, osp.basename(source_fname)
142-
)
142+
#dest_fname = osp.join(
143+
# dest_dir, osp.basename(source_fname))
144+
dest_fname = str(Path(dest_dir) /
145+
osp.basename(source_fname))
143146
include_files.append((source_fname, dest_fname))
144147
return include_files
145148

@@ -351,7 +354,8 @@ def add_pyqt4(self):
351354
if osp.isdir(pyqt_tmp):
352355
shutil.rmtree(pyqt_tmp)
353356
os.mkdir(pyqt_tmp)
354-
vc90man_pyqt = osp.join(pyqt_tmp, vc90man)
357+
# vc90man_pyqt = osp.join(pyqt_tmp, vc90man)
358+
vc90man_pyqt = str(Path(pyqt_tmp) / vc90man)
355359
man = (
356360
open(vc90man, "r")
357361
.read()
@@ -362,10 +366,12 @@ def add_pyqt4(self):
362366
)
363367
open(vc90man_pyqt, 'w').write(man)
364368
for dirpath, _, filenames in os.walk(
365-
osp.join(pyqt_path, "plugins")
369+
# osp.join(pyqt_path, "plugins")
370+
str(Path(pyqt_path) / "plugins")
366371
):
367372
filelist = [
368-
osp.join(dirpath, f)
373+
# osp.join(dirpath, f)
374+
str(Path(dirpath) / f)
369375
for f in filenames
370376
if osp.splitext(f)[1] in ('.dll', '.py')
371377
]
@@ -389,8 +395,9 @@ def add_pyqt4(self):
389395
if self.msvc:
390396
atexit.register(remove_dir, pyqt_tmp)
391397
# Including french translation
392-
fr_trans = osp.join(
393-
pyqt_path, "translations", "qt_fr.qm"
398+
# fr_trans = osp.join(
399+
# pyqt_path, "translations", "qt_fr.qm"
400+
fr_trans = str(Path(pyqt_path) / "translations" / "qt_fr.qm")
394401
)
395402
if osp.exists(fr_trans):
396403
self.data_files.append(
@@ -434,7 +441,8 @@ def add_pyside(self):
434441
if self.msvc:
435442
vc90man = "Microsoft.VC90.CRT.manifest"
436443
os.mkdir('pyside_tmp')
437-
vc90man_pyside = osp.join('pyside_tmp', vc90man)
444+
# vc90man_pyside = osp.join('pyside_tmp', vc90man)
445+
vc90man_pyside = str(Path('pyside_tmp') / vc90man)
438446
man = (
439447
open(vc90man, "r")
440448
.read()
@@ -445,10 +453,12 @@ def add_pyside(self):
445453
)
446454
open(vc90man_pyside, 'w').write(man)
447455
for dirpath, _, filenames in os.walk(
448-
osp.join(pyside_path, "plugins")
456+
# osp.join(pyside_path, "plugins")
457+
str(Path(pyside_path) / "plugins")
449458
):
450459
filelist = [
451-
osp.join(dirpath, f)
460+
# osp.join(dirpath, f)
461+
str(Path(dirpath) / f)
452462
for f in filenames
453463
if osp.splitext(f)[1] in ('.dll', '.py')
454464
]
@@ -472,7 +482,8 @@ def add_pyside(self):
472482
# Replacing dlls found by cx_Freeze by the real PySide Qt dlls:
473483
# (http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows)
474484
dlls = [
475-
osp.join(pyside_path, fname)
485+
# osp.join(pyside_path, fname)
486+
str(Path(pyside_path) / fname)
476487
for fname in os.listdir(pyside_path)
477488
if osp.splitext(fname)[1] == '.dll'
478489
]
@@ -481,9 +492,9 @@ def add_pyside(self):
481492
if self.msvc:
482493
atexit.register(remove_dir, 'pyside_tmp')
483494
# Including french translation
484-
fr_trans = osp.join(
485-
pyside_path, "translations", "qt_fr.qm"
486-
)
495+
# fr_trans = osp.join(
496+
# pyside_path, "translations", "qt_fr.qm")
497+
fr_trans = str(Path(pyside_path) / "translations" / "qt_fr.qm")
487498
if osp.exists(fr_trans):
488499
self.data_files.append(
489500
('translations', (fr_trans,))
@@ -573,9 +584,10 @@ def add_modules(self, *module_names):
573584
(
574585
'',
575586
(
576-
osp.join(
577-
get_module_path('h5py'),
578-
'zlib1.dll',
587+
#osp.join(
588+
# get_module_path('h5py'),
589+
# 'zlib1.dll',
590+
str(Path(get_module_path('h5py')) / 'zlib1.dll'
579591
),
580592
),
581593
)
@@ -688,7 +700,8 @@ def add_module_data_dir(
688700
"""
689701
module_dir = get_module_path(module_name)
690702
nstrip = len(module_dir) + len(osp.sep)
691-
data_dir = osp.join(module_dir, data_dir_name)
703+
# data_dir = osp.join(module_dir, data_dir_name)
704+
data_dir = str(Path(module_dir) / data_dir_name)
692705
if not osp.isdir(data_dir):
693706
raise IOError(
694707
"Directory not found: %s" % data_dir
@@ -700,9 +713,11 @@ def add_module_data_dir(
700713
if osp.basename(dirpath) in exclude_dirs:
701714
continue
702715
if not copy_to_root:
703-
dirname = osp.join(module_name, dirname)
716+
# dirname = osp.join(module_name, dirname)
717+
dirname = str(Path(module_name) / dirname)
704718
pathlist = [
705-
osp.join(dirpath, f)
719+
# osp.join(dirpath, f)
720+
str(Path(dirpath) / f)
706721
for f in filenames
707722
if osp.splitext(f)[1].lower() in extensions
708723
]
@@ -743,13 +758,15 @@ def add_module_data_files(
743758
verbose,
744759
exclude_dirs,
745760
)
746-
translation_file = osp.join(
747-
module_dir,
748-
"locale",
749-
"fr",
750-
"LC_MESSAGES",
751-
"%s.mo" % module_name,
752-
)
761+
#translation_file = osp.join(
762+
# module_dir,
763+
# "locale",
764+
# "fr",
765+
# "LC_MESSAGES",
766+
# "%s.mo" % module_name,
767+
#)
768+
translation_file = str(Path(module_dir) / "locale" / "fr" /
769+
"LC_MESSAGES" / f"{module_name}.mo" )
753770
if osp.isfile(translation_file):
754771
self.data_files.append(
755772
(

winpython/qthelpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import os
5050
import re
5151
import os.path as osp
52+
from pathlib import Path
5253
import sys
5354

5455
# Local import
@@ -61,7 +62,8 @@
6162

6263
def get_icon(name):
6364
"""Return QIcon from icon name"""
64-
return QIcon(osp.join(config.IMAGE_PATH, name))
65+
# return QIcon(osp.join(config.IMAGE_PATH, name))
66+
return QIcon(str(Path(config.IMAGE_PATH) / name))
6567

6668

6769
class MacApplication(QApplication):

0 commit comments

Comments
 (0)