@@ -12,9 +12,12 @@ PYDIST = ./$(LXC_ENV_FOLDER)dist
1212# folder where the python intermediate build files take place
1313PYBUILD = ./$(LXC_ENV_FOLDER)build
1414# python version to use
15−PY =3
16−PYTHON = python$(PY)
17−PIP = pip$(PY)
15+PY ?=3
16+# $(PYTHON) points to the python interpreter from the OS! The python from the
17+# OS is needed e.g. to create a virtualenv. For tasks inside the virtualenv the
18+# interpeter from '$(PY_ENV_BIN)/python' is used.
19+PYTHON ?= python$(PY)
20+PIP ?= pip$(PY)
1821PIP_INST ?= --user
1922
2023# https://www.python.org/dev/peps/pep-0508/#extras
@@ -27,7 +30,7 @@ PYLINT_RC ?= .pylintrc
2730TEST_FOLDER ?= ./tests
2831TEST ?= .
2932
30−VTENV_OPTS ?=
33+VTENV_OPTS = "--no-site-packages"
3134PY_ENV = ./$(LXC_ENV_FOLDER)local/py$(PY)
3235PY_ENV_BIN = $(PY_ENV)/bin
3336PY_ENV_ACT = . $(PY_ENV_BIN)/activate
@@ -38,6 +41,20 @@ ifeq ($(OS),Windows_NT)
3841 PY_ENV_ACT = $(PY_ENV_BIN)/activate
3942endif
4043
44+ifeq ($(PYTHON),python)
45+ VIRTUALENV = virtualenv
46+else
47+ VIRTUALENV = virtualenv --python=$(PYTHON)
48+endif
49+
50+ifeq ($(KBUILD_VERBOSE),1)
51+ PIP_VERBOSE =
52+ VIRTUALENV_VERBOSE =
53+else
54+ PIP_VERBOSE = "-q"
55+ VIRTUALENV_VERBOSE = "-q"
56+endif
57+
4158python-help::
4259 @echo 'makefile.python:'
4360 @echo ' pyenv | pyenv[un]install'
@@ -81,22 +98,6 @@ python-exe:
8198 @:
8299endif
83100
84−msg-pip-exe:
85− @echo "\n $(PIP) is required\n\n\
86− Make sure you have updated pip installed, grab it from\n\
87− https://pip.pypa.io or install it from your package\n\
88− manager. On debian based OS these requirements are\n\
89− installed by::\n\n\
90− sudo -H apt-get install python$(PY)-pip\n" | $(FMT)
91−
92−ifeq ($(shell which $(PIP) >/dev/null 2>&1; echo $$?), 1)
93−pip-exe: msg-pip-exe
94− $(error The '$(PIP)' command was not found)
95−else
96−pip-exe:
97− @:
98−endif
99−
100101# ------------------------------------------------------------------------------
101102# commands
102103# ------------------------------------------------------------------------------
@@ -107,9 +108,9 @@ quiet_cmd_pyinstall = INSTALL $2
107108
108109# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
109110quiet_cmd_pyenvinstall = PYENV install $2
110− cmd_pyenvinstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
111+ cmd_pyenvinstall = $(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
111112
112−# Uninstall the package. Since pip does not uninstall the no longer needed
113+# Uninstall the package. Since pip does not uninstall the no longer needed
113114# depencies (something like autoremove) the depencies remain.
114115
115116# $2 package name to uninstall, this uses pip from the OS.
@@ -118,25 +119,23 @@ quiet_cmd_pyuninstall = UNINSTALL $2
118119
119120# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
120121quiet_cmd_pyenvuninstall = PYENV uninstall $2
121− cmd_pyenvuninstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes $2
122+ cmd_pyenvuninstall = $(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) uninstall --yes $2
122123
123124# $2 path to folder where virtualenv take place
124125quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
125126 cmd_virtualenv = \
126− if [ ! -d "$(PY_ENV)" ];then \
127− echo "PYENV create virtualenv $2"; \
128− $(PYTHON) -m venv $(VTENV_OPTS) $2; \
127+ if [ ! -d "./$(PY_ENV)" ];then \
128+ $(VIRTUALENV) $(VIRTUALENV_VERBOSE) $(VTENV_OPTS) $2; \
129129 else \
130130 echo "PYENV using virtualenv from $2"; \
131− fi; \
132− echo "commands available at $(PY_ENV_BIN):"; ls $(PY_ENV_BIN) | $(FMT) ;
131+ fi
133132
134133# $2 path to lint
135134quiet_cmd_pylint = LINT $@
136− cmd_pylint = $(PY_ENV_BIN)/pylint --rcfile $(PYLINT_RC) $2
135+ cmd_pylint = $(PY_ENV_BIN)/python -m pylint --rcfile $(PYLINT_RC) $2
137136
138137quiet_cmd_pytest = TEST $@
139− cmd_pytest = $(PY_ENV_BIN)/tox -vv
138+ cmd_pytest = $(PY_ENV_BIN)/python -m tox -vv
140139
141140# setuptools, pip, easy_install its a mess full of cracks, a documentation hell
142141# and broken by design ... all sucks, I really, really hate all this ... aaargh!
@@ -203,7 +202,7 @@ PHONY += pyclean
203202pyclean:
204203 $(call cmd,pyclean)
205204
206−# to build *local* environment, python and virtualenv from the OS is needed!
205+# to build *local* environment, python from the OS is needed!
207206pyenv: $(PY_ENV)
208207$(PY_ENV): python-exe
209208 $(call cmd,virtualenv,$(PY_ENV))
@@ -212,7 +211,7 @@ $(PY_ENV): python-exe
212211
213212PHONY += pylint-exe
214213pylint-exe: $(PY_ENV)
215− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install pylint
214+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install pylint
216215
217216PHONY += pylint
218217pylint: pylint-exe
@@ -236,11 +235,11 @@ pydebug: $(PY_ENV)
236235
237236# install / uninstall python objects into virtualenv (PYENV)
238237pyenv-install: $(PY_ENV)
239− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e .
238+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e .
240239 @echo "ACTIVATE $(call normpath,$(PY_ENV_ACT)) "
241240
242241pyenv-uninstall: $(PY_ENV)
243− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes .
242+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) uninstall --yes .
244243
245244# runs python interpreter from ./local/py<N>/bin/python
246245pyenv-python: pyenv-install