13
13
from __future__ import print_function
14
14
15
15
import os
16
- import os .path as osp
16
+ # import os.path as osp
17
17
from pathlib import Path
18
18
import shutil
19
19
import re
28
28
# from former wppm separate script launcher
29
29
import textwrap
30
30
from argparse import ArgumentParser , HelpFormatter , RawTextHelpFormatter
31
- from winpython import py3compat
31
+ # from winpython import py3compat
32
32
33
33
from winpython import piptree
34
34
@@ -75,7 +75,8 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
75
75
# machine which is not connected to the internet
76
76
# we store only normalized names now (PEP 503)
77
77
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 )))
79
80
my_metadata = dict (
80
81
description = '' ,
81
82
url = 'https://pypi.org/project/' + name ,
@@ -109,7 +110,8 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
109
110
try :
110
111
db [normalize (name )] = {}
111
112
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 :
113
115
db .write (configfile )
114
116
except :
115
117
pass
@@ -139,7 +141,8 @@ def __str__(self):
139
141
pytext ,
140
142
self .description ,
141
143
self .url ,
142
- osp .basename (self .fname ),
144
+ # osp.basename(self.fname),
145
+ Path (self .fname ).name ,
143
146
)
144
147
return text
145
148
@@ -182,7 +185,7 @@ def __init__(self, fname, update=False):
182
185
def extract_infos (self ):
183
186
"""Extract package infos (name, version, architecture)
184
187
from filename (installer basename)"""
185
- bname = osp .basename (self .fname )
188
+ bname = Path ( self . fname ). name # osp.basename(self.fname)
186
189
if bname .endswith (('32.whl' , '64.whl' )):
187
190
# {name}[-{bloat}]-{version}-{python tag}-{abi tag}-{platform tag}.whl
188
191
# ['sounddevice','0.3.5','py2.py3.cp34.cp35','none','win32']
@@ -230,9 +233,9 @@ def extract_infos(self):
230
233
self .name = match .groups ()[0 ]
231
234
self .logname = '%s-wininst.log' % self .name
232
235
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 ),
236
239
'U' ,
237
240
)
238
241
searchtxt = 'DisplayName='
@@ -279,7 +282,8 @@ def __init__(
279
282
target
280
283
)
281
284
# 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
283
287
284
288
def clean_up (self ):
285
289
"""Remove directories which couldn't be removed when building"""
@@ -309,40 +313,53 @@ def copy_files(
309
313
create_bat_files = False ,
310
314
):
311
315
"""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 ():
314
320
return
315
321
offset = len (srcdir ) + len (os .pathsep )
316
322
for dirpath , dirnames , filenames in os .walk (srcdir ):
317
323
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 )
321
330
if self .verbose :
322
331
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 ():
325
336
os .mkdir (full_dst )
326
337
package .files .append (dst )
327
338
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 )
330
343
if dirpath .endswith ('_system32' ):
331
344
# Files that should be copied in %WINDIR%\system32
332
345
dst = fname
333
346
else :
334
- dst = osp .join (dstdir , t_fname )
347
+ # dst = osp.join(dstdir, t_fname)
348
+ dst = str (Path (dstdir ) / t_fname )
335
349
if self .verbose :
336
350
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 )
338
353
shutil .move (src , full_dst )
339
354
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
341
357
if create_bat_files and ext in ('' , '.py' ):
342
358
dst = name + '.bat'
343
359
if self .verbose :
344
360
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 )
346
363
fd = open (full_dst , 'w' )
347
364
fd .write (
348
365
"""@echo off
@@ -355,10 +372,12 @@ def copy_files(
355
372
356
373
def create_file (self , package , name , dstdir , contents ):
357
374
"""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 )
359
377
if self .verbose :
360
378
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 )
362
381
open (full_dst , 'w' ).write (contents )
363
382
package .files .append (dst )
364
383
@@ -369,7 +388,8 @@ def get_installed_packages(self, update=False):
369
388
wppm = []
370
389
try :
371
390
if (
372
- os .path .dirname (sys .executable )
391
+ #os.path.dirname(sys.executable)
392
+ str (Path (sys .executable ).parent )
373
393
== self .target
374
394
):
375
395
# win pip 22.2, we can use pip inspect API
@@ -469,10 +489,13 @@ def do_pip_action(
469
489
my_actions = actions
470
490
if my_actions is None :
471
491
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'
474
496
)
475
- if osp .isfile (executing ):
497
+ #if osp.isfile(executing):
498
+ if Path (executing ).is_file ():
476
499
complement = [
477
500
r'&&' ,
478
501
'cd' ,
@@ -509,7 +532,8 @@ def patch_standard_packages(
509
532
import filecmp
510
533
511
534
# 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 :
513
537
site_package_place = "\\ site-packages\\ "
514
538
else :
515
539
site_package_place = "\\ Lib\\ site-packages\\ "
@@ -523,14 +547,17 @@ def patch_standard_packages(
523
547
origin = self .target + site_package_place + "pywin32_system32"
524
548
525
549
destin = self .target
526
- if osp .isdir (origin ):
550
+ # if osp.isdir(origin):
551
+ if Path (origin ).is_dir ():
527
552
for name in os .listdir (origin ):
528
553
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 ),
531
558
)
532
- if not os .path .exists (
533
- there
559
+ # if not os.path.exists(there
560
+ if not Path ( there ). exists (
534
561
) or not filecmp .cmp (here , there ):
535
562
shutil .copyfile (here , there )
536
563
# 'pip' to do movable launchers (around line 100) !!!!
@@ -621,12 +648,14 @@ def create_pybat(
621
648
):
622
649
"""Create launcher batch script when missing"""
623
650
624
- scriptpy = osp .join (
625
- self .target , 'Scripts'
651
+ # scriptpy = osp.join(
652
+ # self.target, 'Scripts'
653
+ scriptpy = str (Path (self .target ) / 'Scripts'
626
654
) # std Scripts of python
627
655
628
656
# 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 ():
630
659
os .mkdir (scriptpy )
631
660
632
661
if not list (names ) == names :
@@ -638,16 +667,20 @@ def create_pybat(
638
667
else :
639
668
my_list = names
640
669
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 (
648
680
):
649
681
fd = open (
650
- osp .join (scriptpy , name + '.bat' ),
682
+ # osp.join(scriptpy, name + '.bat'),
683
+ str (Path (scriptpy ) / (name + '.bat' )),
651
684
'w' ,
652
685
)
653
686
fd .write (contents )
@@ -668,8 +701,10 @@ def handle_specific_packages(self, package):
668
701
self .create_file (
669
702
package ,
670
703
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
673
708
),
674
709
contents ,
675
710
)
@@ -694,7 +729,8 @@ def handle_specific_packages(self, package):
694
729
"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\site-packages\package.name\uic\pyuic.py" %1 %2 %3 %4 %5 %6 %7 %8 %9'''
695
730
696
731
# 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
698
734
tmp_string = tmp_string .replace ('python.exe' , my_exec )
699
735
700
736
self .create_file (
@@ -706,14 +742,17 @@ def handle_specific_packages(self, package):
706
742
),
707
743
)
708
744
# 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'
711
749
)
712
750
for dirname in ('Loader' , 'port_v2' , 'port_v3' ):
713
751
self .create_file (
714
752
package ,
715
753
'__init__.py' ,
716
- osp .join (uic_path , dirname ),
754
+ # osp.join(uic_path, dirname),
755
+ str (Path (uic_path ) / dirname ),
717
756
'' ,
718
757
)
719
758
@@ -804,24 +843,36 @@ def main(test=False):
804
843
# 'sandbox',
805
844
#)
806
845
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' )
808
848
809
849
# 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'
812
854
)
813
855
print (Package (fname ))
814
856
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'
820
867
)
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'
825
876
)
826
877
827
878
dist = Distribution (target , verbose = True )
@@ -987,7 +1038,8 @@ def main(test=False):
987
1038
sys .exit ()
988
1039
elif not args .install and not args .uninstall :
989
1040
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 :
991
1043
if args .fname == "" :
992
1044
parser .print_help ()
993
1045
sys .exit ()
0 commit comments