1# -*- coding: utf-8; mode: makefile-gmake -*-
3# list of python packages (folders) or modules (files) of this build
6SITE_PYTHON ?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))site-python
7export PYTHONPATH := $(SITE_PYTHON):$$PYTHONPATH
9# folder where the python distribution takes place
11# folder where the python intermediate build files take place
13# python version to use
19# https://www.python.org/dev/peps/pep-0508/#extras
20#PY_SETUP_EXTRAS ?= \[develop,test\]
29VTENV_OPTS = "--no-site-packages"
30PY_ENV = ./local/py$(PY)
31PY_ENV_BIN = $(PY_ENV)/bin
32PY_ENV_ACT = . $(PY_ENV_BIN)/activate
34ifeq ($(OS),Windows_NT)
36 PY_ENV_BIN = $(PY_ENV)/Scripts
37 PY_ENV_ACT = $(PY_ENV_BIN)/activate
40ifeq ($(PYTHON),python)
41 VIRTUALENV = virtualenv
43 VIRTUALENV = virtualenv --python=$(PYTHON)
46ifeq ($(KBUILD_VERBOSE),1)
51 VIRTUALENV_VERBOSE = "-q"
55 @echo 'makefile.python:'
56 @echo ' pyenv | pyenv[un]install'
57 @echo ' build $(PY_ENV) & [un]install python objects'
58 @echo ' targts using pyenv $(PY_ENV):'
59 @echo ' pylint - run pylint *linting*'
60 @echo ' pytest - run *tox* test on python objects'
61 @echo ' pydebug - run tests within a PDB debug session'
62 @echo ' pybuild - build python packages'
63 @echo ' pyclean - clean intermediate python objects'
64 @echo ' targets using system users environment:'
65 @echo ' py[un]install - [un]install python objects in editable mode'
66 @echo ' upload-pypi - upload $(PYDIST)/* files to PyPi'
68 @echo ' make PY=2 [targets] => to eval targets with python 2 ($(PY))'
69 @echo ' make PIP_INST= => to set/unset pip install options ($(PIP_INST))'
70 @echo ' make TEST=. => choose test from $(TEST_FOLDER) (default "." runs all)'
71 @echo ' make DEBUG= => target "debug": do not invoke PDB on errors'
72 @echo ' make PY_SETUP_EXTRAS => also install extras_require from setup.py \[develop,test\]'
73 @echo ' when using target "pydebug", set breakpoints within py-source by adding::'
76# ------------------------------------------------------------------------------
78# ------------------------------------------------------------------------------
80PHONY += msg-python-exe python-exe
82 @echo "\n $(PYTHON) is required\n\n\
83 Make sure you have $(PYTHON) installed, grab it from\n\
84 https://www.python.org or install it from your package\n\
85 manager. On debian based OS these requirements are\n\
87 sudo -H apt-get install $(PYTHON)\n" | $(FMT)
89ifeq ($(shell which $(PYTHON) >/dev/null 2>&1; echo $$?), 1)
90python-exe: msg-python-exe
91 $(error The '$(PYTHON)' command was not found)
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\
103 sudo -H apt-get install python$(PY)-pip\n" | $(FMT)
105ifeq ($(shell which $(PIP) >/dev/null 2>&1; echo $$?), 1)
107 $(error The '$(PIP)' command was not found)
113PHONY += msg-virtualenv-exe 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\
119 pip install --user https://github.com/pypa/virtualenv/tarball/master\n" | $(FMT)
121ifeq ($(shell which virtualenv >/dev/null 2>&1; echo $$?), 1)
122virtualenv-exe: msg-virtualenv-exe
123 $(error The 'virtualenv' command was not found)
129# ------------------------------------------------------------------------------
131# ------------------------------------------------------------------------------
133# $2 path to folder with setup.py, this uses pip from the OS
134quiet_cmd_pyinstall = INSTALL $2
135 cmd_pyinstall = $(PIP) $(PIP_VERBOSE) install $(PIP_INST) -e $2$(PY_SETUP_EXTRAS)
137# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
138quiet_cmd_pyenvinstall = PYENV install $2
139 cmd_pyenvinstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
141# Uninstall the package. Since pip does not uninstall the no longer needed
142# depencies (something like autoremove) the depencies remain.
144# $2 package name to uninstall, this uses pip from the OS.
145quiet_cmd_pyuninstall = UNINSTALL $2
146 cmd_pyuninstall = $(PIP) $(PIP_VERBOSE) uninstall --yes $2
148# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
149quiet_cmd_pyenvuninstall = PYENV uninstall $2
150 cmd_pyenvuninstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes $2
152# $2 path to folder where virtualenv take place
153quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
155 if [ ! -d "./$(PY_ENV)" ];then \
156 $(VIRTUALENV) $(VIRTUALENV_VERBOSE) $(VTENV_OPTS) $2; \
158 echo "PYENV using virtualenv from $2"; \
162quiet_cmd_pylint = LINT $@
163 cmd_pylint = $(PY_ENV_BIN)/pylint --rcfile $(PYLINT_RC) $2
165quiet_cmd_pytest = TEST $@
166 cmd_pytest = $(PY_ENV_BIN)/tox -vv
168# setuptools, pip, easy_install its a mess full of cracks, a documentation hell
169# and broken by design ... all sucks, I really, really hate all this ... aaargh!
171# About python packaging see `Python Packaging Authority`_. Most of the names
172# here are mapped to ``setup(<name1>=..., <name2>=...)`` arguments in
173# ``setup.py``. See `Packaging and distributing projects`_ about ``setup(...)``
174# arguments. If this is all new for you, start with `PyPI Quick and Dirty`_.
184# .. _`Python Packaging Authority`: https://www.pypa.io
185# .. _`Packaging and distributing projects`: https://packaging.python.org/guides/distributing-packages-using-setuptools/
186# .. _`PyPI Quick and Dirty`: https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
187# .. _pythonwheels: https://pythonwheels.com/
188# .. _setuptools: https://setuptools.readthedocs.io/en/latest/setuptools.html
189# .. _packaging: https://packaging.python.org/guides/distributing-packages-using-setuptools/#packaging-and-distributing-projects
190# .. _sdist: https://packaging.python.org/guides/distributing-packages-using-setuptools/#source-distributions
191# .. _bdist_wheel: https://packaging.python.org/guides/distributing-packages-using-setuptools/#pure-python-wheels
192# .. _installing: https://packaging.python.org/tutorials/installing-packages/
194quiet_cmd_pybuild = BUILD $@
195 cmd_pybuild = $(PY_ENV_BIN)/$(PYTHON) setup.py \
197 bdist_wheel --bdist-dir $(PYBUILD) -d $(PYDIST)
199quiet_cmd_pyclean = CLEAN $@
200# remove 'build' folder since bdist_wheel does not care the --bdist-dir
202 rm -rf $(PYDIST) $(PYBUILD) ./local ./.tox *.egg-info ;\
203 find . -name '*.pyc' -exec rm -f {} + ;\
204 find . -name '*.pyo' -exec rm -f {} + ;\
205 find . -name __pycache__ -exec rm -rf {} +
207# ------------------------------------------------------------------------------
209# ------------------------------------------------------------------------------
211# for installation use the pip from the OS!
214 $(call cmd,pyinstall,.)
218 $(call cmd,pyuninstall,$(PYOBJECTS))
220# for installation use the pip from PY_ENV (not the OS)!
222pyenvinstall: $(PY_ENV)
223 $(call cmd,pyenvinstall,.)
225PHONY += pyenvuninstall
226pyenvuninstall: $(PY_ENV)
227 $(call cmd,pyenvuninstall,$(PYOBJECTS))
233# to build *local* environment, python and virtualenv from the OS is needed!
235$(PY_ENV): virtualenv-exe python-exe
236 $(call cmd,virtualenv,$(PY_ENV))
237 @$(PY_ENV_BIN)/pip install $(PIP_VERBOSE) -r requirements.txt
241 @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install pylint
245 $(call cmd,pylint,$(PYOBJECTS))
256# set breakpoint with:
258# e.g. to run tests in debug mode in emacs use:
259# 'M-x pdb' ... 'make pydebug'
261 DEBUG=$(DEBUG) $(PY_ENV_BIN)/pytest $(DEBUG) -v $(TEST_FOLDER)/$(TEST)
263# install / uninstall python objects into virtualenv (PYENV)
264pyenv-install: $(PY_ENV)
265 @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e .
266 @echo "ACTIVATE $(call normpath,$(PY_ENV_ACT)) "
268pyenv-uninstall: $(PY_ENV)
269 @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes .
271# runs python interpreter from ./local/py<N>/bin/python
272pyenv-python: pyenv-install
273 cd ./local; ../$(PY_ENV_BIN)/python -i
275# With 'dependency_links=' setuptools supports dependencies on packages hosted
276# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
277# drawback is, due to security reasons (I don't know where the security gate on
278# PyPi is), this feature is not supported by pip [2]. Thats why an upload to
279# PyPi is required and since uploads via setuptools is not recommended, we have
280# to imstall / use twine ... its really a mess.
282# [1] http://python-packaging.readthedocs.io/en/latest/dependencies.html#packages-not-on-pypi
283# [2] https://github.com/pypa/pip/pull/1519
285# https://github.com/pypa/twine
287upload-pypi: pyclean pybuild
288 @$(PY_ENV_BIN)/twine upload $(PYDIST)/*
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list