From 41fd8b51e77e8c8ff76ae6b19a08f77962900502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Tue, 29 Aug 2023 16:01:04 -0700 Subject: [PATCH] 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: 39d2517d3d9de8175aa2c95491b043580e28500f --- tools/install_python_dependencies.sh | 20 +++++++++++++++----- tools/mac_setup.sh | 2 +- tools/ubuntu_setup.sh | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/install_python_dependencies.sh b/tools/install_python_dependencies.sh index 79c36d57d..07bb8ac9a 100755 --- a/tools/install_python_dependencies.sh +++ b/tools/install_python_dependencies.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 < "${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)" diff --git a/tools/mac_setup.sh b/tools/mac_setup.sh index 3892efd6b..c767131f5 100755 --- a/tools/mac_setup.sh +++ b/tools/mac_setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/tools/ubuntu_setup.sh b/tools/ubuntu_setup.sh index 6b9cf7eff..1bdeb50e0 100755 --- a/tools/ubuntu_setup.sh +++ b/tools/ubuntu_setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e