Skip to content

Commit 01e3b4c

Browse files
committed
remove osp use in wppm.py
1 parent 44a8946 commit 01e3b4c

File tree

1 file changed

+117
-65
lines changed

1 file changed

+117
-65
lines changed

winpython/wppm.py

Lines changed: 117 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from __future__ import print_function
1414

1515
import os
16-
import os.path as osp
16+
# import os.path as osp
1717
from pathlib import Path
1818
import shutil
1919
import re
@@ -28,7 +28,7 @@
2828
# from former wppm separate script launcher
2929
import textwrap
3030
from argparse import ArgumentParser, HelpFormatter, RawTextHelpFormatter
31-
from winpython import py3compat
31+
# from winpython import py3compat
3232

3333
from winpython import piptree
3434

@@ -75,7 +75,8 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
7575
# machine which is not connected to the internet
7676
# we store only normalized names now (PEP 503)
7777
db = cp.ConfigParser()
78-
db.readfp(open(osp.join(DATA_PATH, database)))
78+
# db.readfp(open(osp.join(DATA_PATH, database)))
79+
db.readfp(open(str(Path(DATA_PATH) / database)))
7980
my_metadata = dict(
8081
description='',
8182
url='https://pypi.org/project/' + name,
@@ -109,7 +110,8 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
109110
try:
110111
db[normalize(name)] = {}
111112
db[normalize(name)]['description'] = my_metadata['description']
112-
with open(osp.join(DATA_PATH, database), 'w') as configfile:
113+
# with open(osp.join(DATA_PATH, database), 'w') as configfile:
114+
with open(str(Path(DATA_PATH) / database), 'w') as configfile:
113115
db.write(configfile)
114116
except:
115117
pass
@@ -139,7 +141,8 @@ def __str__(self):
139141
pytext,
140142
self.description,
141143
self.url,
142-
osp.basename(self.fname),
144+
# osp.basename(self.fname),
145+
Path(self.fname).name,
143146
)
144147
return text
145148

@@ -182,7 +185,7 @@ def __init__(self, fname, update=False):
182185
def extract_infos(self):
183186
"""Extract package infos (name, version, architecture)
184187
from filename (installer basename)"""
185-
bname = osp.basename(self.fname)
188+
bname = Path(self.fname).name # osp.basename(self.fname)
186189
if bname.endswith(('32.whl', '64.whl')):
187190
# {name}[-{bloat}]-{version}-{python tag}-{abi tag}-{platform tag}.whl
188191
# ['sounddevice','0.3.5','py2.py3.cp34.cp35','none','win32']
@@ -230,9 +233,9 @@ def extract_infos(self):
230233
self.name = match.groups()[0]
231234
self.logname = '%s-wininst.log' % self.name
232235
fd = open(
233-
osp.join(
234-
self.distribution.target, self.logname
235-
),
236+
# osp.join(
237+
# self.distribution.target, self.logname
238+
str(Path(self.distribution.target) / self.logname),
236239
'U',
237240
)
238241
searchtxt = 'DisplayName='
@@ -279,7 +282,8 @@ def __init__(
279282
target
280283
)
281284
# name of the exe (python.exe or pypy3;exe)
282-
self.short_exe = osp.basename(utils.get_python_executable(self.target))
285+
# self.short_exe = osp.basename(utils.get_python_executable(self.target))
286+
self.short_exe = Path(utils.get_python_executable(self.target)).name
283287

284288
def clean_up(self):
285289
"""Remove directories which couldn't be removed when building"""
@@ -309,40 +313,53 @@ def copy_files(
309313
create_bat_files=False,
310314
):
311315
"""Add copy task"""
312-
srcdir = osp.join(targetdir, srcdir)
313-
if not osp.isdir(srcdir):
316+
# srcdir = osp.join(targetdir, srcdir)
317+
srcdir = str(Path(targetdir) / srcdir)
318+
# if not osp.isdir(srcdir):
319+
if not Path(srcdir).is_dir():
314320
return
315321
offset = len(srcdir) + len(os.pathsep)
316322
for dirpath, dirnames, filenames in os.walk(srcdir):
317323
for dname in dirnames:
318-
t_dname = osp.join(dirpath, dname)[offset:]
319-
src = osp.join(srcdir, t_dname)
320-
dst = osp.join(dstdir, t_dname)
324+
# t_dname = osp.join(dirpath, dname)[offset:]
325+
t_dname = str(Path(dirpath) / dname)[offset:]
326+
# src = osp.join(srcdir, t_dname)
327+
src = str(Path(srcdir) / t_dname)
328+
# dst = osp.join(dstdir, t_dname)
329+
dst = str(Path(dstdir) / t_dname)
321330
if self.verbose:
322331
print("mkdir: %s" % dst)
323-
full_dst = osp.join(self.target, dst)
324-
if not osp.exists(full_dst):
332+
# full_dst = osp.join(self.target, dst)
333+
full_dst = str(Path(self.target) / dst)
334+
# if not osp.exists(full_dst):
335+
if not Path(full_dst).exists():
325336
os.mkdir(full_dst)
326337
package.files.append(dst)
327338
for fname in filenames:
328-
t_fname = osp.join(dirpath, fname)[offset:]
329-
src = osp.join(srcdir, t_fname)
339+
# t_fname = osp.join(dirpath, fname)[offset:]
340+
t_fname = str(Path(dirpath) / fname)[offset:]
341+
# src = osp.join(srcdir, t_fname)
342+
src = str(Path(srcdir) / t_fname)
330343
if dirpath.endswith('_system32'):
331344
# Files that should be copied in %WINDIR%\system32
332345
dst = fname
333346
else:
334-
dst = osp.join(dstdir, t_fname)
347+
# dst = osp.join(dstdir, t_fname)
348+
dst = str(Path(dstdir) / t_fname)
335349
if self.verbose:
336350
print("file: %s" % dst)
337-
full_dst = osp.join(self.target, dst)
351+
# full_dst = osp.join(self.target, dst)
352+
full_dst = str(Path(self.target) / dst)
338353
shutil.move(src, full_dst)
339354
package.files.append(dst)
340-
name, ext = osp.splitext(dst)
355+
#name, ext = osp.splitext(dst)
356+
name, ext = Path(dst).stem, Path(dst).suffix
341357
if create_bat_files and ext in ('', '.py'):
342358
dst = name + '.bat'
343359
if self.verbose:
344360
print("file: %s" % dst)
345-
full_dst = osp.join(self.target, dst)
361+
# full_dst = osp.join(self.target, dst)
362+
full_dst = str(Path(self.target) / dst)
346363
fd = open(full_dst, 'w')
347364
fd.write(
348365
"""@echo off
@@ -355,10 +372,12 @@ def copy_files(
355372

356373
def create_file(self, package, name, dstdir, contents):
357374
"""Generate data file -- path is relative to distribution root dir"""
358-
dst = osp.join(dstdir, name)
375+
# dst = osp.join(dstdir, name)
376+
dst = str(Path(dstdir) / name)
359377
if self.verbose:
360378
print("create: %s" % dst)
361-
full_dst = osp.join(self.target, dst)
379+
# full_dst = osp.join(self.target, dst)
380+
full_dst = str(Path(self.target) / dst)
362381
open(full_dst, 'w').write(contents)
363382
package.files.append(dst)
364383

@@ -369,7 +388,8 @@ def get_installed_packages(self, update=False):
369388
wppm = []
370389
try:
371390
if (
372-
os.path.dirname(sys.executable)
391+
#os.path.dirname(sys.executable)
392+
str(Path(sys.executable).parent)
373393
== self.target
374394
):
375395
# win pip 22.2, we can use pip inspect API
@@ -469,10 +489,13 @@ def do_pip_action(
469489
my_actions = actions
470490
if my_actions is None:
471491
my_actions = []
472-
executing = osp.join(
473-
self.target, '..', 'scripts', 'env.bat'
492+
# executing = osp.join(
493+
# self.target, '..', 'scripts', 'env.bat'
494+
executing = str(Path(
495+
self.target).parent / 'scripts' / 'env.bat'
474496
)
475-
if osp.isfile(executing):
497+
#if osp.isfile(executing):
498+
if Path(executing).is_file():
476499
complement = [
477500
r'&&',
478501
'cd',
@@ -509,7 +532,8 @@ def patch_standard_packages(
509532
import filecmp
510533

511534
# Adpating to PyPy
512-
if 'pypy3' in osp.basename(utils.get_python_executable(self.target)):
535+
# if 'pypy3' in osp.basename(utils.get_python_executable(self.target)):
536+
if 'pypy3' in Path(utils.get_python_executable(self.target)).name:
513537
site_package_place="\\site-packages\\"
514538
else:
515539
site_package_place="\\Lib\\site-packages\\"
@@ -523,14 +547,17 @@ def patch_standard_packages(
523547
origin = self.target + site_package_place + "pywin32_system32"
524548

525549
destin = self.target
526-
if osp.isdir(origin):
550+
# if osp.isdir(origin):
551+
if Path(origin).is_dir():
527552
for name in os.listdir(origin):
528553
here, there = (
529-
osp.join(origin, name),
530-
osp.join(destin, name),
554+
# osp.join(origin, name),
555+
str(Path(origin) / name),
556+
# osp.join(destin, name),
557+
str(Path(destin) / name),
531558
)
532-
if not os.path.exists(
533-
there
559+
# if not os.path.exists(there
560+
if not Path(there).exists(
534561
) or not filecmp.cmp(here, there):
535562
shutil.copyfile(here, there)
536563
# 'pip' to do movable launchers (around line 100) !!!!
@@ -621,12 +648,14 @@ def create_pybat(
621648
):
622649
"""Create launcher batch script when missing"""
623650

624-
scriptpy = osp.join(
625-
self.target, 'Scripts'
651+
# scriptpy = osp.join(
652+
# self.target, 'Scripts'
653+
scriptpy = str(Path(self.target) / 'Scripts'
626654
) # std Scripts of python
627655

628656
# PyPy has no initial Scipts directory
629-
if not osp.isdir(scriptpy):
657+
# if not osp.isdir(scriptpy):
658+
if not Path(scriptpy).is_dir():
630659
os.mkdir(scriptpy)
631660

632661
if not list(names) == names:
@@ -638,16 +667,20 @@ def create_pybat(
638667
else:
639668
my_list = names
640669
for name in my_list:
641-
if osp.isdir(scriptpy) and osp.isfile(
642-
osp.join(scriptpy, name)
643-
):
644-
if not osp.isfile(
645-
osp.join(scriptpy, name + '.exe')
646-
) and not osp.isfile(
647-
osp.join(scriptpy, name + '.bat')
670+
# if osp.isdir(scriptpy) and osp.isfile(
671+
# osp.join(scriptpy, name)):
672+
if Path(scriptpy).is_dir() and (Path(
673+
scriptpy) / name).is_dir():
674+
#if not osp.isfile(
675+
# osp.join(scriptpy, name + '.exe')
676+
#) and not osp.isfile(
677+
# osp.join(scriptpy, name + '.bat')
678+
if not (Path(scriptpy) / (name + '.exe')).is_file(
679+
) and not (Path(scriptpy) / (name + '.bat')).is_file(
648680
):
649681
fd = open(
650-
osp.join(scriptpy, name + '.bat'),
682+
# osp.join(scriptpy, name + '.bat'),
683+
str(Path(scriptpy) / (name + '.bat')),
651684
'w',
652685
)
653686
fd.write(contents)
@@ -668,8 +701,10 @@ def handle_specific_packages(self, package):
668701
self.create_file(
669702
package,
670703
name,
671-
osp.join(
672-
'Lib', 'site-packages', package.name
704+
#osp.join(
705+
# 'Lib', 'site-packages', package.name
706+
str(Path(
707+
'Lib') / 'site-packages' / package.name
673708
),
674709
contents,
675710
)
@@ -694,7 +729,8 @@ def handle_specific_packages(self, package):
694729
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\site-packages\package.name\uic\pyuic.py" %1 %2 %3 %4 %5 %6 %7 %8 %9'''
695730

696731
# PyPy adaption: python.exe or pypy3.exe
697-
my_exec = osp.basename(utils.get_python_executable(self.target))
732+
#my_exec = osp.basename(utils.get_python_executable(self.target))
733+
my_exec = Path(utils.get_python_executable(self.target)).name
698734
tmp_string = tmp_string.replace('python.exe', my_exec)
699735

700736
self.create_file(
@@ -706,14 +742,17 @@ def handle_specific_packages(self, package):
706742
),
707743
)
708744
# Adding missing __init__.py files (fixes Issue 8)
709-
uic_path = osp.join(
710-
'Lib', 'site-packages', package.name, 'uic'
745+
# uic_path = osp.join(
746+
# 'Lib', 'site-packages', package.name, 'uic'
747+
uic_path = str(Path(
748+
'Lib') / 'site-packages' / package.name / 'uic'
711749
)
712750
for dirname in ('Loader', 'port_v2', 'port_v3'):
713751
self.create_file(
714752
package,
715753
'__init__.py',
716-
osp.join(uic_path, dirname),
754+
# osp.join(uic_path, dirname),
755+
str(Path(uic_path) / dirname),
717756
'',
718757
)
719758

@@ -804,24 +843,36 @@ def main(test=False):
804843
# 'sandbox',
805844
#)
806845
sbdir = str(Path(__file__).parents[0].parent.parent.parent / 'sandbox')
807-
tmpdir = osp.join(sbdir, 'tobedeleted')
846+
#tmpdir = osp.join(sbdir, 'tobedeleted')
847+
tmpdir = str(Path(sbdir) / 'tobedeleted')
808848

809849
# fname = osp.join(tmpdir, 'scipy-0.10.1.win-amd64-py2.7.exe')
810-
fname = osp.join(
811-
sbdir, 'VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe'
850+
#fname = osp.join(
851+
# sbdir, 'VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe'
852+
fname = str(Path(
853+
sbdir) / 'VTK-5.10.0-Qt-4.7.4.win32-py2.7.exe'
812854
)
813855
print(Package(fname))
814856
sys.exit()
815-
target = osp.join(
816-
utils.BASE_DIR,
817-
'build',
818-
'winpython-2.7.3',
819-
'python-2.7.3',
857+
#target = osp.join(
858+
# utils.BASE_DIR,
859+
# 'build',
860+
# 'winpython-2.7.3',
861+
# 'python-2.7.3',
862+
target = str(Path(
863+
utils.BASE_DIR) /
864+
'build' /
865+
'winpython-2.7.3' /
866+
'python-2.7.3'
820867
)
821-
fname = osp.join(
822-
utils.BASE_DIR,
823-
'packages.src',
824-
'docutils-0.9.1.tar.gz',
868+
#fname = osp.join(
869+
# utils.BASE_DIR,
870+
# 'packages.src',
871+
# 'docutils-0.9.1.tar.gz',
872+
fname = str(Path(
873+
utils.BASE_DIR) /
874+
'packages.src' /
875+
'docutils-0.9.1.tar.gz'
825876
)
826877

827878
dist = Distribution(target, verbose=True)
@@ -987,7 +1038,8 @@ def main(test=False):
9871038
sys.exit()
9881039
elif not args.install and not args.uninstall:
9891040
args.install = True
990-
if not osp.isfile(args.fname) and args.install:
1041+
#if not osp.isfile(args.fname) and args.install:
1042+
if not Path(args.fname).is_file() and args.install:
9911043
if args.fname=="":
9921044
parser.print_help()
9931045
sys.exit()

0 commit comments

Comments
 (0)