Skip to content

Commit

Permalink
Cherry-pick #11212 to 7.0: Use PYTHON_EXE env var as the python inter…
Browse files Browse the repository at this point in the history
…preter (#11569)

* Use PYTHON_EXE env var as the python interpreter (#11212)

Setting the PYTHON_EXE environment variable causes new Python virtual environments
to be created using the specified interpreter. Both `make` and `mage` honor the
variable.

For example, `PYTHON_EXE=python2.7 make python-env`.

(cherry picked from commit 9fb274a)
  • Loading branch information
andrewkroh committed Apr 4, 2019
1 parent 517d39f commit c38bafc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-developer.next.asciidoc
Expand Up @@ -23,3 +23,6 @@ The list below covers the major changes between 7.0.0-rc1 and master only.
==== Bugfixes

==== Added

- Added support for using PYTHON_EXE to control what Python interpreter is used
by `make` and `mage`. Example: `export PYTHON_EXE=python2.7`. {pull}11212[11212]
11 changes: 9 additions & 2 deletions dev-tools/mage/pytest.go
Expand Up @@ -167,10 +167,17 @@ func PythonVirtualenv() (string, error) {
return pythonVirtualenvDir, nil
}

// If set use PYTHON_EXE env var as the python interpreter.
var args []string
if pythonExe := os.Getenv("PYTHON_EXE"); pythonExe != "" {
args = append(args, "-p", pythonExe)
}
args = append(args, ve)

// Execute virtualenv.
if _, err := os.Stat(ve); err != nil {
// Run virtualenv if the dir does not exist.
if err := sh.Run("virtualenv", ve); err != nil {
if err := sh.Run("virtualenv", args...); err != nil {
return "", err
}
}
Expand All @@ -181,7 +188,7 @@ func PythonVirtualenv() (string, error) {
}

pip := virtualenvPath(ve, "pip")
args := []string{"install"}
args = []string{"install"}
if !mg.Verbose() {
args = append(args, "--quiet")
}
Expand Down
2 changes: 1 addition & 1 deletion libbeat/scripts/Makefile
Expand Up @@ -250,7 +250,7 @@ load-tests: ## @testing Runs load tests
# Sets up the virtual python environment
.PHONY: python-env
python-env: ${ES_BEATS}/libbeat/tests/system/requirements.txt
@test -d ${PYTHON_ENV} || virtualenv ${VIRTUALENV_PARAMS} ${PYTHON_ENV}
@test -d ${PYTHON_ENV} || virtualenv $(if ${PYTHON_EXE},-p ${PYTHON_EXE}) ${VIRTUALENV_PARAMS} ${PYTHON_ENV}
@. ${PYTHON_ENV}/bin/activate && pip install ${PIP_INSTALL_PARAMS} -q --upgrade pip ; \
if [ -a ./tests/system/requirements.txt ] && [ ! ${ES_BEATS}/libbeat/tests/system/requirements.txt -ef ./tests/system/requirements.txt ] ; then \
. ${PYTHON_ENV}/bin/activate && pip install ${PIP_INSTALL_PARAMS} -qUr ${ES_BEATS}/libbeat/tests/system/requirements.txt -Ur ./tests/system/requirements.txt ; \
Expand Down

0 comments on commit c38bafc

Please sign in to comment.