This is a bash code to check if a venv was given and to source it. Instead create a code…
- User
This is a bash code to check if a venv was given and to source it. Instead create a code that sources a venv if that exists, conda activate if CONDA exists and exists only if both do not exist
VENV=config_path venv)
Check if VENV is empty
if [ -z "$VENV" ]; then echo "Failed to load VENV configuration." exit 1 fi
absolute_path=VENV) echo "Using VENV at VENV
- Assistant
Here is the bash code that sources a venv if that exists, conda activate if CONDA exists, and exits if both do not exist:
Check if VENV is set and source it
VENV=config_path venv)
if [ -n "(readlink -f absolute_path" source (conda info --env | grep '^*' | cut -d' ' -f2) echo "Using conda environment: $conda_env" conda activate else echo "No virtual environment found. Please ensure you have a virtual environment set up." exit 1 fi CopiedThis code first checks if the VENV variable is set and not empty. If it is set, it sources the virtual environment. If VENV is not set, it checks if conda is available by using the command -v conda condition. If conda is available, it activates the current conda environment using conda activate. If neither VENV nor conda is available, it prints an error message and exits with a status code of 1.
- User
The question is not if conda command exists but if a CONDA variable was defined just like the VENV was. if VENV is defined use a VENV otherwise use conda
- Assistant
Here is the updated bash code that sources a venv if that exists, and uses conda if the CONDA variable is defined:
Check if VENV is set and source it
VENV=config_path venv)
if [ -n "(readlink -f absolute_path" source CONDA" ]; then # Check if CONDA is set and activate the environment conda_env=conda_env" conda activate else echo "No virtual environment found. Please ensure you have a virtual environment set up." exit 1 fi CopiedThis code first checks if the VENV variable is set and not empty. If it is set, it sources the virtual environment. If VENV is not set, it checks if the CONDA variable is set and not empty. If CONDA is set, it activates the current conda environment using conda activate. If neither VENV nor CONDA is set, it prints an error message and exits with a status code of 1.