Skip to content

Commit

Permalink
More robust run_notebook.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshanuikabundi committed Jul 4, 2023
1 parent 457ae4b commit 8c14489
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions source/_ext/run_notebook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ shopt -s failglob

# Make sure we're in the same directory as this script,
# the environment file, and the notebook
cd "${0%/*}"
cd "$(dirname "$0")"

################################ CONFIG ################################

# Choose a prefix for the new environment
# Choosing a prefix in the working directory means that deleting the working
# directory will clean up the environment. Note that it will not clean up the
# micromamba cache, which may be substantial.
PREFIX='./env'
# Choose a name for the new environment
# Note that deleting this will not clean up the micromamba cache, which may be
# substantial.
ENVNAME='__openff_examples__'

# The filename of the Conda environment file to run the notebook in
ENV_FILE='environment.yaml'
Expand Down Expand Up @@ -94,19 +93,20 @@ fi
# script is running)
eval "$(./micromamba shell hook --shell=bash)"

# Create the new environment, or install packages into it from the YAML file if
# it already exists
if [[ -d $PREFIX/conda-meta/ ]]; then
micromamba update --file $ENV_FILE --prefix "$PREFIX"
# Create the new environment, or install and update packages from the YAML file
# if it already exists
if micromamba env list | grep "^\s*${ENVNAME}\s*"; then
micromamba install --file "$ENV_FILE" --name "$ENVNAME" --yes
micromamba update --file "$ENV_FILE" --name "$ENVNAME" --yes
else
micromamba create --file $ENV_FILE --prefix "$PREFIX"
micromamba create --file "$ENV_FILE" --name "$ENVNAME" --yes
fi

# Unset environment variables that might confuse Python
unset PYTHONPATH
unset PYTHONHOME

# Activate the new environment
micromamba activate "$PREFIX"
micromamba activate "$ENVNAME"
# Open the notebook in the new environment
jupyter lab $NOTEBOOK

0 comments on commit 8c14489

Please sign in to comment.