Created
August 4, 2024 11:14
-
-
Save Mausy5043/8e7877f9a7a8da948e31d5e0b7f260f8 to your computer and use it in GitHub Desktop.
Bash script to create conda environment based on the available `environment.yml` file or create a default environment in cast no YAML file provided.
This file contains hidden or 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
#!/bin/bash | |
# MIT License applies. | |
# Copyright 2024 Maurice (mausy5043) Hendrix | |
# environment name stored in YAML file takes precedence | |
if [ -f "environment.yml" ]; then | |
# YAML exists, so we use that | |
echo "Found : environment.yml" | |
env_name=$(grep "name:" environment.yml |cut -d ":" -f 2 |xargs) | |
else | |
if [ -z "${1}" ]; then | |
echo "ERROR: No environment name set!" | |
exit 1 | |
else | |
env_name="${1}" | |
# YAML doesn't exist so we create it now | |
{ | |
echo "name: ${env_name}" | |
echo "channels:" | |
echo " - conda-forge" | |
echo " - defaults" | |
echo "dependencies:" | |
echo " - python=3.11" | |
} > ./environment.yml | |
echo "Created : environment.yml" | |
fi | |
fi | |
echo "Creating: ${env_name}" | |
conda env create --yes --file "environment.yml" | |
# store the name for the `cg` command | |
echo "${env_name}" > ./.env | |
echo "Ready : ${env_name} created." | |
echo "Activate it before use. | |
# Usage: | |
# 1. git clone http://repo | |
# 2. cd repo | |
# 3. mkenv repo | |
# wait for new terminal view to open | |
# visually check if conda activated the environment | |
# 4. pycheck | |
# Tip: save an environment using: | |
# conda env export --from-history>rescue.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment