merenlab / anvio.org

The anvi'o community web page
4 stars 11 forks source link

bash + zsh path setting code for anvio-dev installation #23

Open bluegenes opened 1 year ago

bluegenes commented 1 year ago

cc @ahenoch

The following detects shell to enable the path setting + update to work in zsh. It also uses the current working directory, fixing issues for any folks who don't place the anvio directory in ~/github

mkdir -p "${CONDA_PREFIX}/etc/conda/activate.d/"
SHELL_NAME=$(basename "$SHELL")

# Define color/formatting codes for different shells
if [ "$SHELL_NAME" = "zsh" ]; then
  # Zsh shell
  blue_text=$(tput setaf 4)
  red_text=$(tput setaf 1)
  reset_text=$(tput sgr0)
else
  # Bash shell (default to original formatting)
  blue_text="\033[1;34m"
  red_text="\033[0;31m"
  reset_text="\033[0m"
fi

# Create the activation script
cat <<EOF >"${CONDA_PREFIX}/etc/conda/activate.d/anvio.sh"
# creating an activation script for the conda environment for anvi'o
# development branch so (1) Python knows where to find anvi'o libraries,
# (2) the shell knows where to find anvi'o programs, and (3) every time
# the environment is activated, it synchronizes with the latest code from
# the active GitHub repository:
export PYTHONPATH=\$PYTHONPATH:${PWD}
export PATH=\$PATH:${PWD}/bin:${PWD}/sandbox
echo -e "${blue_text}Updating from anvi'o GitHub ${red_text}(press CTRL+C to cancel)${reset_text} ..."
cd ${PWD} && git pull && cd -
EOF

Tested for zsh on M2 mac, please do test on bash. This might be worth obscuring as a script.

A simpler solution might be to enable pip install -e . :)

(edited. had a pythonpath error initially :)