20
20
21
21
import sys
22
22
import os
23
- import os .path as osp
23
+ # import os.path as osp
24
24
from pathlib import Path
25
25
import shutil
26
26
import traceback
36
36
def get_module_path (modname ):
37
37
"""Return module *modname* base path"""
38
38
module = sys .modules .get (modname , __import__ (modname ))
39
- return osp .abspath (osp .dirname (module .__file__ ))
39
+ # return osp.abspath(osp.dirname(module.__file__))
40
+ return str (Path (module .__file__ ).parent .resolve ())
40
41
41
42
42
43
# ==============================================================================
@@ -67,12 +68,15 @@ def prepend_module_to_path(module_path):
67
68
1) In your application to import local frozen copies of internal libraries
68
69
2) In your py2exe distributed package to add a text file containing the returned string
69
70
"""
70
- if not osp .isdir (module_path ):
71
+ #if not osp.isdir(module_path):
72
+ if not Path (module_path ).is_dir ():
71
73
# Assuming py2exe distribution
72
74
return
73
- sys .path .insert (0 , osp .abspath (module_path ))
75
+ #sys.path.insert(0, osp.abspath(module_path))
76
+ sys .path .insert (0 , str (Path (module_path ).resolve ()))
74
77
changeset = get_changeset (module_path )
75
- name = osp .basename (module_path )
78
+ # name = osp.basename(module_path)
79
+ name = Path (module_path ).name
76
80
prefix = "Prepending module to sys.path"
77
81
message = prefix + (
78
82
"%s [revision %s]" % (name , changeset )
@@ -95,7 +99,8 @@ def prepend_module_to_path(module_path):
95
99
96
100
def prepend_modules_to_path (module_base_path ):
97
101
"""Prepend to sys.path all modules located in *module_base_path*"""
98
- if not osp .isdir (module_base_path ):
102
+ # if not osp.isdir(module_base_path):
103
+ if not Path (module_base_path ).is_dir ():
99
104
# Assuming py2exe distribution
100
105
return
101
106
fnames = [
@@ -106,7 +111,8 @@ def prepend_modules_to_path(module_base_path):
106
111
messages = [
107
112
prepend_module_to_path (dirname )
108
113
for dirname in fnames
109
- if osp .isdir (dirname )
114
+ # if osp.isdir(dirname)
115
+ if Path (dirname ).is_dir ()
110
116
]
111
117
return os .linesep .join (messages )
112
118
@@ -118,10 +124,12 @@ def _remove_later(fname):
118
124
"""Try to remove file later (at exit)"""
119
125
120
126
def try_to_remove (fname ):
121
- if osp .exists (fname ):
127
+ # if osp.exists(fname):
128
+ if Path (fname ).exists ():
122
129
os .remove (fname )
123
130
124
- atexit .register (try_to_remove , osp .abspath (fname ))
131
+ # atexit.register(try_to_remove, osp.abspath(fname))
132
+ atexit .register (try_to_remove , str (Path (fname ).resolve ()))
125
133
126
134
127
135
def to_include_files (data_files ):
@@ -142,7 +150,7 @@ def to_include_files(data_files):
142
150
#dest_fname = osp.join(
143
151
# dest_dir, osp.basename(source_fname))
144
152
dest_fname = str (Path (dest_dir ) /
145
- osp . basename (source_fname ))
153
+ Path (source_fname ). name )
146
154
include_files .append ((source_fname , dest_fname ))
147
155
return include_files
148
156
@@ -276,7 +284,8 @@ def setup(
276
284
else version
277
285
)
278
286
self .description = description
279
- assert osp .isfile (script )
287
+ # assert osp.isfile(script)
288
+ assert Path (script ).is_file ()
280
289
self .script = script
281
290
self .target_name = target_name
282
291
self .target_dir = target_dir
@@ -339,7 +348,8 @@ def add_pyqt4(self):
339
348
340
349
import PyQt4
341
350
342
- pyqt_path = osp .dirname (PyQt4 .__file__ )
351
+ # pyqt_path = osp.dirname(PyQt4.__file__)
352
+ pyqt_path = str (Path (PyQt4 .__file__ ).parent )
343
353
344
354
# Configuring PyQt4
345
355
conf = os .linesep .join (
@@ -351,7 +361,8 @@ def add_pyqt4(self):
351
361
if self .msvc :
352
362
vc90man = "Microsoft.VC90.CRT.manifest"
353
363
pyqt_tmp = 'pyqt_tmp'
354
- if osp .isdir (pyqt_tmp ):
364
+ # if osp.isdir(pyqt_tmp):
365
+ if Path (pyqt_tmp ).is_dir ():
355
366
shutil .rmtree (pyqt_tmp )
356
367
os .mkdir (pyqt_tmp )
357
368
# vc90man_pyqt = osp.join(pyqt_tmp, vc90man)
@@ -373,12 +384,14 @@ def add_pyqt4(self):
373
384
# osp.join(dirpath, f)
374
385
str (Path (dirpath ) / f )
375
386
for f in filenames
376
- if osp .splitext (f )[1 ] in ('.dll' , '.py' )
387
+ # if osp.splitext(f)[1] in ('.dll', '.py')
388
+ if Path (f ).suffix in ('.dll' , '.py' )
377
389
]
378
390
if self .msvc and [
379
391
f
380
392
for f in filelist
381
- if osp .splitext (f )[1 ] == '.dll'
393
+ # if osp.splitext(f)[1] == '.dll'
394
+ if Path (f ).suffix == '.dll'
382
395
]:
383
396
# Where there is a DLL build with Microsoft Visual C++ 2008,
384
397
# there must be a manifest file as well...
@@ -397,9 +410,10 @@ def add_pyqt4(self):
397
410
# Including french translation
398
411
# fr_trans = osp.join(
399
412
# pyqt_path, "translations", "qt_fr.qm"
413
+ # )
400
414
fr_trans = str (Path (pyqt_path ) / "translations" / "qt_fr.qm" )
401
- )
402
- if osp .exists (fr_trans ):
415
+ # if osp.exists(fr_trans):
416
+ if Path ( fr_trans ) .exists ():
403
417
self .data_files .append (
404
418
('translations' , (fr_trans ,))
405
419
)
@@ -429,7 +443,8 @@ def add_pyside(self):
429
443
430
444
import PySide
431
445
432
- pyside_path = osp .dirname (PySide .__file__ )
446
+ # pyside_path = osp.dirname(PySide.__file__)
447
+ pyside_path = str (Path (PySide .__file__ ).parent )
433
448
434
449
# Configuring PySide
435
450
conf = os .linesep .join (
@@ -460,12 +475,14 @@ def add_pyside(self):
460
475
# osp.join(dirpath, f)
461
476
str (Path (dirpath ) / f )
462
477
for f in filenames
463
- if osp .splitext (f )[1 ] in ('.dll' , '.py' )
478
+ # if osp.splitext(f)[1] in ('.dll', '.py')
479
+ if Path (f ).suffix in ('.dll' , '.py' )
464
480
]
465
481
if self .msvc and [
466
482
f
467
483
for f in filelist
468
- if osp .splitext (f )[1 ] == '.dll'
484
+ # if osp.splitext(f)[1] == '.dll'
485
+ if Path (f ).suffix == '.dll'
469
486
]:
470
487
# Where there is a DLL build with Microsoft Visual C++ 2008,
471
488
# there must be a manifest file as well...
@@ -485,7 +502,8 @@ def add_pyside(self):
485
502
# osp.join(pyside_path, fname)
486
503
str (Path (pyside_path ) / fname )
487
504
for fname in os .listdir (pyside_path )
488
- if osp .splitext (fname )[1 ] == '.dll'
505
+ #if osp.splitext(fname)[1] == '.dll'
506
+ if Path (fname ).suffix == '.dll'
489
507
]
490
508
self .data_files .append (('' , dlls ))
491
509
@@ -495,7 +513,8 @@ def add_pyside(self):
495
513
# fr_trans = osp.join(
496
514
# pyside_path, "translations", "qt_fr.qm")
497
515
fr_trans = str (Path (pyside_path ) / "translations" / "qt_fr.qm" )
498
- if osp .exists (fr_trans ):
516
+ #if osp.exists(fr_trans):
517
+ if Path (fr_trans ).exists ():
499
518
self .data_files .append (
500
519
('translations' , (fr_trans ,))
501
520
)
@@ -613,12 +632,15 @@ def add_modules(self, *module_names):
613
632
import sphinx .ext
614
633
615
634
for fname in os .listdir (
616
- osp .dirname (sphinx .ext .__file__ )
635
+ #osp.dirname(sphinx.ext.__file__)
636
+ str (Path (sphinx .ext .__file__ ).parent )
617
637
):
618
- if osp .splitext (fname )[1 ] == '.py' :
638
+ #if osp.splitext(fname)[1] == '.py':
639
+ if Path (fname ).suffix == '.py' :
619
640
modname = (
620
641
'sphinx.ext.%s'
621
- % osp .splitext (fname )[0 ]
642
+ # % osp.splitext(fname)[0]
643
+ % Path (fname ).stem
622
644
)
623
645
self .includes .append (modname )
624
646
elif module_name == 'pygments' :
@@ -699,18 +721,21 @@ def add_module_data_dir(
699
721
*extensions*: list of file extensions, e.g. ('.png', '.svg')
700
722
"""
701
723
module_dir = get_module_path (module_name )
702
- nstrip = len (module_dir ) + len (osp .sep )
724
+ # nstrip = len(module_dir) + len(osp.sep)
725
+ nstrip = len (module_dir ) + len (os .sep )
703
726
# data_dir = osp.join(module_dir, data_dir_name)
704
727
data_dir = str (Path (module_dir ) / data_dir_name )
705
- if not osp .isdir (data_dir ):
728
+ # if not osp.isdir(data_dir):
729
+ if not Path (data_dir ).is_dir ():
706
730
raise IOError (
707
731
"Directory not found: %s" % data_dir
708
732
)
709
733
for dirpath , _dirnames , filenames in os .walk (
710
734
data_dir
711
735
):
712
736
dirname = dirpath [nstrip :]
713
- if osp .basename (dirpath ) in exclude_dirs :
737
+ #if osp.basename(dirpath) in exclude_dirs:
738
+ if Path (dirpath ).name in exclude_dirs :
714
739
continue
715
740
if not copy_to_root :
716
741
# dirname = osp.join(module_name, dirname)
@@ -719,7 +744,8 @@ def add_module_data_dir(
719
744
# osp.join(dirpath, f)
720
745
str (Path (dirpath ) / f )
721
746
for f in filenames
722
- if osp .splitext (f )[1 ].lower () in extensions
747
+ # if osp.splitext(f)[1].lower() in extensions
748
+ if Path (f ).suffix .lower () in extensions
723
749
]
724
750
self .data_files .append ((dirname , pathlist ))
725
751
if verbose :
@@ -767,23 +793,30 @@ def add_module_data_files(
767
793
#)
768
794
translation_file = str (Path (module_dir ) / "locale" / "fr" /
769
795
"LC_MESSAGES" / f"{ module_name } .mo" )
770
- if osp .isfile (translation_file ):
796
+ # if osp.isfile(translation_file):
797
+ if Path (translation_file ).is_file ():
771
798
self .data_files .append (
772
799
(
773
- osp .join (
774
- module_name ,
775
- "locale" ,
776
- "fr" ,
777
- "LC_MESSAGES" ,
778
- ),
800
+ #osp.join(
801
+ # module_name,
802
+ # "locale",
803
+ # "fr",
804
+ # "LC_MESSAGES",
805
+ #),
806
+ str (Path (
807
+ module_name ) /
808
+ "locale" /
809
+ "fr" /
810
+ "LC_MESSAGES" ),
779
811
(translation_file ,),
780
812
)
781
813
)
782
814
print (
783
815
"Adding module '%s' translation file: %s"
784
816
% (
785
817
module_name ,
786
- osp .basename (translation_file ),
818
+ #osp.basename(translation_file),
819
+ Path (translation_file ).name ,
787
820
)
788
821
)
789
822
@@ -821,7 +854,8 @@ def build(
821
854
def __cleanup (self ):
822
855
"""Remove old build and dist directories"""
823
856
remove_dir ("build" )
824
- if osp .isdir ("dist" ):
857
+ # if osp.isdir("dist"):
858
+ if Path ("dist" ).is_dir ():
825
859
remove_dir ("dist" )
826
860
remove_dir (self .target_dir )
827
861
@@ -877,7 +911,8 @@ def build_py2exe(
877
911
icon_resources = [(0 , self .icon )],
878
912
bitmap_resources = [],
879
913
other_resources = [],
880
- dest_base = osp .splitext (self .target_name )[0 ],
914
+ # dest_base=osp.splitext(self.target_name)[0],
915
+ dest_base = Path (self .target_name ).stem ,
881
916
version = self .version ,
882
917
company_name = company_name ,
883
918
copyright = copyright ,
0 commit comments