Skip to content

Commit c6bc2f3

Browse files
committed
partial remove osp from make.py
1 parent 5bbf3a2 commit c6bc2f3

File tree

1 file changed

+58
-29
lines changed

1 file changed

+58
-29
lines changed

make.py

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
# osp.dirname(__file__), 'changelogs'
3030
# )
3131
CHANGELOGS_DIR = str(Path(__file__).parent / 'changelogs')
32-
assert osp.isdir(CHANGELOGS_DIR)
32+
# assert osp.isdir(CHANGELOGS_DIR)
33+
assert Path(CHANGELOGS_DIR).is_dir()
3334

3435

3536
def get_drives():
@@ -51,8 +52,10 @@ def get_nsis_exe():
5152
r'C:\Program Files (x86)',
5253
drive + r'PortableApps\NSISPortableANSI',
5354
drive + r'PortableApps\NSISPortable',
54-
osp.join(localdir, 'NSISPortableANSI'),
55-
osp.join(localdir, 'NSISPortable'),
55+
# osp.join(localdir, 'NSISPortableANSI'),
56+
str(Path(localdir) / 'NSISPortableANSI'),
57+
# osp.join(localdir, 'NSISPortable'),
58+
str(Path(localdir) / 'NSISPortable'),
5659
):
5760
for subdirname in ('.', 'App'):
5861
exe = osp.join(
@@ -61,7 +64,8 @@ def get_nsis_exe():
6164
'NSIS',
6265
'makensis.exe',
6366
)
64-
if osp.isfile(exe):
67+
# if osp.isfile(exe):
68+
if Path(exe).is_file():
6569
return exe
6670
else:
6771
raise RuntimeError(
@@ -83,7 +87,8 @@ def get_iscc_exe():
8387
# drive+r'PortableApps\NSISPortableANSI',
8488
# drive+r'PortableApps\NSISPortable',
8589
# osp.join(localdir, 'NSISPortableANSI'),
86-
osp.join(localdir, 'Inno Setup 5'),
90+
# osp.join(localdir, 'Inno Setup 5'),
91+
str(Path(localdir) / 'Inno Setup 5'),
8792
):
8893
for subdirname in ('.', 'App'):
8994
exe = osp.join(
@@ -92,7 +97,8 @@ def get_iscc_exe():
9297
'Inno Setup 5',
9398
'iscc.exe',
9499
)
95-
if osp.isfile(exe):
100+
# if osp.isfile(exe):
101+
if Path(exe).is_file():
96102
return exe
97103
else:
98104
#raise RuntimeError(
@@ -111,14 +117,16 @@ def get_7zip_exe():
111117
for dirname in (
112118
r'C:\Program Files',
113119
r'C:\Program Files (x86)',
114-
osp.join(localdir, '7-Zip'),
120+
# osp.join(localdir, '7-Zip'),
121+
str(Path(localdir) / '7-Zip'),
115122
):
116123
for subdirname in ('.', 'App'):
117124
exe = osp.join(
118125
dirname, subdirname, '7-Zip', '7z.exe'
119126
)
120127
# include = osp.join(dirname, subdirname, '7-Zip', 'include')
121-
if osp.isfile(exe):
128+
# if osp.isfile(exe):
129+
if Path(exe).is_file():
122130
return exe
123131
else:
124132
raise RuntimeError(
@@ -215,7 +223,8 @@ def build_nsis(srcname, dstname, data):
215223
data = [
216224
(
217225
'!addincludedir',
218-
osp.join(portable_dir, 'include'),
226+
# osp.join(portable_dir, 'include'),
227+
str(Path(portable_dir) / 'include'),
219228
)
220229
] + list(data)
221230
replace_in_nsis_file(dstname, data)
@@ -350,7 +359,8 @@ def __init__(
350359

351360
# osp.join(self.winpydir, self.python_name) = Directory of Python exec
352361
# self.pythondir =osp.join(self.winpydir, self.python_name)
353-
self.python_name = osp.basename(self.python_fname)[
362+
# self.python_name = osp.basename(self.python_fname)[
363+
self.python_name = Path(self.python_fname).name[
354364
:-4
355365
]
356366
self.distname = 'winUNKNOWN' #win%s' % self.python_name # PyPy ?
@@ -488,7 +498,8 @@ def winpyver(self):
488498
@property
489499
def python_dir(self):
490500
"""Return Python dirname (full path) of the target distribution"""
491-
return osp.join(self.winpydir, self.python_name) # python.exe path
501+
# return osp.join(self.winpydir, self.python_name) # python.exe path
502+
return str(Path(self.winpydir) / self.python_name) # python.exe path
492503

493504
@property
494505
def winpy_arch(self):
@@ -583,8 +594,10 @@ def get_package_fname(self, pattern):
583594
def create_batch_script(self, name, contents,
584595
do_changes=None):
585596
"""Create batch script %WINPYDIR%/name"""
586-
scriptdir = osp.join(self.winpydir, 'scripts')
587-
if not osp.isdir(scriptdir):
597+
# scriptdir = osp.join(self.winpydir, 'scripts')
598+
scriptdir = str(Path(self.winpydir) / 'scripts')
599+
# if not osp.isdir(scriptdir):
600+
if not Path(scriptdir).is_dir():
588601
os.mkdir(scriptdir)
589602
print ('dochanges for %s %', name, do_changes)
590603
# live patch pypy3
@@ -593,7 +606,8 @@ def create_batch_script(self, name, contents,
593606
for i in do_changes:
594607
contents_final = contents_final.replace(i[0], i[1])
595608

596-
fd = open(osp.join(scriptdir, name), 'w')
609+
# fd = open(osp.join(scriptdir, name), 'w')
610+
fd = open(str(Path(scriptdir) / name), 'w')
597611
fd.write(contents_final)
598612
fd.close()
599613

@@ -611,8 +625,10 @@ def create_launcher(
611625
portable_dir = osp.join(
612626
osp.dirname(osp.abspath(__file__)), 'portable'
613627
)
614-
icon_fname = osp.join(portable_dir, 'icons', icon)
615-
assert osp.isfile(icon_fname)
628+
# icon_fname = osp.join(portable_dir, 'icons', icon)
629+
icon_fname = str(Path(portable_dir) / 'icons' / icon)
630+
# assert osp.isfile(icon_fname)
631+
assert Path(icon_fname).is_file()
616632

617633
# Customizing NSIS script
618634
if command is None:
@@ -686,7 +702,8 @@ def create_installer(self):
686702
portable_dir = osp.join(
687703
osp.dirname(osp.abspath(__file__)), 'portable'
688704
)
689-
fname = osp.join(portable_dir, 'installer-tmp.nsi')
705+
# fname = osp.join(portable_dir, 'installer-tmp.nsi')
706+
fname = str(Path(portable_dir) / 'installer-tmp.nsi')
690707
data = (
691708
('DISTDIR', self.winpydir),
692709
('ARCH', self.winpy_arch),
@@ -811,30 +828,36 @@ def _extract_python(self):
811828
def _copy_dev_tools(self):
812829
"""Copy dev tools"""
813830
self._print(f"Copying tools from {self.toolsdirs} to {self.winpydir}/t")
814-
toolsdir = osp.join(self.winpydir, 't')
831+
# toolsdir = osp.join(self.winpydir, 't')
832+
toolsdir = str(Path(self.winpydir) / 't')
815833
os.mkdir(toolsdir)
816834
for (
817835
dirname
818836
) in (
819837
[ok_dir for ok_dir in self.toolsdirs if osp.isdir(ok_dir)]
820838
): # the ones in the make.py script environment
821839
for name in os.listdir(dirname):
822-
path = osp.join(dirname, name)
840+
# path = osp.join(dirname, name)
841+
path = str(Path(dirname) / name)
823842
copy = (
824843
shutil.copytree
825-
if osp.isdir(path)
844+
# if osp.isdir(path)
845+
if Path(path).is_dir()
826846
else shutil.copyfile
827847
)
828848
if self.verbose:
829849
print(
830850
path
831851
+ ' --> '
832-
+ osp.join(toolsdir, name)
852+
# + osp.join(toolsdir, name)
853+
+ str(Path(toolsdir) / name)
833854
)
834-
copy(path, osp.join(toolsdir, name))
855+
# copy(path, osp.join(toolsdir, name))
856+
copy(path, str(Path(toolsdir) / name))
835857
self._print_done()
836858
# move node higher
837-
nodejs_current = osp.join(toolsdir, 'n')
859+
# nodejs_current = osp.join(toolsdir, 'n')
860+
nodejs_current = str(Path(toolsdir) / 'n')
838861
nodejs_target = self.winpydir + self.NODEJS_PATH
839862
if nodejs_current != nodejs_target and osp.isdir(
840863
nodejs_current
@@ -843,29 +866,35 @@ def _copy_dev_tools(self):
843866

844867
def _copy_dev_docs(self):
845868
"""Copy dev docs"""
846-
docsdir = osp.join(self.winpydir, 'notebooks')
869+
# docsdir = osp.join(self.winpydir, 'notebooks')
870+
docsdir = str(Path(self.winpydir) / 'notebooks')
847871
self._print(f"Copying Noteebook docs from {self.docsdirs} to {docsdir}")
848-
if not osp.isdir(docsdir):
872+
# if not osp.isdir(docsdir):
873+
if not Path(docsdir).is_dir():
849874
os.mkdir(docsdir)
850875
docsdir = osp.join(
851876
self.winpydir, 'notebooks', 'docs'
852877
)
853-
if not osp.isdir(docsdir):
878+
# if not osp.isdir(docsdir):
879+
if not Path(docsdir).is_dir():
854880
os.mkdir(docsdir)
855881
for dirname in self.docsdirs:
856882
for name in os.listdir(dirname):
857-
path = osp.join(dirname, name)
883+
# path = osp.join(dirname, name)
884+
path = str(Path(dirname) / name)
858885
copy = (
859886
shutil.copytree
860-
if osp.isdir(path)
887+
# if osp.isdir(path)
888+
if Path(path).is_dir()
861889
else shutil.copyfile
862890
)
863891
copy(path, osp.join(docsdir, name))
864892
if self.verbose:
865893
print(
866894
path
867895
+ ' --> '
868-
+ osp.join(docsdir, name)
896+
# + osp.join(docsdir, name)
897+
+ str(Path(docsdir) / name)
869898
)
870899
self._print_done()
871900

0 commit comments

Comments
 (0)