Skip to content

Commit ee5363b

Browse files
committed
Use PYTHON_EXE env var as the python interpreter (elastic#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)
1 parent f0128b6 commit ee5363b

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG-developer.next.asciidoc

+8
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ https://github.com/elastic/beats/compare/v6.7.0..6.7[Check the HEAD diff]
2222

2323
==== Added
2424

25+
- Metricset generator generates beta modules by default now. {pull}10657[10657]
26+
- The `beat.Event` accessor methods now support `@metadata` keys. {pull}10761[10761]
27+
- Assertion for documented fields in tests fails if any of the fields in the tested event is documented as an alias. {pull}10921[10921]
28+
- Support for Logger in the Metricset base instance. {pull}11106[11106]
29+
- Introduce processing.Support to instance.Setting. This allows Beats to fully modify the event processing. {pull}10801[10801]
30+
- Filebeat modules can now use ingest pipelines in YAML format. {pull}11209[11209]
31+
- Added support for using PYTHON_EXE to control what Python interpreter is used
32+
by `make` and `mage`. Example: `export PYTHON_EXE=python2.7`. {pull}11212[11212]

dev-tools/mage/pytest.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,17 @@ func PythonVirtualenv() (string, error) {
162162
return pythonVirtualenvDir, nil
163163
}
164164

165+
// If set use PYTHON_EXE env var as the python interpreter.
166+
var args []string
167+
if pythonExe := os.Getenv("PYTHON_EXE"); pythonExe != "" {
168+
args = append(args, "-p", pythonExe)
169+
}
170+
args = append(args, ve)
171+
165172
// Execute virtualenv.
166173
if _, err := os.Stat(ve); err != nil {
167174
// Run virtualenv if the dir does not exist.
168-
if err := sh.Run("virtualenv", ve); err != nil {
175+
if err := sh.Run("virtualenv", args...); err != nil {
169176
return "", err
170177
}
171178
}
@@ -176,7 +183,7 @@ func PythonVirtualenv() (string, error) {
176183
}
177184

178185
pip := virtualenvPath(ve, "pip")
179-
args := []string{"install"}
186+
args = []string{"install"}
180187
if !mg.Verbose() {
181188
args = append(args, "--quiet")
182189
}

libbeat/scripts/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ load-tests: ## @testing Runs load tests
245245
# Sets up the virtual python environment
246246
.PHONY: python-env
247247
python-env: ${ES_BEATS}/libbeat/tests/system/requirements.txt
248-
@test -d ${PYTHON_ENV} || virtualenv ${VIRTUALENV_PARAMS} ${PYTHON_ENV}
248+
@test -d ${PYTHON_ENV} || virtualenv $(if ${PYTHON_EXE},-p ${PYTHON_EXE}) ${VIRTUALENV_PARAMS} ${PYTHON_ENV}
249249
@. ${PYTHON_ENV}/bin/activate && pip install ${PIP_INSTALL_PARAMS} -q --upgrade pip ; \
250250
if [ -a ./tests/system/requirements.txt ] && [ ! ${ES_BEATS}/libbeat/tests/system/requirements.txt -ef ./tests/system/requirements.txt ] ; then \
251251
. ${PYTHON_ENV}/bin/activate && pip install ${PIP_INSTALL_PARAMS} -qUr ${ES_BEATS}/libbeat/tests/system/requirements.txt -Ur ./tests/system/requirements.txt ; \

0 commit comments

Comments
 (0)