Last active
July 3, 2024 20:27
-
-
Save kchawla-pi/b7d40fcc8b8ed1266e9b427ffffa2526 to your computer and use it in GitHub Desktop.
POSIX shell function to deny the install commands if you are in the base environment.
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
# Source: https://github.com/conda/conda/issues/7791#issuecomment-945676641 | |
# Add this in .bashrc or .zshrc to deny the install commands if you are in the base environment. | |
# From https://github.com/conda/conda/issues/7791#issuecomment-946537246 | |
# One case where this does not prevent from installing to base: | |
# If one uses pip in a conda environment, that has no pip installed, it will still install all the packages into the base environment. | |
# This may happen when an empty environment is created and then one simply runs pip install -r requirements.txt. | |
# TODO: Do a `which pip` & compare it to conda base env path as an additional check for the pip() function. | |
function pip(){ | |
if [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then | |
echo "Not allowed in base" | |
else | |
command pip "$@" | |
fi | |
} | |
function extended_conda(){ | |
if [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then | |
echo "Not allowed in base" | |
else | |
conda "$@" | |
fi | |
} | |
alias conda=extended_conda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment