From 05bb4f9a8dc19ba902c53566845291d3ceff47c2 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Mon, 19 Feb 2024 01:38:02 +0300 Subject: [PATCH] Use Homebrew in Linux if Pyenv is installed with Homebrew or PYTHON_BUILD_USE_HOMEBREW is set --- plugins/python-build/README.md | 9 ++- plugins/python-build/bin/python-build | 13 +++- plugins/python-build/test/build.bats | 104 +++++++++++++++++--------- 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/plugins/python-build/README.md b/plugins/python-build/README.md index f0826fc8..7fd92165 100644 --- a/plugins/python-build/README.md +++ b/plugins/python-build/README.md @@ -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. diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index ae4246f8..044defde 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -118,8 +118,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 diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index f050e4b5..aacef79f 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -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 <