Created
January 8, 2024 19:52
-
-
Save jefferys/457cf5f67edd387380de6bbe55ca8cdd to your computer and use it in GitHub Desktop.
Micromamba local self-contained environment setup using Slurm if avaialble
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
#!/usr/bin/env bash | |
#SBATCH --job-name mambaEnv | |
#SBATCH --cpus-per-task 6 | |
#SBATCH --mem 16G | |
#SBATCH --partition allnodes | |
#SBATCH --output ./mambaEnv.%j.out | |
#SBATCH --error ./mambaEnv.%j.err | |
# yaml filename is required argument 1 | |
if [ "$#" -ne 1 ]; then | |
echo "Error: must specify yaml file as the first argument." | |
exit 1 | |
fi | |
yaml="$1" | |
# "yaml" must exist | |
if [ ! -f "$yaml" ]; then | |
echo "Error: File $yaml does not exist." | |
exit 1 | |
fi | |
# Get path to a "micromamba" directory associated with yaml file | |
baseDir=$(dirname "$yaml") | |
baseDir=$(cd "$baseDir" && pwd) | |
if [ ! -d "$baseDir" ]; then | |
echo "Error: could not identify the base diectory for the file $yaml" | |
exit 1 | |
fi | |
# Set prefix | |
export MAMBA_ROOT_PREFIX="${baseDir}/micromamba" | |
# Install mamba if needed | |
if [ ! -d "$MAMBA_ROOT_PREFIX" ]; then | |
mkdir "$MAMBA_ROOT_PREFIX" | |
curl -La https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C "$MAMBA_ROOT_PREFIX" | |
fi | |
# Create environment from yaml | |
# TODO - test to see if environment already exists? How do I get the env name | |
# to check for? Should that be a parameter? Should we default to the yaml file | |
# name, sans "[.][^.]$" terminal extenstion? | |
command=$("$MAMBA_ROOT_PREFIX/bin/micromamba" shell hook -s bash) | |
eval "$command" | |
micromamba create --yes -f "$yaml" | |
# List environments available | |
micromamba env list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment