-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1566 from willend/main
Makes "Pylab" launcher button available and functional across platforms.
- Loading branch information
Showing
3 changed files
with
121 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@set BINDIR=%~dp0 | ||
@CALL %BINDIR%\\mccodeenv.bat | ||
@ECHO OFF | ||
@ECHO @FLAVOR@ Jupyter lab shell | ||
@set INSTRUMENT=%1 | ||
@REM Check if we were called with an input file name? | ||
@IF "%INSTRUMENT%"=="" (call :JupyLaunch "INSTRUMENT" ".") | ||
|
||
@FOR /F "delims=" %%i IN ("%INSTRUMENT%") DO ( | ||
SET BASE=%%~ni | ||
SET EXT=%%~xi | ||
) | ||
|
||
@IF "%EXT%"==".instr" ( | ||
@FLAVOR@-pygen %INSTRUMENT% | ||
SET INSTRUMENT="%BASE%_generated.py" | ||
goto :JupyText | ||
) ELSE IF "%EXT%"==".py" ( | ||
goto :JupyLaunch | ||
) ELSE IF "%EXT%"==".ipynb" ( | ||
goto :JupyText | ||
) ELSE (JupyLaunch | ||
call :JupyLaunch "INSTRUMENT" "." | ||
) | ||
|
||
@IF /I "%INSTRUMENT%"=="%%~G" | ||
@IF "%INSTRUMENT%"=="" (call :JupyLaunch "INSTRUMENT" ".") | ||
@ELSE () | ||
|
||
:JupyText | ||
@jupytext --to ipynb %INSTRUMENT% | ||
@SET INSTRUMENT="%BASE%_generated.ipynb" | ||
|
||
:JupyLaunch | ||
@jupyter lab %INSTRUMENT% | ||
@goto :EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,79 @@ | ||
@set BINDIR=%~dp0 | ||
@CALL %BINDIR%\\mccodeenv.bat | ||
@ECHO OFF | ||
@ECHO @FLAVOR@ Jupyter lab shell | ||
@set INSTRUMENT=%1 | ||
@REM Check if we were called with an input file name? | ||
@IF "%INSTRUMENT%"=="" (call :JupyLaunch "INSTRUMENT" ".") | ||
|
||
@FOR /F "delims=" %%i IN ("%INSTRUMENT%") DO ( | ||
SET BASE=%%~ni | ||
SET EXT=%%~xi | ||
) | ||
|
||
@IF "%EXT%"==".instr" ( | ||
@FLAVOR@-pygen %INSTRUMENT% | ||
SET INSTRUMENT="%BASE%_generated.py" | ||
goto :JupyText | ||
) ELSE IF "%EXT%"==".py" ( | ||
goto :JupyLaunch | ||
) ELSE IF "%EXT%"==".ipynb" ( | ||
goto :JupyText | ||
) ELSE (JupyLaunch | ||
call :JupyLaunch "INSTRUMENT" "." | ||
) | ||
|
||
@IF /I "%INSTRUMENT%"=="%%~G" | ||
@IF "%INSTRUMENT%"=="" (call :JupyLaunch "INSTRUMENT" ".") | ||
@ELSE () | ||
|
||
@:JupyText | ||
@jupytext --to ipynb %INSTRUMENT% | ||
@SET INSTRUMENT="%BASE%_generated.ipynb" | ||
|
||
@:JupyLaunch | ||
@jupyter lab %INSTRUMENT% | ||
@goto :EOF | ||
#!/usr/bin/env bash | ||
|
||
if [[ 1 == 1 ]]; then | ||
# Legacy McCode PATH setup | ||
TOPENV="$0" | ||
|
||
# Check if we are being called with a non-full path | ||
if [[ $TOPENV != "/"* ]]; then | ||
TOPENV="$PWD/$TOPENV" | ||
fi | ||
|
||
# Iterate down a (possible) chain of symlinks (macOS does not have readlink -f) | ||
while [ -L "$TOPENV" ]; | ||
do | ||
TOPENV=`readlink "$TOPENV"` | ||
done | ||
TOPENV=`dirname $TOPENV` | ||
TOPENV=`dirname $TOPENV` | ||
TOPENV=`dirname $TOPENV` | ||
|
||
else | ||
TOPENV="\$( cd -P \"\$( dirname \"\${BASH_SOURCE[0]}\" )\" && pwd )" | ||
fi | ||
|
||
|
||
|
||
ARCH=`arch` | ||
UNAME=`uname -s` | ||
|
||
# On macOS, shorten TMPDIR | ||
if [[ ${UNAME} = Darwin* ]]; then | ||
export TMPDIR=/tmp | ||
OSXVER=`sw_vers -productVersion|cut -f 1 -d.` | ||
fi | ||
|
||
export PATH=$TOPENV/miniconda3/bin:$PATH | ||
|
||
export @FLAVOR_UPPER@=$TOPENV/@DEST_DATADIR_COMPS@ | ||
|
||
export PATH=$TOPENV/@DEST_BINDIR@:$PATH | ||
# Check if we are running with miniconda-provided python libs and set PYTHONPATH accordingly | ||
if [ -d "$@FLAVOR_UPPER@/miniconda3" ]; then | ||
#Activation hook for conda | ||
_conda_bindir="$@FLAVOR_UPPER@/miniconda3/bin" | ||
function conda() { | ||
unset conda | ||
eval "$(${_conda_bindir}/conda shell.bash hook 2> /dev/null)" | ||
conda "$@" | ||
} | ||
conda activate $@FLAVOR_UPPER@/miniconda3 | ||
export PS1='(@FLAVOR@-@MCCODE_VERSION@/miniconda3) \W \$ ' | ||
else | ||
export PS1='@FLAVOR@-@MCCODE_VERSION@ env \W \$ ' | ||
fi | ||
|
||
|
||
if [ -d "$@FLAVOR_UPPER@/share/NCrystal/python/" ]; then | ||
export PYTHONPATH=$@FLAVOR_UPPER@/share/NCrystal/python/:$PYTHONPATH | ||
fi | ||
|
||
# Finally, launch jupyter, potentially via $1 as input | ||
export INSTRUMENT=$1 | ||
# Check if we got an input file or not | ||
if [ -z "${INSTRUMENT}" ]; then | ||
# Still empty? Look for most recent local .py or .ipynb file | ||
export INSTRUMENT=`ls -rt *.py *.ipynb | tail -1` | ||
if [ -z "${INSTRUMENT}" ]; then | ||
# Still empty? Just open . | ||
export INSTRUMENT="." | ||
fi | ||
fi | ||
|
||
# Got an input, check if it has suffix .instr | ||
if [[ "${INSTRUMENT}" == *".instr" ]]; then | ||
@FLAVOR@-jupylab ${INSTRUMENT} | ||
else | ||
jupyter lab ${INSTRUMENT} | ||
fi | ||
|