on master help sign in
makefile.python: hardening - drop virtualenv, drop build support py2

From py3.3 on a subset of virtualenv is built-in, so you can run '-m venv' ot of the box. - replace: $(PY_ENV_BIN)/pip --> $(PY_ENV_BIN)/python -m pip - remove obsolete virtualenv-exe target and adjust VTENV_OPTS - remove obsolete msg-pip-exe target - print list of py launchers available from $(PY_ENV_BIN) to the log - fix hard coded ./local Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit9b48ae47ec837250a9a15e26f85ada33b7aa4f71 authorMarkus Heiser <markus.heiser@darmarit.de> dateWed 1 Apr 2020, 14:16 (7 years ago) parent8c145ff
2 files changed+26−65
.travis.yml−1 utils/makefile.python+26−64
.travis.yml−1
@@ -28,7 +28,6 @@ stages:
2828
2929jobs:
3030 include:
31− - python: "2.7"
3231 - python: "3.5"
3332 - python: "3.6"
3433 - stage: docker
utils/makefile.python+26−64
@@ -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
@@ -26,7 +30,7 @@ PYLINT_RC ?= .pylintrc
2630TEST_FOLDER ?= ./tests
2731TEST ?= .
2832
29−VTENV_OPTS = "--no-site-packages"
33+VTENV_OPTS ?=
3034PY_ENV = ./local/py$(PY)
3135PY_ENV_BIN = $(PY_ENV)/bin
3236PY_ENV_ACT = . $(PY_ENV_BIN)/activate
@@ -37,20 +41,6 @@ ifeq ($(OS),Windows_NT)
3741 PY_ENV_ACT = $(PY_ENV_BIN)/activate
3842endif
3943
40−ifeq ($(PYTHON),python)
41− VIRTUALENV = virtualenv
42−else
43− VIRTUALENV = virtualenv --python=$(PYTHON)
44−endif
45−
46−ifeq ($(KBUILD_VERBOSE),1)
47− PIP_VERBOSE =
48− VIRTUALENV_VERBOSE =
49−else
50− PIP_VERBOSE = "-q"
51− VIRTUALENV_VERBOSE = "-q"
52−endif
53−
5444python-help::
5545 @echo 'makefile.python:'
5646 @echo ' pyenv | pyenv[un]install'
@@ -59,7 +49,7 @@ python-help::
5949 @echo ' pylint - run pylint *linting*'
6050 @echo ' pytest - run *tox* test on python objects'
6151 @echo ' pydebug - run tests within a PDB debug session'
62− @echo ' pybuild - build python packages'
52+ @echo ' pybuild - build python packages ($(PYDIST) $(PYBUILD))'
6353 @echo ' pyclean - clean intermediate python objects'
6454 @echo ' targets using system users environment:'
6555 @echo ' py[un]install - [un]install python objects in editable mode'
@@ -94,38 +84,6 @@ python-exe:
9484 @:
9585endif
9686
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−
12987# ------------------------------------------------------------------------------
13088# commands
13189# ------------------------------------------------------------------------------
@@ -136,9 +94,9 @@ quiet_cmd_pyinstall = INSTALL $2
13694
13795# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
13896quiet_cmd_pyenvinstall = PYENV install $2
139− cmd_pyenvinstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
97+ cmd_pyenvinstall = $(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
14098
141−# Uninstall the package. Since pip does not uninstall the no longer needed
99+# Uninstall the package. Since pip does not uninstall the no longer needed
142100# depencies (something like autoremove) the depencies remain.
143101
144102# $2 package name to uninstall, this uses pip from the OS.
@@ -147,16 +105,19 @@ quiet_cmd_pyuninstall = UNINSTALL $2
147105
148106# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
149107quiet_cmd_pyenvuninstall = PYENV uninstall $2
150− cmd_pyenvuninstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes $2
108+ cmd_pyenvuninstall = $(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) uninstall --yes $2
151109
152110# $2 path to folder where virtualenv take place
111+# creating a virtualenv uses $(PYTHON) from the OS!
153112quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
154113 cmd_virtualenv = \
155− if [ ! -d "./$(PY_ENV)" ];then \
156− $(VIRTUALENV) $(VIRTUALENV_VERBOSE) $(VTENV_OPTS) $2; \
114+ if [ ! -d "$(PY_ENV)" ];then \
115+ echo "PYENV create virtualenv $2"; \
116+ $(PYTHON) -m venv $(VTENV_OPTS) $2; \
157117 else \
158118 echo "PYENV using virtualenv from $2"; \
159− fi
119+ fi; \
120+ echo "commands available at $(PY_ENV_BIN):"; ls $(PY_ENV_BIN) | $(FMT) ;
160121
161122# $2 path to lint
162123quiet_cmd_pylint = LINT $@
@@ -192,14 +153,14 @@ quiet_cmd_pytest = TEST $@
192153# .. _installing: https://packaging.python.org/tutorials/installing-packages/
193154#
194155quiet_cmd_pybuild = BUILD $@
195− cmd_pybuild = $(PY_ENV_BIN)/$(PYTHON) setup.py \
156+ cmd_pybuild = $(PY_ENV_BIN)/python setup.py \
196157 sdist -d $(PYDIST) \
197158 bdist_wheel --bdist-dir $(PYBUILD) -d $(PYDIST)
198159
199160quiet_cmd_pyclean = CLEAN $@
200161# remove 'build' folder since bdist_wheel does not care the --bdist-dir
201162 cmd_pyclean = \
202− rm -rf $(PYDIST) $(PYBUILD) ./local ./.tox *.egg-info ;\
163+ rm -rf $(PYDIST) $(PYBUILD) $(PY_ENV) ./.tox *.egg-info ;\
203164 find . -name '*.pyc' -exec rm -f {} + ;\
204165 find . -name '*.pyo' -exec rm -f {} + ;\
205166 find . -name __pycache__ -exec rm -rf {} +
@@ -230,15 +191,16 @@ PHONY += pyclean
230191pyclean:
231192 $(call cmd,pyclean)
232193
233−# to build *local* environment, python and virtualenv from the OS is needed!
194+# to build *local* environment, python from the OS is needed!
234195pyenv: $(PY_ENV)
235−$(PY_ENV): virtualenv-exe python-exe
196+$(PY_ENV): python-exe
236197 $(call cmd,virtualenv,$(PY_ENV))
237− @$(PY_ENV_BIN)/pip install $(PIP_VERBOSE) -r requirements.txt
198+ $(Q)$(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -U pip wheel pip setuptools
199+ $(Q)$(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -r requirements.txt
238200
239201PHONY += pylint-exe
240202pylint-exe: $(PY_ENV)
241− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install pylint
203+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install pylint
242204
243205PHONY += pylint
244206pylint: pylint-exe
@@ -262,15 +224,15 @@ pydebug: $(PY_ENV)
262224
263225# install / uninstall python objects into virtualenv (PYENV)
264226pyenv-install: $(PY_ENV)
265− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e .
227+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e .
266228 @echo "ACTIVATE $(call normpath,$(PY_ENV_ACT)) "
267229
268230pyenv-uninstall: $(PY_ENV)
269− @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes .
231+ @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) uninstall --yes .
270232
271233# runs python interpreter from ./local/py<N>/bin/python
272234pyenv-python: pyenv-install
273− cd ./local; ../$(PY_ENV_BIN)/python -i
235+ $(PY_ENV_BIN)/python -i
274236
275237# With 'dependency_links=' setuptools supports dependencies on packages hosted
276238# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
@@ -284,7 +246,7 @@ pyenv-python: pyenv-install
284246
285247# https://github.com/pypa/twine
286248PHONY += upload-pypi
287−upload-pypi: pyclean pybuild
249+upload-pypi: pyclean pyenvinstall pybuild
288250 @$(PY_ENV_BIN)/twine upload $(PYDIST)/*
289251
290252.PHONY: $(PHONY)