Skip to content

Commit 8b152a7

Browse files
author
stonebig
committed
a 'student' usage of WinPython
1 parent f7c83fd commit 8b152a7

File tree

1 file changed

+135
-15
lines changed

1 file changed

+135
-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')

0 commit comments

Comments
 (0)