forked from winpython/winpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
2219 lines (1998 loc) · 68.3 KB
/
make.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#
# Copyright © 2012 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see winpython/__init__.py for details)
"""
WinPython build script
Created on Sun Aug 12 11:17:50 2012
"""
from __future__ import print_function
import os
import os.path as osp
import re
import subprocess
import shutil
import sys
# Local imports
from winpython import disthelpers as dh
from winpython import wppm, utils
import diff
CHANGELOGS_DIR = osp.join(
osp.dirname(__file__), 'changelogs'
)
assert osp.isdir(CHANGELOGS_DIR)
def get_drives():
"""Return all active drives"""
import win32api
return win32api.GetLogicalDriveStrings().split('\000')[
:-1
]
def get_nsis_exe():
"""Return NSIS executable"""
localdir = osp.join(sys.prefix, os.pardir, os.pardir)
for drive in get_drives():
for dirname in (
r'C:\Program Files',
r'C:\Program Files (x86)',
drive + r'PortableApps\NSISPortableANSI',
drive + r'PortableApps\NSISPortable',
osp.join(localdir, 'NSISPortableANSI'),
osp.join(localdir, 'NSISPortable'),
):
for subdirname in ('.', 'App'):
exe = osp.join(
dirname,
subdirname,
'NSIS',
'makensis.exe',
)
if osp.isfile(exe):
return exe
else:
raise RuntimeError(
"NSIS is not installed on this computer."
)
NSIS_EXE = get_nsis_exe() # NSIS Compiler
def get_iscc_exe():
"""Return ISCC executable"""
localdir = osp.join(sys.prefix, os.pardir, os.pardir)
for drive in get_drives():
for dirname in (
r'C:\Program Files',
r'C:\Program Files (x86)',
# drive+r'PortableApps\NSISPortableANSI',
# drive+r'PortableApps\NSISPortable',
# osp.join(localdir, 'NSISPortableANSI'),
osp.join(localdir, 'Inno Setup 5'),
):
for subdirname in ('.', 'App'):
exe = osp.join(
dirname,
subdirname,
'Inno Setup 5',
'iscc.exe',
)
if osp.isfile(exe):
return exe
else:
raise RuntimeError(
"Inno Setup 5 is not installed on this computer."
)
ISCC_EXE = get_iscc_exe() # Inno Setup Compiler (iscc.exe)
def get_7zip_exe():
"""Return 7zip executable"""
localdir = osp.join(sys.prefix, os.pardir, os.pardir)
for drive in get_drives():
for dirname in (
r'C:\Program Files',
r'C:\Program Files (x86)',
osp.join(localdir, '7-Zip'),
):
for subdirname in ('.', 'App'):
exe = osp.join(
dirname, subdirname, '7-Zip', '7z.exe'
)
# include = osp.join(dirname, subdirname, '7-Zip', 'include')
if osp.isfile(exe):
return exe
else:
raise RuntimeError(
"7-Zip is not installed on this computer."
)
SEVENZIP_EXE = (
get_7zip_exe()
) # Inno Setup Compiler (iscc.exe)
def replace_in_nsis_file(fname, data):
"""Replace text in line starting with *start*, from this position:
data is a list of (start, text) tuples"""
fd = open(fname, 'U')
lines = fd.readlines()
fd.close()
for idx, line in enumerate(lines):
for start, text in data:
if start not in (
'Icon',
'OutFile',
) and not start.startswith('!'):
start = '!define ' + start
if line.startswith(start + ' '):
lines[idx] = (
line[: len(start) + 1]
+ ('"%s"' % text)
+ '\n'
)
fd = open(fname, 'w')
fd.writelines(lines)
print('iss for ', fname, 'is', lines)
fd.close()
def replace_in_iss_file(fname, data):
"""Replace text in line starting with *start*, from this position:
data is a list of (start, text) tuples"""
fd = open(fname, 'U')
lines = fd.readlines()
fd.close()
for idx, line in enumerate(lines):
for start, text in data:
if start not in (
'Icon',
'OutFile',
) and not start.startswith('!'):
start = '#define ' + start
if line.startswith(start + ' '):
lines[idx] = (
line[: len(start) + 1]
+ ('"%s"' % text)
+ '\n'
)
fd = open(fname, 'w')
fd.writelines(lines)
print('Inno Setup for ', fname, 'is', lines)
fd.close()
def replace_in_7zip_file(fname, data):
"""Replace text in line starting with *start*, from this position:
data is a list of (start, text) tuples"""
fd = open(fname, 'U')
lines = fd.readlines()
fd.close()
for idx, line in enumerate(lines):
for start, text in data:
if start not in (
'Icon',
'OutFile',
) and not start.startswith('!'):
start = 'set ' + start
if line.startswith(start + '='):
lines[idx] = (
line[: len(start) + 1]
+ ('%s' % text)
+ '\n'
)
fd = open(fname, 'w')
fd.writelines(lines)
print('7-zip for ', fname, 'is', lines)
fd.close()
def build_nsis(srcname, dstname, data):
"""Build NSIS script"""
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
shutil.copy(osp.join(portable_dir, srcname), dstname)
data = [
(
'!addincludedir',
osp.join(portable_dir, 'include'),
)
] + list(data)
replace_in_nsis_file(dstname, data)
try:
retcode = subprocess.call(
'"%s" -V2 "%s"' % (NSIS_EXE, dstname),
shell=True,
stdout=sys.stderr,
)
if retcode < 0:
print(
"Child was terminated by signal",
-retcode,
file=sys.stderr,
)
except OSError as e:
print("Execution failed:", e, file=sys.stderr)
os.remove(dstname)
def build_iss(srcname, dstname, data):
"""Build Inno Setup Script"""
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
shutil.copy(osp.join(portable_dir, srcname), dstname)
data = [('PORTABLE_DIR', portable_dir)] + list(data)
replace_in_iss_file(dstname, data)
try:
retcode = subprocess.call(
'"%s" "%s"' % (ISCC_EXE, dstname),
shell=True,
stdout=sys.stderr,
)
if retcode < 0:
print(
"Child was terminated by signal",
-retcode,
file=sys.stderr,
)
except OSError as e:
print("Execution failed:", e, file=sys.stderr)
# os.remove(dstname)
def build_7zip(srcname, dstname, data):
"""7-Zip Setup Script"""
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
shutil.copy(osp.join(portable_dir, srcname), dstname)
data = [
('PORTABLE_DIR', portable_dir),
('SEVENZIP_EXE', SEVENZIP_EXE),
] + list(data)
replace_in_7zip_file(dstname, data)
try:
# insted of a 7zip command line, we launch a script that does it
# retcode = subprocess.call('"%s" "%s"' % (SEVENZIP_EXE, dstname),
retcode = subprocess.call(
'"%s" ' % (dstname),
shell=True,
stdout=sys.stderr,
)
if retcode < 0:
print(
"Child was terminated by signal",
-retcode,
file=sys.stderr,
)
except OSError as e:
print("Execution failed:", e, file=sys.stderr)
# os.remove(dstname)
class WinPythonDistribution(object):
"""WinPython distribution"""
MINGW32_PATH = r'\t\mingw32\bin'
R_PATH = r'\t\R\bin'
JULIA_PATH = r'\t\Julia\bin'
NODEJS_PATH = r'\n' # r'\t\n'
def __init__(
self,
build_number,
release_level,
target,
wheeldir,
toolsdirs=None,
verbose=False,
simulation=False,
basedir=None,
install_options=None,
flavor='',
docsdirs=None,
):
assert isinstance(build_number, int)
assert isinstance(release_level, str)
self.build_number = build_number
self.release_level = release_level
self.target = target
self.wheeldir = wheeldir
if toolsdirs is None:
toolsdirs = []
self._toolsdirs = toolsdirs
if docsdirs is None:
docsdirs = []
self._docsdirs = docsdirs
self.verbose = verbose
self.winpydir = None
self.distribution = None
self.installed_packages = []
self.simulation = simulation
self.basedir = (
basedir
) # added to build from winpython
self.install_options = install_options
self.flavor = flavor
self.python_fname = self.get_package_fname(
r'python-([0-9\.rcba]*)((\.|\-)amd64)?\.(zip|zip)'
)
self.python_name = osp.basename(self.python_fname)[
:-4
]
self.distname = 'win%s' % self.python_name
vlst = (
re.match(r'winpython-([0-9\.]*)', self.distname)
.groups()[0]
.split('.')
)
self.python_version = '.'.join(vlst[:2])
self.python_fullversion = '.'.join(vlst[:3])
@property
def package_index_wiki(self):
"""Return Package Index page in Wiki format"""
installed_tools = []
def get_tool_path(relpath, checkfunc):
if self.simulation:
for dirname in self.toolsdirs:
path = dirname + relpath.replace(
r'\t', ''
)
if checkfunc(path):
return path
else:
path = self.winpydir + relpath
if checkfunc(path):
return path
if get_tool_path(r'\t\SciTE.exe', osp.isfile):
installed_tools += [('SciTE', '3.3.7')]
rpath = get_tool_path(self.R_PATH, osp.isdir)
if rpath is not None:
rver = utils.get_r_version(rpath)
installed_tools += [('R', rver)]
juliapath = get_tool_path(
self.JULIA_PATH, osp.isdir
)
if juliapath is not None:
juliaver = utils.get_julia_version(juliapath)
installed_tools += [('Julia', juliaver)]
nodepath = get_tool_path(
self.NODEJS_PATH, osp.isdir
)
if nodepath is not None:
nodever = utils.get_nodejs_version(nodepath)
installed_tools += [('Nodejs', nodever)]
npmver = utils.get_npmjs_version(nodepath)
installed_tools += [('npmjs', npmver)]
pandocexe = get_tool_path(
r'\t\pandoc.exe', osp.isfile
)
if pandocexe is not None:
pandocver = utils.get_pandoc_version(
osp.dirname(pandocexe)
)
installed_tools += [('Pandoc', pandocver)]
vscodeexe = get_tool_path(r'\t\VSCode\Code.exe', osp.isfile)
if vscodeexe is not None:
installed_tools += [('VSCode',
utils.getFileProperties(vscodeexe)['FileVersion'])]
tools = []
for name, ver in installed_tools:
metadata = wppm.get_package_metadata(
'tools.ini', name
)
url, desc = (
metadata['url'],
metadata['description'],
)
tools += [
'[%s](%s) | %s | %s'
% (name, url, ver, desc)
]
# get all packages installed in the changelog, whatever the method
self.installed_packages = (
self.distribution.get_installed_packages(update=True)
)
packages = [
'[%s](%s) | %s | %s'
% (
pack.name,
pack.url,
pack.version,
pack.description,
)
for pack in sorted(
self.installed_packages,
key=lambda p: p.name.lower(),
)
]
python_desc = 'Python programming language with standard library'
return """## WinPython %s
The following packages are included in WinPython-%sbit v%s%s.
### Tools
Name | Version | Description
-----|---------|------------
%s
### Python packages
Name | Version | Description
-----|---------|------------
[Python](http://www.python.org/) | %s | %s
%s""" % (
self.winpyver2 + self.flavor,
self.winpy_arch,
self.winpyver2 + self.flavor,
(' %s' % self.release_level),
'\n'.join(tools),
self.python_fullversion,
python_desc,
'\n'.join(packages),
)
# @property makes self.winpyver becomes a call to self.winpyver()
@property
def winpyver(self):
"""Return WinPython version (with flavor and release level!)"""
return '%s.%d%s%s' % (
self.python_fullversion,
self.build_number,
self.flavor,
self.release_level,
)
@property
def python_dir(self):
"""Return Python dirname (full path) of the target distribution"""
return osp.join(self.winpydir, self.python_name)
@property
def winpy_arch(self):
"""Return WinPython architecture"""
return '%d' % self.distribution.architecture
@property
def py_arch(self):
"""Return distribution architecture, in Python distutils format:
win-amd64 or win32"""
if self.distribution.architecture == 64:
return 'win-amd64'
else:
return 'win32'
@property
def prepath(self):
"""Return PATH contents to be prepend to the environment variable"""
path = [
r"Lib\site-packages\PyQt5",
r"Lib\site-packages\PySide2",
"", # Python root directory
"DLLs",
"Scripts",
r"..\t",
r"..\t\mingw32\bin",
]
if (
self.distribution.architecture == 32
and osp.isdir(self.winpydir + self.MINGW32_PATH)
):
path += [r".." + self.MINGW32_PATH]
if self.distribution.architecture == 32:
path += [r".." + self.R_PATH + r"\i386"]
if self.distribution.architecture == 64:
path += [r".." + self.R_PATH + r"\x64"]
path += [r".." + self.JULIA_PATH]
path += [r".." + self.NODEJS_PATH]
return path
@property
def postpath(self):
"""Return PATH contents to be append to the environment variable"""
path = []
# if osp.isfile(self.winpydir + self.THG_PATH):
# path += [r"..\t\TortoiseHg"]
return path
@property
def toolsdirs(self):
"""Return tools directory list"""
return [
osp.join(
osp.dirname(osp.abspath(__file__)), 't'
)
] + self._toolsdirs
@property
def docsdirs(self):
"""Return docs directory list"""
if osp.isdir(
osp.join(
osp.dirname(osp.abspath(__file__)), 'docs'
)
):
return [
osp.join(
osp.dirname(osp.abspath(__file__)),
'docs',
)
] + self._docsdirs
else:
return self._docsdirs
def get_package_fname(self, pattern):
"""Get package matching pattern in wheeldir"""
path = self.wheeldir
for fname in os.listdir(path):
match = re.match(pattern, fname)
if match is not None or pattern == fname:
return osp.abspath(osp.join(path, fname))
else:
raise RuntimeError(
'Could not find required package matching %s'
% pattern
)
def create_batch_script(self, name, contents):
"""Create batch script %WINPYDIR%/name"""
scriptdir = osp.join(self.winpydir, 'scripts')
if not osp.isdir(scriptdir):
os.mkdir(scriptdir)
fd = open(osp.join(scriptdir, name), 'w')
fd.write(contents)
fd.close()
def create_launcher(
self,
name,
icon,
command=None,
args=None,
workdir=r'$EXEDIR\scripts',
launcher='launcher_basic.nsi',
):
"""Create exe launcher with NSIS"""
assert name.endswith('.exe')
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
icon_fname = osp.join(portable_dir, 'icons', icon)
assert osp.isfile(icon_fname)
# Customizing NSIS script
if command is None:
if args is not None and '.pyw' in args:
command = '${WINPYDIR}\pythonw.exe'
else:
command = '${WINPYDIR}\python.exe'
if args is None:
args = ''
if workdir is None:
workdir = ''
fname = osp.join(
self.winpydir, osp.splitext(name)[0] + '.nsi'
)
data = [
('WINPYDIR', '$EXEDIR\%s' % self.python_name),
('WINPYVER', self.winpyver),
('COMMAND', command),
('PARAMETERS', args),
('WORKDIR', workdir),
('Icon', icon_fname),
('OutFile', name),
]
build_nsis(launcher, fname, data)
def create_python_batch(
self,
name,
script_name,
workdir=None,
options=None,
command=None,
):
"""Create batch file to run a Python script"""
if options is None:
options = ''
else:
options = ' ' + options
if command is None:
if script_name.endswith('.pyw'):
command = 'start "%WINPYDIR%\pythonw.exe"'
else:
command = '"%WINPYDIR%\python.exe"'
changedir = ''
if workdir is not None:
workdir = workdir
changedir = (
r"""cd/D %s
"""
% workdir
)
if script_name:
script_name = ' ' + script_name
self.create_batch_script(
name,
r"""@echo off
call "%~dp0env_for_icons.bat"
"""
+ changedir
+ command
+ script_name
+ options
+ " %*",
)
def create_installer(self):
"""Create installer with NSIS"""
self._print("Creating WinPython installer")
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
fname = osp.join(portable_dir, 'installer-tmp.nsi')
data = (
('DISTDIR', self.winpydir),
('ARCH', self.winpy_arch),
(
'VERSION',
'%s.%d%s'
% (
self.python_fullversion,
self.build_number,
self.flavor,
),
),
(
'VERSION_INSTALL',
'%s%d'
% (
self.python_fullversion.replace(
'.', ''
),
self.build_number,
),
),
('RELEASELEVEL', self.release_level),
)
build_nsis('installer.nsi', fname, data)
self._print_done()
def create_installer_inno(self):
"""Create installer with INNO"""
self._print("Creating WinPython installer INNO")
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
fname = osp.join(
portable_dir, 'installer_INNO-tmp.iss'
)
data = (
('DISTDIR', self.winpydir),
('ARCH', self.winpy_arch),
(
'VERSION',
'%s.%d%s'
% (
self.python_fullversion,
self.build_number,
self.flavor,
),
),
(
'VERSION_INSTALL',
'%s%d'
% (
self.python_fullversion.replace(
'.', ''
),
self.build_number,
),
),
('RELEASELEVEL', self.release_level),
)
build_iss('installer_INNO.iss', fname, data)
self._print_done()
def create_installer_7zip(self, installer_option=''):
"""Create installer with 7-ZIP"""
self._print("Creating WinPython installer 7-ZIP")
portable_dir = osp.join(
osp.dirname(osp.abspath(__file__)), 'portable'
)
fname = osp.join(
portable_dir, 'installer_7zip-tmp.bat'
)
data = (
('DISTDIR', self.winpydir),
('ARCH', self.winpy_arch),
(
'VERSION',
'%s.%d%s'
% (
self.python_fullversion,
self.build_number,
self.flavor,
),
),
(
'VERSION_INSTALL',
'%s%d'
% (
self.python_fullversion.replace(
'.', ''
),
self.build_number,
),
),
('RELEASELEVEL', self.release_level),
)
data += (('INSTALLER_OPTION', installer_option),)
build_7zip('installer_7zip.bat', fname, data)
self._print_done()
def _print(self, text):
"""Print action text indicating progress"""
if self.verbose:
utils.print_box(text)
else:
print(text + '...', end=" ")
def _print_done(self):
"""Print OK at the end of a process"""
if not self.verbose:
print("OK")
def _extract_python(self):
"""Extracting Python installer, creating distribution object"""
self._print("Extracting Python .zip version")
utils.extract_archive(
self.python_fname,
targetdir=self.python_dir + r'\..',
)
self._print_done()
def _add_msvc_files(self):
"""Adding Microsoft Visual C++ DLLs"""
print("Adding Microsoft Visual C++ DLLs" "")
msvc_version = dh.get_msvc_version(
self.distribution.version
)
for fname in dh.get_msvc_dlls(
msvc_version,
architecture=self.distribution.architecture,
):
shutil.copy(fname, self.python_dir)
def _copy_dev_tools(self):
"""Copy dev tools"""
self._print("Copying tools")
toolsdir = osp.join(self.winpydir, 't')
os.mkdir(toolsdir)
for (
dirname
) in (
self.toolsdirs
): # the ones in the make.py script environment
for name in os.listdir(dirname):
path = osp.join(dirname, name)
copy = (
shutil.copytree
if osp.isdir(path)
else shutil.copyfile
)
if self.verbose:
print(
path
+ ' --> '
+ osp.join(toolsdir, name)
)
copy(path, osp.join(toolsdir, name))
self._print_done()
# move node higher
nodejs_current = osp.join(toolsdir, 'n')
nodejs_target = self.winpydir + self.NODEJS_PATH
if nodejs_current != nodejs_target and osp.isdir(
nodejs_current
):
shutil.move(nodejs_current, nodejs_target)
def _copy_dev_docs(self):
"""Copy dev docs"""
self._print("Copying Noteebook docs")
docsdir = osp.join(self.winpydir, 'notebooks')
if not osp.isdir(docsdir):
os.mkdir(docsdir)
docsdir = osp.join(
self.winpydir, 'notebooks', 'docs'
)
if not osp.isdir(docsdir):
os.mkdir(docsdir)
for dirname in self.docsdirs:
for name in os.listdir(dirname):
path = osp.join(dirname, name)
copy = (
shutil.copytree
if osp.isdir(path)
else shutil.copyfile
)
copy(path, osp.join(docsdir, name))
if self.verbose:
print(
path
+ ' --> '
+ osp.join(docsdir, name)
)
self._print_done()
def _create_launchers(self):
"""Create launchers"""
self._print("Creating launchers")
self.create_launcher(
'WinPython Command Prompt.exe',
'cmd.ico',
command='$SYSDIR\cmd.exe',
args=r'/k cmd.bat',
)
self.create_launcher(
'WinPython Powershell Prompt.exe',
'powershell.ico',
command='$SYSDIR\cmd.exe',
args=r'/k cmd_ps.bat',
)
self.create_launcher(
'WinPython Interpreter.exe',
'python.ico',
command='$SYSDIR\cmd.exe',
args=r'/k winpython.bat',
)
self.create_launcher(
'IDLEX.exe',
'python.ico',
command='wscript.exe',
args=r'Noshell.vbs winidlex.bat',
)
self.create_launcher(
'IDLE (Python GUI).exe',
'python.ico',
command='wscript.exe',
args=r'Noshell.vbs winidle.bat',
)
self.create_launcher(
'Spyder.exe',
'spyder.ico',
command='wscript.exe',
args=r'Noshell.vbs winspyder.bat',
)
self.create_launcher(
'Spyder reset.exe',
'spyder_reset.ico',
command='wscript.exe',
args=r'Noshell.vbs spyder_reset.bat',
)
self.create_launcher(
'WinPython Control Panel.exe',
'winpython.ico',
command='wscript.exe',
args=r'Noshell.vbs wpcp.bat',
)
# Multi-Qt launchers
self.create_launcher(
'Qt Designer.exe',
'qtdesigner.ico',
command='wscript.exe',
args=r'Noshell.vbs qtdesigner.bat',
)
self.create_launcher(
'Qt Linguist.exe',
'qtlinguist.ico',
command='wscript.exe',
args=r'Noshell.vbs qtlinguist.bat',
)
# Jupyter launchers
self.create_launcher(
'IPython Qt Console.exe',
'ipython.ico',
command='wscript.exe',
args=r'Noshell.vbs winqtconsole.bat',
)
# this one needs a shell to kill fantom processes
self.create_launcher(
'Jupyter Notebook.exe',
'jupyter.ico',
command='$SYSDIR\cmd.exe',
args=r'/k winipython_notebook.bat',
)
self.create_launcher(
'Jupyter Lab.exe',
'jupyter.ico',
command='$SYSDIR\cmd.exe',
args=r'/k winjupyter_lab.bat',
)
self.create_launcher(
'Pyzo.exe',
'pyzologo.ico',
command='wscript.exe',
args=r'Noshell.vbs winpyzo.bat',
)
# VSCode launcher
self.create_launcher(
'VS Code.exe',
'code.ico',
command='wscript.exe',
args=r'Noshell.vbs winvscode.bat',
)
self._print_done()
def _create_batch_scripts_initial(self):
"""Create batch scripts"""
self._print("Creating batch scripts initial")
conv = lambda path: ";".join(
['%WINPYDIR%\\' + pth for pth in path]
)
path = (
conv(self.prepath)
+ ";%PATH%;"
+ conv(self.postpath)
)
convps = lambda path: ";".join(
["$env:WINPYDIR\\" + pth for pth in path]
)
pathps = (
convps(self.prepath)
+ ";$env:path;"
+ convps(self.postpath)
)
self.create_batch_script(
'env.bat',
r"""@echo off
set WINPYDIRBASE=%~dp0..
rem get a normalize path
set WINPYDIRBASETMP=%~dp0..
pushd %WINPYDIRBASETMP%