Skip to content

Commit ffdb816

Browse files
committed
Merge pull request #268 from stonebig/master
a 'student' usage of WinPython
2 parents 90c851d + 8b152a7 commit ffdb816

File tree

2 files changed

+287
-15
lines changed

2 files changed

+287
-15
lines changed

make.py

Lines changed: 135 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ def create_batch_script(self, name, contents):
311311

312312
def create_launcher(self, name, icon, command=None,
313313
args=None, workdir=None, settingspath=None,
314-
bettercommand=None, betterworkdir=None, betterargs=None):
314+
bettercommand=None, betterworkdir=None, betterargs=None,
315+
launcher='launcher.nsi'):
315316
"""Create exe launcher with NSIS"""
316317
assert name.endswith('.exe')
317318
portable_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'portable')
@@ -365,7 +366,7 @@ def create_launcher(self, name, icon, command=None,
365366
data += [('SETTINGSDIR', osp.dirname(settingspath)),
366367
('SETTINGSNAME', osp.basename(settingspath))]
367368

368-
build_nsis('launcher.nsi', fname, data)
369+
build_nsis(launcher, fname, data)
369370

370371
def create_python_batch(self, name, script_name,
371372
workdir=None, options=None, command=None):
@@ -513,6 +514,8 @@ def _copy_dev_docs(self):
513514

514515
def _create_launchers(self):
515516
"""Create launchers"""
517+
518+
516519
self._print("Creating launchers")
517520
self.create_launcher('WinPython Command Prompt.exe', 'cmd.ico',
518521
command='$SYSDIR\cmd.exe',
@@ -526,13 +529,13 @@ def _create_launchers(self):
526529
self.create_launcher('IDLEX (Python GUI).exe', 'python.ico',
527530
args='idlex.pyw',
528531
workdir='${WINPYDIR}\Scripts')
529-
settingspath = osp.join('.spyder2', '.spyder.ini')
532+
settingspath = osp.join('.spyder-py3', '.spyder2', '.spyder.ini')
530533
self.create_launcher('Spyder.exe', 'spyder.ico',
531534
command='${WINPYDIR}\python.exe',
532535
args='-m spyderlib.start_app',
533536
workdir='${WINPYDIR}\Scripts',
534537
settingspath=settingspath)
535-
self.create_launcher('Spyder (reset).exe', 'spyder_reset.ico',
538+
self.create_launcher('Spyder reset.exe', 'spyder_reset.ico',
536539
command='${WINPYDIR}\python.exe',
537540
args='-m spyderlib.start_app --reset',
538541
workdir='${WINPYDIR}\Scripts',
@@ -572,35 +575,71 @@ def _create_launchers(self):
572575
bettercommand=Qt5_dir + r'\linguist.exe')
573576

574577
# Jupyter launchers
575-
if osp.isfile(osp.join(self.python_dir, 'Scripts', 'jupyter.exe')):
576-
self.create_launcher('IPython Qt Console.exe', 'ipython.ico',
578+
self.create_launcher('IPython Qt Console.exe', 'ipython.ico',
577579
command='${WINPYDIR}\Scripts\%s' %
578580
'jupyter-qtconsole.exe',
579-
workdir=r'${WINPYDIR}\..\notebooks')
581+
workdir=r'$EXEDIR\notebooks')
580582

581-
self.create_launcher('Jupyter Notebook.exe', 'jupyter.ico',
583+
self.create_launcher('Jupyter Notebook.exe', 'jupyter.ico',
582584
command='${WINPYDIR}\Scripts\%s' %
583585
'jupyter-notebook.exe',
584-
workdir=r'${WINPYDIR}\..\notebooks')
586+
workdir=r'$EXEDIR\notebooks')
585587

586588
# R console launchers
587589
r_exe = self.R_PATH + r"\i386\R.exe"
588590
if osp.isfile(self.winpydir + r_exe):
589591
self.create_launcher('R Console32.exe', 'r.ico',
590-
command='${WINPYDIR}\..' + r_exe,
591-
workdir=r'${WINPYDIR}\..\notebooks')
592+
command='$EXEDIR' + r_exe,
593+
workdir=r'$EXEDIR\notebooks')
592594
r_exe = self.R_PATH + r"\x64\R.exe"
593595
if osp.isfile(self.winpydir + r_exe):
594596
self.create_launcher('R Console64.exe', 'r.ico',
595-
command='${WINPYDIR}\..' + r_exe,
596-
workdir=r'${WINPYDIR}\..\notebooks')
597+
command='$EXEDIR' + r_exe,
598+
workdir=r'$EXEDIR\notebooks')
597599

598600
# Julia console launcher
599601
julia_exe = self.JULIA_PATH + r"\julia.exe"
600602
if osp.isfile(self.winpydir + julia_exe):
601603
self.create_launcher('Julia Console.exe', 'julia.ico',
602-
command='${WINPYDIR}\..'+ julia_exe,
603-
workdir=r'${WINPYDIR}\..\notebooks')
604+
command='$EXEDIR'+ julia_exe,
605+
workdir=r'$EXEDIR\notebooks')
606+
607+
# ******* Student Experiment (start)
608+
609+
#self.create_launcher('IDLEX (students).exe', 'python.ico',
610+
# command='$SYSDIR\cmd.exe',
611+
# args= r'/k IDLEX_for_student.bat %*',
612+
# workdir='$EXEDIR\scripts')
613+
self.create_launcher('IDLEX (student).exe', 'python.ico',
614+
command='wscript.exe',
615+
args= r'Noshell.vbs IDLEX_for_student.bat',
616+
workdir='$EXEDIR\scripts',
617+
launcher='launcher_basic.nsi')
618+
619+
self.create_launcher('Spyder (student).exe', 'spyder.ico',
620+
command='wscript.exe',
621+
args=r'Noshell.vbs spyder_for_student.bat',
622+
workdir='$EXEDIR\Scripts',
623+
launcher='launcher_basic.nsi')
624+
625+
self.create_launcher('Spyder reset (student).exe', 'spyder_reset.ico',
626+
command='wscript.exe',
627+
args=r'Noshell.vbs spyder_for_student.bat',
628+
workdir='$EXEDIR\Scripts',
629+
launcher='launcher_basic.nsi')
630+
631+
self.create_launcher('IPython Qt Console (student).exe', 'ipython.ico',
632+
command='wscript.exe',
633+
args=r'Noshell.vbs qtconsole_for_student.bat',
634+
workdir='$EXEDIR\Scripts',
635+
launcher='launcher_basic.nsi')
636+
637+
# this one needs a shell to kill fantom processes
638+
self.create_launcher('Jupyter Notebook (student).exe', 'jupyter.ico',
639+
command='$SYSDIR\cmd.exe',
640+
args=r'/k ipython_notebook_for_student.bat',
641+
workdir='$EXEDIR\Scripts',
642+
launcher='launcher_basic.nsi')
604643

605644
self._print_done()
606645

@@ -639,6 +678,51 @@ def _create_batch_scripts_initial(self):
639678
rem keep nbextensions in Winpython directory, rather then %APPDATA% default
640679
set JUPYTER_DATA_DIR=%WINPYDIR%\..\settings
641680
""")
681+
682+
self.create_batch_script('env_for_student.bat', r"""
683+
@echo off
684+
rem to have WinPython working in a local account
685+
if "%WINPYDIR%"=="" call %~dp0env.bat
686+
687+
rem ******* Classic WinPython *******
688+
rem set JUPYTER_DATA_DIR=%WINPYDIR%\..\settings
689+
rem set HOME=%WINPYDIR%\..\settings
690+
691+
rem ******* Student WinPython *******
692+
set HOME=%HOMEDRIVE%%HOMEPATH%\Documents\WinPython%WINPYVER%
693+
set JUPYTER_DATA_DIR=%HOME%
694+
695+
if not exist "%HOME%\Notebooks" mkdir "%HOME%\Notebooks"
696+
697+
if exist "%HOME%\Notebooks\docs" goto ok_docs
698+
mkdir "%HOME%\Notebooks\docs"
699+
xcopy /i "%WINPYDIR%\..\Notebooks\docs\*.ipynb" "%HOME%\Notebooks\docs"
700+
:ok_docs
701+
702+
703+
if not exist "%HOME%\.spyder-py%WINPYVER:~0,1%" mkdir "%HOME%\.spyder-py%WINPYVER:~0,1%"
704+
if not exist "%HOME%\.spyder-py%WINPYVER:~0,1%\workingdir" echo %HOME%\Notebooks>"%HOME%\.spyder-py%WINPYVER:~0,1%\workingdir"
705+
706+
rem ******* make cython use mingwpy part *******
707+
if not exist "%HOME%\pydistutils.cfg" xcopy "%WINPYDIR%\..\settings\pydistutils.cfg" "%HOME%"
708+
""")
709+
710+
self.create_batch_script('Noshell.vbs',
711+
r"""
712+
'from http://superuser.com/questions/140047/how-to-run-a-batch-file-without-launching-a-command-window/390129
713+
If WScript.Arguments.Count >= 1 Then
714+
ReDim arr(WScript.Arguments.Count-1)
715+
For i = 0 To WScript.Arguments.Count-1
716+
Arg = WScript.Arguments(i)
717+
If InStr(Arg, " ") > 0 Then Arg = chr(34) & Arg & chr(34)
718+
arr(i) = Arg
719+
Next
720+
721+
RunCmd = Join(arr)
722+
CreateObject("Wscript.Shell").Run RunCmd, 0 , True
723+
End If
724+
""")
725+
642726

643727
def _create_batch_scripts(self):
644728
"""Create batch scripts"""
@@ -708,6 +792,7 @@ def _create_batch_scripts(self):
708792
call %~dp0env.bat
709793
cmd.exe /k""")
710794
self.create_python_batch('python.bat', '')
795+
711796
self.create_python_batch('spyder.bat', 'spyderlib.start_app',
712797
workdir='Scripts',
713798
command = '%WINPYDIR%\python.exe -m')
@@ -742,6 +827,41 @@ def _create_batch_scripts(self):
742827
pause
743828
""")
744829

830+
# ******* Student Experiment (start)
831+
self.create_batch_script('idlex_for_student.bat',r"""@echo off
832+
call "%~dp0env_for_student.bat"
833+
cd/D "%HOME%\Notebooks"
834+
"%WINPYDIR%\python.exe" "%WINPYDIR%\scripts\idlex.pyw" %*
835+
""")
836+
837+
self.create_batch_script('spyder_for_student.bat',r"""@echo off
838+
call "%~dp0env_for_student.bat"
839+
cd/D "%HOME%\Notebooks"
840+
"%WINPYDIR%\python.exe" -m spyderlib.start_app %*
841+
""")
842+
self.create_batch_script('spyder_reset_for_student.bat',r"""@echo off
843+
call "%~dp0env_for_student.bat"
844+
cd/D "%HOME%\Notebooks"
845+
%WINPYDIR%\python.exe -m spyderlib.start_app --reset %*
846+
echo %HOME%\Notebooks>"%HOME%\.spyder-py%WINPYVER:~0,1%\workingdir"
847+
rem legacy if ever needed
848+
echo %HOME%\Notebooks>"%HOME%\.spyder2\workingdir"
849+
echo %HOME%\Notebooks>"%HOME%\.spyder\workingdir"
850+
""")
851+
852+
self.create_batch_script('ipython_notebook_for_student.bat',r"""@echo off
853+
call "%~dp0env_for_student.bat"
854+
cd/D "%HOME%\Notebooks"
855+
"%WINPYDIR%\scripts\jupyter-notebook.exe" --notebook-dir="%HOME%\Notebooks" %*
856+
""")
857+
858+
self.create_batch_script('qtconsole_for_student.bat',r"""@echo off
859+
call "%~dp0env_for_student.bat"
860+
cd/D "%HOME%\Notebooks"
861+
"%WINPYDIR%\scripts\jupyter-qtconsole.exe" %*
862+
""")
863+
# ******* Student Experiment (end)
864+
745865
# pre-run mingw batch
746866
print('now pre-running extra mingw')
747867
filepath = osp.join(self.winpydir, 'scripts', 'make_cython_use_mingw.bat')

portable/launcher_basic.nsi

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
3+
WinPython launcher template script
4+
5+
Copyright © 2012 Pierre Raybaut
6+
Licensed under the terms of the MIT License
7+
(see winpython/__init__.py for details)
8+
9+
*/
10+
11+
;================================================================
12+
; These lines are automatically replaced when creating launchers:
13+
; (see winpython/make.py)
14+
!addincludedir ""
15+
16+
!define COMMAND ""
17+
!define PARAMETERS ""
18+
!define WORKDIR ""
19+
!define PREPATH ""
20+
!define POSTPATH ""
21+
!define SETTINGSDIR ""
22+
!define SETTINGSNAME ""
23+
24+
; prefered command (if it is a file)
25+
!define BETTERCOMMAND ""
26+
!define BETTERWORKDIR ""
27+
!define BETTERPARAMETERS ""
28+
29+
Icon ""
30+
OutFile ""
31+
;================================================================
32+
33+
# Standard NSIS plugins
34+
!include "WordFunc.nsh"
35+
!include "FileFunc.nsh"
36+
!include "TextReplace.nsh"
37+
38+
# Custom NSIS plugins
39+
!include "ReplaceInFileWithTextReplace.nsh"
40+
!include "EnumIni.nsh"
41+
42+
SilentInstall silent
43+
AutoCloseWindow true
44+
ShowInstDetails nevershow
45+
RequestExecutionLevel user
46+
47+
Section ""
48+
Call Execute
49+
SectionEnd
50+
51+
Function Execute
52+
; prefered command (if it is a file)
53+
StrCmp "${BETTERCOMMAND}" "" no_better_workdir
54+
StrCpy $R8 "${BETTERCOMMAND}"
55+
IfFileExists $R8 do_better_workdircheck
56+
Goto no_better_workdir
57+
58+
do_better_workdircheck:
59+
StrCpy $R8 "${BETTERWORKDIR}"
60+
IfFileExists $R8 do_better_workdir
61+
Goto no_better_workdir
62+
63+
do_better_workdir:
64+
StrCmp ${BETTERWORKDIR} "" 0 betterworkdir
65+
System::Call "kernel32::GetCurrentDirectory(i ${NSIS_MAX_STRLEN}, t .r0)"
66+
SetOutPath $0
67+
Goto end_workdir
68+
betterworkdir:
69+
SetOutPath "${BETTERWORKDIR}"
70+
Goto end_workdir
71+
72+
no_better_workdir:
73+
;normal workdir
74+
StrCmp ${WORKDIR} "" 0 workdir
75+
System::Call "kernel32::GetCurrentDirectory(i ${NSIS_MAX_STRLEN}, t .r0)"
76+
SetOutPath $0
77+
Goto end_workdir
78+
workdir:
79+
SetOutPath "${WORKDIR}"
80+
end_workdir:
81+
82+
;================================================================
83+
; Settings directory HOME (will affect $PROFILE)
84+
IfFileExists "$EXEDIR\settings\*.*" 0 end_settings
85+
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("HOME", "$EXEDIR\settings").r0'
86+
StrCmp "${SETTINGSDIR}" "" end_settings
87+
CreateDirectory "$EXEDIR\settings\${SETTINGSDIR}"
88+
89+
end_settings:
90+
;================================================================
91+
92+
93+
; WinPython settings
94+
IfFileExists "$EXEDIR\settings\*.*" 0 winpython_settings_profile
95+
StrCpy $R6 "$EXEDIR\settings\winpython.ini"
96+
Goto winpython_settings_continue
97+
winpython_settings_profile:
98+
StrCpy $R6 "$PROFILE\winpython.ini"
99+
winpython_settings_continue:
100+
IfFileExists $R6 winpython_settings_done
101+
ClearErrors
102+
FileOpen $0 $R6 w
103+
IfErrors winpython_settings_done
104+
FileWrite $0 "[debug]$\r$\nstate = disabled"
105+
FileWrite $0 "$\r$\n"
106+
FileWrite $0 "$\r$\n[environment]"
107+
FileWrite $0 "$\r$\n## <?> Uncomment lines to override environment variables"
108+
FileWrite $0 "$\r$\n#PATH = "
109+
FileWrite $0 "$\r$\n#PYTHONPATH = "
110+
FileWrite $0 "$\r$\n#PYTHONSTARTUP = "
111+
FileClose $0
112+
winpython_settings_done:
113+
114+
115+
; Debug state
116+
IfFileExists $R6 0 no_debug
117+
ReadINIStr $R7 $R6 "debug" "state"
118+
StrCmp $R7 "" no_debug
119+
StrCmp $R7 "disabled" no_debug
120+
StrCpy $R7 "enabled"
121+
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("WINPYDEBUG", "True").r0'
122+
no_debug:
123+
124+
125+
;================================================================
126+
; NO PATH Environment variables
127+
ReadEnvStr $R0 "PATH"
128+
129+
;================================================================
130+
131+
132+
; Command line parameters
133+
${GetParameters} $R1
134+
StrCmp "${PARAMETERS}" "" end_param 0
135+
StrCpy $R1 "${PARAMETERS} $R1"
136+
end_param:
137+
138+
; prefered command (if it is a file)
139+
StrCmp "${BETTERCOMMAND}" "" no_better_command
140+
StrCpy $R8 "${BETTERCOMMAND}"
141+
IfFileExists $R8 do_better_command
142+
Goto no_better_command
143+
144+
do_better_command:
145+
Exec '"${BETTERCOMMAND}" $R1'
146+
Goto end_of_command
147+
148+
no_better_command:
149+
Exec '"${COMMAND}" $R1'
150+
151+
end_of_command:
152+
FunctionEnd

0 commit comments

Comments
 (0)