macOS: generate .pyenvrc during setup (#29698)

* Create .pyenvrc if it does not exist

* Replace source zshrc with pyenvrc

* Remove unnecessary variables if pyenv wasn't installed

* Add check fo PYENV_SHELL

* source instead of eval

* printf instead of echo

* leave previous pyenvrc path to source

* Add newline

* Change shebang

* Dont source the file after setup

* eval virtualenv-init too

* modify comment

* Just unset broken function on macos
old-commit-hash: 39d2517d3d
beeps
Kacper Rączy 2 years ago committed by GitHub
parent de996d76bb
commit 41fd8b51e7
  1. 20
      tools/install_python_dependencies.sh
  2. 2
      tools/mac_setup.sh
  3. 2
      tools/ubuntu_setup.sh

@ -13,20 +13,30 @@ fi
if ! command -v "pyenv" > /dev/null 2>&1; then
echo "pyenv install ..."
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
PYENV_PATH_SETUP="export PATH=\$HOME/.pyenv/bin:\$HOME/.pyenv/shims:\$PATH"
fi
if [ -z "$PYENV_SHELL" ] || [ -n "$PYENV_PATH_SETUP" ]; then
echo "pyenvrc setup ..."
cat <<EOF > "${HOME}/.pyenvrc"
if [ -z "\$PYENV_ROOT" ]; then
export PATH=\$HOME/.pyenv/bin:\$HOME/.pyenv/shims:\$PATH
$PYENV_PATH_SETUP
export PYENV_ROOT="\$HOME/.pyenv"
eval "\$(pyenv init --path)"
eval "\$(pyenv init -)"
eval "\$(pyenv virtualenv-init -)"
fi
EOF
echo -e "\nsource ~/.pyenvrc" >> $RC_FILE
# activate pyenv now
source $RC_FILE
SOURCE_PYENVRC="source ~/.pyenvrc"
if ! grep "^$SOURCE_PYENVRC$" $RC_FILE > /dev/null; then
printf "\n$SOURCE_PYENVRC\n" >> $RC_FILE
fi
eval "$SOURCE_PYENVRC"
# $(pyenv init -) produces a function which is broken on bash 3.2 which ships on macOS
if [ $(uname) == "Darwin" ]; then
unset -f pyenv
fi
fi
export MAKEFLAGS="-j$(nproc)"

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

Loading…
Cancel
Save