@@ -5,6 +5,7 @@ PYOBJECTS ?=
55
66SITE_PYTHON ?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))site-python
77export PYTHONPATH := $(SITE_PYTHON):$$PYTHONPATH
8+export PY_ENV PYDIST PYBUILD
89
910# folder where the python distribution takes place
1011PYDIST ?= ./py_dist
@@ -12,6 +13,9 @@ PYDIST ?= ./py_dist
1213PYBUILD ?= ./py_build
1314# python version to use
1415PY ?=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.
1519PYTHON ?= python$(PY)
1620PIP ?= pip$(PY)
1721PIP_INST ?= --user
@@ -59,7 +63,7 @@ python-help::
5963 @echo ' pylint - run pylint *linting*'
6064 @echo ' pytest - run *tox* test on python objects'
6165 @echo ' pydebug - run tests within a PDB debug session'
62− @echo ' pybuild - build python packages'
66+ @echo ' pybuild - build python packages ($(PYDIST) $(PYBUILD))'
6367 @echo ' pyclean - clean intermediate python objects'
6468 @echo ' targets using system users environment:'
6569 @echo ' py[un]install - [un]install python objects in editable mode'
@@ -94,38 +98,6 @@ python-exe:
9498 @:
9599endif
96100
97−msg-pip-exe:
98− @echo "\n $(PIP) is required\n\n\
99− Make sure you have updated pip installed, grab it from\n\
100− https://pip.pypa.io or install it from your package\n\
101− manager. On debian based OS these requirements are\n\
102− installed by::\n\n\
103− sudo -H apt-get install python$(PY)-pip\n" | $(FMT)
104−
105−ifeq ($(shell which $(PIP) >/dev/null 2>&1; echo $$?), 1)
106−pip-exe: msg-pip-exe
107− $(error The '$(PIP)' command was not found)
108−else
109−pip-exe:
110− @:
111−endif
112−
113−PHONY += msg-virtualenv-exe virtualenv-exe
114−msg-virtualenv-exe:
115− @echo "\n virtualenv is required\n\n\
116− Make sure you have an updated virtualenv installed, grab it from\n\
117− https://virtualenv.pypa.io/en/stable/installation/ or install it\n\
118− via pip by::\n\n\
119− pip install --user https://github.com/pypa/virtualenv/tarball/master\n" | $(FMT)
120−
121−ifeq ($(shell which virtualenv >/dev/null 2>&1; echo $$?), 1)
122−virtualenv-exe: msg-virtualenv-exe
123− $(error The 'virtualenv' command was not found)
124−else
125−virtualenv-exe:
126− @:
127−endif
128−
129101# ------------------------------------------------------------------------------
130102# commands
131103# ------------------------------------------------------------------------------
@@ -136,9 +108,9 @@ quiet_cmd_pyinstall = INSTALL $2
136108
137109# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
138110quiet_cmd_pyenvinstall = PYENV install $2
139− 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)
140112
141−# 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
142114# depencies (something like autoremove) the depencies remain.
143115
144116# $2 package name to uninstall, this uses pip from the OS.
@@ -147,7 +119,7 @@ quiet_cmd_pyuninstall = UNINSTALL $2
147119
148120# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
149121quiet_cmd_pyenvuninstall = PYENV uninstall $2
150− 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
151123
152124# $2 path to folder where virtualenv take place
153125quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
@@ -160,10 +132,10 @@ quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
160132
161133# $2 path to lint
162134quiet_cmd_pylint = LINT $@
163− cmd_pylint = $(PY_ENV_BIN)/pylint --rcfile $(PYLINT_RC) $2
135+ cmd_pylint = $(PY_ENV_BIN)/python -m pylint --rcfile $(PYLINT_RC) $2
164136
165137quiet_cmd_pytest = TEST $@
166− cmd_pytest = $(PY_ENV_BIN)/tox -vv
138+ cmd_pytest = $(PY_ENV_BIN)/python -m tox -vv
167139
168140# setuptools, pip, easy_install its a mess full of cracks, a documentation hell
169141# and broken by design ... all sucks, I really, really hate all this ... aaargh!
@@ -192,14 +164,14 @@ quiet_cmd_pytest = TEST $@
192164# .. _installing: https://packaging.python.org/tutorials/installing-packages/
193165#
194166quiet_cmd_pybuild = BUILD $@
195− cmd_pybuild = $(PY_ENV_BIN)/$(PYTHON) setup.py \
167+ cmd_pybuild = $(PY_ENV_BIN)/python setup.py \
196168 sdist -d $(PYDIST) \
197169 bdist_wheel --bdist-dir $(PYBUILD) -d $(PYDIST)
198170
199171quiet_cmd_pyclean = CLEAN $@
200172# remove 'build' folder since bdist_wheel does not care the --bdist-dir
201173 cmd_pyclean = \
202− rm -rf $(PYDIST) $(PYBUILD) ./local ./.tox *.egg-info ;\
174+ rm -rf $(PYDIST) $(PYBUILD) $(PY_ENV) ./.tox *.egg-info ;\
203175 find . -name '*.pyc' -exec rm -f {} + ;\
204176 find . -name '*.pyo' -exec rm -f {} + ;\
205177 find . -name __pycache__ -exec rm -rf {} +
@@ -230,15 +202,16 @@ PHONY += pyclean
230202pyclean:
231203 $(call cmd,pyclean)
232204
233−# to build *local* environment, python and virtualenv from the OS is needed!
205+# to build *local* environment, python from the OS is needed!
234206pyenv: $(PY_ENV)
235−$(PY_ENV): virtualenv-exe python-exe
207+$(PY_ENV): python-exe
236208 $(call cmd,virtualenv,$(PY_ENV))
237− @$(PY_ENV_BIN)/pip install $(PIP_VERBOSE) -r requirements.txt
209+ $(Q)$(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -U pip wheel pip setuptools
210+ $(Q)$(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -r requirements.txt
238211
239212PHONY += pylint-exe
240213pylint-exe: $(PY_ENV)
241− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install pylint
214+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install pylint
242215
243216PHONY += pylint
244217pylint: pylint-exe
@@ -262,15 +235,15 @@ pydebug: $(PY_ENV)
262235
263236# install / uninstall python objects into virtualenv (PYENV)
264237pyenv-install: $(PY_ENV)
265− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e .
238+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e .
266239 @echo "ACTIVATE $(call normpath,$(PY_ENV_ACT)) "
267240
268241pyenv-uninstall: $(PY_ENV)
269− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes .
242+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) uninstall --yes .
270243
271244# runs python interpreter from ./local/py<N>/bin/python
272245pyenv-python: pyenv-install
273− cd ./local; ../$(PY_ENV_BIN)/python -i
246+ $(PY_ENV_BIN)/python -i
274247
275248# With 'dependency_links=' setuptools supports dependencies on packages hosted
276249# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
@@ -284,7 +257,7 @@ pyenv-python: pyenv-install
284257
285258# https://github.com/pypa/twine
286259PHONY += upload-pypi
287−upload-pypi: pyclean pybuild
260+upload-pypi: pyclean pyenvinstall pybuild
288261 @$(PY_ENV_BIN)/twine upload $(PYDIST)/*
289262
290263.PHONY: $(PHONY)