20
20
21
21
import sys
22
22
import os
23
- # import os.path as osp
24
23
from pathlib import Path
25
24
import shutil
26
25
import traceback
36
35
def get_module_path (modname ):
37
36
"""Return module *modname* base path"""
38
37
module = sys .modules .get (modname , __import__ (modname ))
39
- # return osp.abspath(osp.dirname(module.__file__))
40
38
return str (Path (module .__file__ ).parent .resolve ())
41
39
42
40
@@ -68,14 +66,11 @@ def prepend_module_to_path(module_path):
68
66
1) In your application to import local frozen copies of internal libraries
69
67
2) In your py2exe distributed package to add a text file containing the returned string
70
68
"""
71
- #if not osp.isdir(module_path):
72
69
if not Path (module_path ).is_dir ():
73
70
# Assuming py2exe distribution
74
71
return
75
- #sys.path.insert(0, osp.abspath(module_path))
76
72
sys .path .insert (0 , str (Path (module_path ).resolve ()))
77
73
changeset = get_changeset (module_path )
78
- # name = osp.basename(module_path)
79
74
name = Path (module_path ).name
80
75
prefix = "Prepending module to sys.path"
81
76
message = prefix + (
@@ -99,12 +94,10 @@ def prepend_module_to_path(module_path):
99
94
100
95
def prepend_modules_to_path (module_base_path ):
101
96
"""Prepend to sys.path all modules located in *module_base_path*"""
102
- # if not osp.isdir(module_base_path):
103
97
if not Path (module_base_path ).is_dir ():
104
98
# Assuming py2exe distribution
105
99
return
106
100
fnames = [
107
- # osp.join(module_base_path, name)
108
101
str (Path (module_base_path ) / name )
109
102
for name in os .listdir (module_base_path )
110
103
]
@@ -124,11 +117,9 @@ def _remove_later(fname):
124
117
"""Try to remove file later (at exit)"""
125
118
126
119
def try_to_remove (fname ):
127
- # if osp.exists(fname):
128
120
if Path (fname ).exists ():
129
121
os .remove (fname )
130
122
131
- # atexit.register(try_to_remove, osp.abspath(fname))
132
123
atexit .register (try_to_remove , str (Path (fname ).resolve ()))
133
124
134
125
@@ -147,8 +138,6 @@ def to_include_files(data_files):
147
138
include_files = []
148
139
for dest_dir , fnames in data_files :
149
140
for source_fname in fnames :
150
- #dest_fname = osp.join(
151
- # dest_dir, osp.basename(source_fname))
152
141
dest_fname = str (Path (dest_dir ) /
153
142
Path (source_fname ).name )
154
143
include_files .append ((source_fname , dest_fname ))
@@ -284,7 +273,6 @@ def setup(
284
273
else version
285
274
)
286
275
self .description = description
287
- # assert osp.isfile(script)
288
276
assert Path (script ).is_file ()
289
277
self .script = script
290
278
self .target_name = target_name
@@ -348,7 +336,6 @@ def add_pyqt4(self):
348
336
349
337
import PyQt4
350
338
351
- # pyqt_path = osp.dirname(PyQt4.__file__)
352
339
pyqt_path = str (Path (PyQt4 .__file__ ).parent )
353
340
354
341
# Configuring PyQt4
@@ -361,11 +348,9 @@ def add_pyqt4(self):
361
348
if self .msvc :
362
349
vc90man = "Microsoft.VC90.CRT.manifest"
363
350
pyqt_tmp = 'pyqt_tmp'
364
- # if osp.isdir(pyqt_tmp):
365
351
if Path (pyqt_tmp ).is_dir ():
366
352
shutil .rmtree (pyqt_tmp )
367
353
os .mkdir (pyqt_tmp )
368
- # vc90man_pyqt = osp.join(pyqt_tmp, vc90man)
369
354
vc90man_pyqt = str (Path (pyqt_tmp ) / vc90man )
370
355
man = (
371
356
open (vc90man , "r" )
@@ -377,20 +362,16 @@ def add_pyqt4(self):
377
362
)
378
363
open (vc90man_pyqt , 'w' ).write (man )
379
364
for dirpath , _ , filenames in os .walk (
380
- # osp.join(pyqt_path, "plugins")
381
365
str (Path (pyqt_path ) / "plugins" )
382
366
):
383
367
filelist = [
384
- # osp.join(dirpath, f)
385
368
str (Path (dirpath ) / f )
386
369
for f in filenames
387
- # if osp.splitext(f)[1] in ('.dll', '.py')
388
370
if Path (f ).suffix in ('.dll' , '.py' )
389
371
]
390
372
if self .msvc and [
391
373
f
392
374
for f in filelist
393
- # if osp.splitext(f)[1] == '.dll'
394
375
if Path (f ).suffix == '.dll'
395
376
]:
396
377
# Where there is a DLL build with Microsoft Visual C++ 2008,
@@ -408,11 +389,7 @@ def add_pyqt4(self):
408
389
if self .msvc :
409
390
atexit .register (remove_dir , pyqt_tmp )
410
391
# Including french translation
411
- # fr_trans = osp.join(
412
- # pyqt_path, "translations", "qt_fr.qm"
413
- # )
414
392
fr_trans = str (Path (pyqt_path ) / "translations" / "qt_fr.qm" )
415
- # if osp.exists(fr_trans):
416
393
if Path (fr_trans ).exists ():
417
394
self .data_files .append (
418
395
('translations' , (fr_trans ,))
@@ -443,7 +420,6 @@ def add_pyside(self):
443
420
444
421
import PySide
445
422
446
- # pyside_path = osp.dirname(PySide.__file__)
447
423
pyside_path = str (Path (PySide .__file__ ).parent )
448
424
449
425
# Configuring PySide
@@ -456,7 +432,6 @@ def add_pyside(self):
456
432
if self .msvc :
457
433
vc90man = "Microsoft.VC90.CRT.manifest"
458
434
os .mkdir ('pyside_tmp' )
459
- # vc90man_pyside = osp.join('pyside_tmp', vc90man)
460
435
vc90man_pyside = str (Path ('pyside_tmp' ) / vc90man )
461
436
man = (
462
437
open (vc90man , "r" )
@@ -468,20 +443,16 @@ def add_pyside(self):
468
443
)
469
444
open (vc90man_pyside , 'w' ).write (man )
470
445
for dirpath , _ , filenames in os .walk (
471
- # osp.join(pyside_path, "plugins")
472
446
str (Path (pyside_path ) / "plugins" )
473
447
):
474
448
filelist = [
475
- # osp.join(dirpath, f)
476
449
str (Path (dirpath ) / f )
477
450
for f in filenames
478
- # if osp.splitext(f)[1] in ('.dll', '.py')
479
451
if Path (f ).suffix in ('.dll' , '.py' )
480
452
]
481
453
if self .msvc and [
482
454
f
483
455
for f in filelist
484
- # if osp.splitext(f)[1] == '.dll'
485
456
if Path (f ).suffix == '.dll'
486
457
]:
487
458
# Where there is a DLL build with Microsoft Visual C++ 2008,
@@ -499,21 +470,16 @@ def add_pyside(self):
499
470
# Replacing dlls found by cx_Freeze by the real PySide Qt dlls:
500
471
# (http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows)
501
472
dlls = [
502
- # osp.join(pyside_path, fname)
503
473
str (Path (pyside_path ) / fname )
504
474
for fname in os .listdir (pyside_path )
505
- #if osp.splitext(fname)[1] == '.dll'
506
475
if Path (fname ).suffix == '.dll'
507
476
]
508
477
self .data_files .append (('' , dlls ))
509
478
510
479
if self .msvc :
511
480
atexit .register (remove_dir , 'pyside_tmp' )
512
481
# Including french translation
513
- # fr_trans = osp.join(
514
- # pyside_path, "translations", "qt_fr.qm")
515
482
fr_trans = str (Path (pyside_path ) / "translations" / "qt_fr.qm" )
516
- #if osp.exists(fr_trans):
517
483
if Path (fr_trans ).exists ():
518
484
self .data_files .append (
519
485
('translations' , (fr_trans ,))
@@ -603,9 +569,6 @@ def add_modules(self, *module_names):
603
569
(
604
570
'' ,
605
571
(
606
- #osp.join(
607
- # get_module_path('h5py'),
608
- # 'zlib1.dll',
609
572
str (Path (get_module_path ('h5py' )) / 'zlib1.dll'
610
573
),
611
574
),
@@ -632,14 +595,11 @@ def add_modules(self, *module_names):
632
595
import sphinx .ext
633
596
634
597
for fname in os .listdir (
635
- #osp.dirname(sphinx.ext.__file__)
636
598
str (Path (sphinx .ext .__file__ ).parent )
637
599
):
638
- #if osp.splitext(fname)[1] == '.py':
639
600
if Path (fname ).suffix == '.py' :
640
601
modname = (
641
602
'sphinx.ext.%s'
642
- # % osp.splitext(fname)[0]
643
603
% Path (fname ).stem
644
604
)
645
605
self .includes .append (modname )
@@ -721,11 +681,8 @@ def add_module_data_dir(
721
681
*extensions*: list of file extensions, e.g. ('.png', '.svg')
722
682
"""
723
683
module_dir = get_module_path (module_name )
724
- # nstrip = len(module_dir) + len(osp.sep)
725
684
nstrip = len (module_dir ) + len (os .sep )
726
- # data_dir = osp.join(module_dir, data_dir_name)
727
685
data_dir = str (Path (module_dir ) / data_dir_name )
728
- # if not osp.isdir(data_dir):
729
686
if not Path (data_dir ).is_dir ():
730
687
raise IOError (
731
688
"Directory not found: %s" % data_dir
@@ -734,17 +691,13 @@ def add_module_data_dir(
734
691
data_dir
735
692
):
736
693
dirname = dirpath [nstrip :]
737
- #if osp.basename(dirpath) in exclude_dirs:
738
694
if Path (dirpath ).name in exclude_dirs :
739
695
continue
740
696
if not copy_to_root :
741
- # dirname = osp.join(module_name, dirname)
742
697
dirname = str (Path (module_name ) / dirname )
743
698
pathlist = [
744
- # osp.join(dirpath, f)
745
699
str (Path (dirpath ) / f )
746
700
for f in filenames
747
- # if osp.splitext(f)[1].lower() in extensions
748
701
if Path (f ).suffix .lower () in extensions
749
702
]
750
703
self .data_files .append ((dirname , pathlist ))
@@ -784,25 +737,11 @@ def add_module_data_files(
784
737
verbose ,
785
738
exclude_dirs ,
786
739
)
787
- #translation_file = osp.join(
788
- # module_dir,
789
- # "locale",
790
- # "fr",
791
- # "LC_MESSAGES",
792
- # "%s.mo" % module_name,
793
- #)
794
740
translation_file = str (Path (module_dir ) / "locale" / "fr" /
795
741
"LC_MESSAGES" / f"{ module_name } .mo" )
796
- # if osp.isfile(translation_file):
797
742
if Path (translation_file ).is_file ():
798
743
self .data_files .append (
799
744
(
800
- #osp.join(
801
- # module_name,
802
- # "locale",
803
- # "fr",
804
- # "LC_MESSAGES",
805
- #),
806
745
str (Path (
807
746
module_name ) /
808
747
"locale" /
@@ -815,7 +754,6 @@ def add_module_data_files(
815
754
"Adding module '%s' translation file: %s"
816
755
% (
817
756
module_name ,
818
- #osp.basename(translation_file),
819
757
Path (translation_file ).name ,
820
758
)
821
759
)
@@ -854,7 +792,6 @@ def build(
854
792
def __cleanup (self ):
855
793
"""Remove old build and dist directories"""
856
794
remove_dir ("build" )
857
- # if osp.isdir("dist"):
858
795
if Path ("dist" ).is_dir ():
859
796
remove_dir ("dist" )
860
797
remove_dir (self .target_dir )
@@ -911,7 +848,6 @@ def build_py2exe(
911
848
icon_resources = [(0 , self .icon )],
912
849
bitmap_resources = [],
913
850
other_resources = [],
914
- # dest_base=osp.splitext(self.target_name)[0],
915
851
dest_base = Path (self .target_name ).stem ,
916
852
version = self .version ,
917
853
company_name = company_name ,
0 commit comments