mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
Merge pull request #2906 from native-api/use_linuxbrew_if_preferred
Use Homebrew in Linux if Pyenv is installled with Homebrew
This commit is contained in:
commit
5503efffcf
3 changed files with 90 additions and 41 deletions
|
@ -120,9 +120,11 @@ The exceptions -- non-default options that are set by default -- are listed belo
|
|||
|
||||
##### Homebrew
|
||||
|
||||
In MacOS, Homebrew is used to find dependency packages if `brew` is found on `PATH`.
|
||||
Homebrew is used to find dependency packages if `brew` is found on `PATH`:
|
||||
* In MacOS, or
|
||||
* If the running Pyenv itself is installed with Homebrew
|
||||
|
||||
Set `PYTHON_BUILD_SKIP_HOMEBREW` to avoid using it.
|
||||
Set `PYTHON_BUILD_USE_HOMEBREW` or `PYTHON_BUILD_SKIP_HOMEBREW` to override this default.
|
||||
|
||||
When Homebrew is used, its `include` and `lib` paths are added to compiler search path (the latter is also set as `rpath`),
|
||||
and also Python dependencies that are typically keg-only are searched for in the Homebrew installation and added individually.
|
||||
|
@ -155,7 +157,8 @@ You can set certain environment variables to control the build process.
|
|||
* `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from
|
||||
their original source URLs instead of using a mirror.
|
||||
* `PYTHON_BUILD_HTTP_CLIENT`, explicitly specify the HTTP client type to use. `aria2`, `curl` and `wget` are the supported values and by default, are searched in that order.
|
||||
* `PYTHON_BUILD_SKIP_HOMEBREW`, if set, will not search for libraries installed by Homebrew in macOS.
|
||||
* `PYTHON_BUILD_SKIP_HOMEBREW`, if set, will not search for libraries installed by Homebrew when it would normally will.
|
||||
* `PYTHON_BUILD_USE_HOMEBREW`, if set, will search for libraries installed by Homebrew when it would normally not.
|
||||
* `PYTHON_BUILD_HOMEBREW_OPENSSL_FORMULA`, override the Homebrew OpenSSL formula to use.
|
||||
* `PYTHON_BUILD_ROOT` overrides the default location from where build definitions
|
||||
in `share/python-build/` are looked up.
|
||||
|
|
|
@ -19,7 +19,10 @@ PYTHON_BUILD_VERSION="20180424"
|
|||
OLDIFS="$IFS"
|
||||
|
||||
set -E
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
[ -n "$PYENV_DEBUG" ] && {
|
||||
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
||||
set -x
|
||||
}
|
||||
|
||||
exec 3<&2 # preserve original stderr at fd 3
|
||||
|
||||
|
@ -118,8 +121,17 @@ is_mac() {
|
|||
}
|
||||
|
||||
can_use_homebrew() {
|
||||
[ -z "$PYTHON_BUILD_SKIP_HOMEBREW" ] || return 1
|
||||
is_mac || return 1
|
||||
[[ -n "$PYTHON_BUILD_USE_HOMEBREW" && -n "$PYTHON_BUILD_SKIP_HOMEBREW" ]] && {
|
||||
echo "error: mutually exclusive environment variables PYTHON_BUILD_USE_HOMEBREW and PYTHON_BUILD_SKIP_HOMEBREW are set" >&3
|
||||
exit 1
|
||||
}
|
||||
[[ -n "$PYTHON_BUILD_USE_HOMEBREW" ]] && return 0
|
||||
[[ -n "$PYTHON_BUILD_SKIP_HOMEBREW" ]] && return 1
|
||||
is_mac && return 0
|
||||
# In Linux, if Pyenv itself is installed with Homebrew,
|
||||
# we assume the user wants to take dependencies from there as well by default
|
||||
command -v brew &>/dev/null && [[ $(abs_dirname "${BASH_SOURCE}") == "$(abs_dirname "$(brew --prefix 2>/dev/null ||true)")"/* ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
# 9.1 -> 901
|
||||
|
|
|
@ -201,34 +201,6 @@ make install
|
|||
OUT
|
||||
}
|
||||
|
||||
@test "yaml is not linked from Homebrew in non-MacOS" {
|
||||
cached_tarball "yaml-0.1.6"
|
||||
cached_tarball "Python-3.6.2"
|
||||
|
||||
for i in {1..10}; do stub uname '-s : echo Linux'; done
|
||||
stub brew true; brew
|
||||
stub_make_install
|
||||
stub_make_install
|
||||
|
||||
install_fixture definitions/needs-yaml
|
||||
assert_success
|
||||
|
||||
unstub uname
|
||||
unstub brew
|
||||
unstub make
|
||||
|
||||
assert_build_log <<OUT
|
||||
yaml-0.1.6: CPPFLAGS="-I${TMP}/install/include" LDFLAGS="-L${TMP}/install/lib -Wl,-rpath,${TMP}/install/lib" PKG_CONFIG_PATH=""
|
||||
yaml-0.1.6: --prefix=${TMP}/install
|
||||
make -j 2
|
||||
make install
|
||||
Python-3.6.2: CPPFLAGS="-I${TMP}/install/include" LDFLAGS="-L${TMP}/install/lib -Wl,-rpath,${TMP}/install/lib" PKG_CONFIG_PATH=""
|
||||
Python-3.6.2: --prefix=$INSTALL_ROOT --enable-shared --libdir=$INSTALL_ROOT/lib
|
||||
make -j 2
|
||||
make install
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "readline is linked from Homebrew" {
|
||||
cached_tarball "Python-3.6.2"
|
||||
|
||||
|
@ -358,12 +330,14 @@ OUT
|
|||
done
|
||||
}
|
||||
|
||||
@test "no library searches performed during normal operation touch homebrew in non-MacOS" {
|
||||
@test "homebrew is not touched if PYTHON_BUILD_SKIP_HOMEBREW is set" {
|
||||
cached_tarball "Python-3.6.2"
|
||||
|
||||
for i in {1..9}; do stub uname '-s : echo Linux'; done
|
||||
for i in {1..4}; do stub uname '-s : echo Darwin'; done
|
||||
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
|
||||
stub brew true; brew
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_SKIP_HOMEBREW=1
|
||||
|
||||
run_inline_definition <<DEF
|
||||
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
|
||||
|
@ -382,14 +356,74 @@ make install
|
|||
OUT
|
||||
}
|
||||
|
||||
@test "no library searches performed during normal operation touch homebrew if envvar is set" {
|
||||
@test "homebrew is used in Linux if PYTHON_BUILD_USE_HOMEBREW is set" {
|
||||
cached_tarball "Python-3.6.2"
|
||||
|
||||
for i in {1..4}; do stub uname '-s : echo Darwin'; done
|
||||
for i in {1..2}; do stub sw_vers '-productVersion : echo 1010'; done
|
||||
stub brew true; brew
|
||||
BREW_PREFIX="$TMP/homebrew-prefix"
|
||||
mkdir -p "$BREW_PREFIX"
|
||||
|
||||
for i in {1..4}; do stub uname '-s : echo Linux'; done
|
||||
stub brew "--prefix : echo '$BREW_PREFIX'"
|
||||
for i in {1..4}; do stub brew false; done
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_USE_HOMEBREW=1
|
||||
|
||||
run_inline_definition <<DEF
|
||||
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
|
||||
DEF
|
||||
assert_success
|
||||
|
||||
unstub uname
|
||||
unstub brew
|
||||
unstub make
|
||||
|
||||
assert_build_log <<OUT
|
||||
Python-3.6.2: CPPFLAGS="-I${TMP}/install/include -I$BREW_PREFIX/include" LDFLAGS="-L${TMP}/install/lib -Wl,-rpath,${TMP}/install/lib -L$BREW_PREFIX/lib -Wl,-rpath,$BREW_PREFIX/lib" PKG_CONFIG_PATH=""
|
||||
Python-3.6.2: --prefix=$INSTALL_ROOT --enable-shared --libdir=$INSTALL_ROOT/lib
|
||||
make -j 2
|
||||
make install
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "homebrew is used in Linux if Pyenv is installed with Homebrew" {
|
||||
cached_tarball "Python-3.6.2"
|
||||
|
||||
BREW_PREFIX="$(type -p python-build)"
|
||||
BREW_PREFIX="${BREW_PREFIX%/*}"
|
||||
BREW_PREFIX="${BREW_PREFIX%/*}"
|
||||
|
||||
for i in {1..4}; do stub uname '-s : echo Linux'; done
|
||||
stub brew "--prefix : echo '$BREW_PREFIX'"
|
||||
for i in {1..4}; do stub brew false; done
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_USE_HOMEBREW=1
|
||||
|
||||
run_inline_definition <<DEF
|
||||
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
|
||||
DEF
|
||||
assert_success
|
||||
|
||||
unstub uname
|
||||
unstub brew
|
||||
unstub make
|
||||
|
||||
assert_build_log <<OUT
|
||||
Python-3.6.2: CPPFLAGS="-I${TMP}/install/include -I$BREW_PREFIX/include" LDFLAGS="-L${TMP}/install/lib -Wl,-rpath,${TMP}/install/lib -L$BREW_PREFIX/lib -Wl,-rpath,$BREW_PREFIX/lib" PKG_CONFIG_PATH=""
|
||||
Python-3.6.2: --prefix=$INSTALL_ROOT --enable-shared --libdir=$INSTALL_ROOT/lib
|
||||
make -j 2
|
||||
make install
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "homebrew is not used in Linux if Pyenv is not installed with Homebrew" {
|
||||
cached_tarball "Python-3.6.2"
|
||||
|
||||
BREW_PREFIX="$TMP/homebrew-prefix"
|
||||
mkdir -p "$BREW_PREFIX"
|
||||
|
||||
for i in {1..9}; do stub uname '-s : echo Linux'; done
|
||||
for i in {1..5}; do stub brew "--prefix : echo '$BREW_PREFIX'"; done
|
||||
stub_make_install
|
||||
export PYTHON_BUILD_SKIP_HOMEBREW=1
|
||||
|
||||
run_inline_definition <<DEF
|
||||
install_package "Python-3.6.2" "http://python.org/ftp/python/3.6.2/Python-3.6.2.tar.gz"
|
||||
|
|
Loading…
Reference in a new issue