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
8export PY_ENV PYDIST PYBUILD
10# folder where the python distribution takes place
11PYDIST = ./$(LXC_ENV_FOLDER)dist
12# folder where the python intermediate build files take place
13PYBUILD = ./$(LXC_ENV_FOLDER)build
14# python version to use
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.
23# https://www.python.org/dev/peps/pep-0508/#extras
24#PY_SETUP_EXTRAS ?= \[develop,test\]
33PY_ENV = ./$(LXC_ENV_FOLDER)local/py$(PY)
34PY_ENV_BIN = $(PY_ENV)/bin
35PY_ENV_ACT = . $(PY_ENV_BIN)/activate
37ifeq ($(OS),Windows_NT)
39 PY_ENV_BIN = $(PY_ENV)/Scripts
40 PY_ENV_ACT = $(PY_ENV_BIN)/activate
46 @echo 'makefile.python:'
47 @echo ' pyenv | pyenv[un]install'
48 @echo ' build $(PY_ENV) & [un]install python objects'
49 @echo ' targts using pyenv $(PY_ENV):'
50 @echo ' pylint - run pylint *linting*'
51 @echo ' pytest - run *tox* test on python objects'
52 @echo ' pydebug - run tests within a PDB debug session'
53 @echo ' pybuild - build python packages ($(PYDIST) $(PYBUILD))'
54 @echo ' pyclean - clean intermediate python objects'
55 @echo ' targets using system users environment:'
56 @echo ' py[un]install - [un]install python objects in editable mode'
57 @echo ' upload-pypi - upload $(PYDIST)/* files to PyPi'
59 @echo ' make PY=3.7 [targets] => to eval targets with python 3.7 ($(PY))'
60 @echo ' make PIP_INST= => to set/unset pip install options ($(PIP_INST))'
61 @echo ' make TEST=. => choose test from $(TEST_FOLDER) (default "." runs all)'
62 @echo ' make DEBUG= => target "debug": do not invoke PDB on errors'
63 @echo ' make PY_SETUP_EXTRAS => also install extras_require from setup.py \[develop,test\]'
64 @echo ' when using target "pydebug", set breakpoints within py-source by adding::'
67# ------------------------------------------------------------------------------
69# ------------------------------------------------------------------------------
71PHONY += msg-python-exe python-exe
73 @echo "\n $(PYTHON) is required\n\n\
74 Make sure you have $(PYTHON) installed, grab it from\n\
75 https://www.python.org or install it from your package\n\
76 manager. On debian based OS these requirements are\n\
78 sudo -H add-apt-repository ppa:deadsnakes/ppa\n\
80 sudo -H apt-get install $(PYTHON) $(PYTHON)-venv\n"
82ifeq ($(shell which $(PYTHON) >/dev/null 2>&1; echo $$?), 1)
83python-exe: msg-python-exe
84 $(error The '$(PYTHON)' command was not found)
91 @echo "\n $(PIP) is required\n\n\
92 Make sure you have updated pip installed, grab it from\n\
93 https://pip.pypa.io or install it from your package\n\
94 manager. On debian based OS these requirements are\n\
96 sudo -H apt-get install python$(PY)-pip\n" | $(FMT)
98ifeq ($(shell which $(PIP) >/dev/null 2>&1; echo $$?), 1)
100 $(error The '$(PIP)' command was not found)
106# ------------------------------------------------------------------------------
108# ------------------------------------------------------------------------------
110# $2 path to folder with setup.py, this uses pip from the OS
111quiet_cmd_pyinstall = INSTALL $2
112 cmd_pyinstall = $(PIP) $(PIP_VERBOSE) install $(PIP_INST) -e $2$(PY_SETUP_EXTRAS)
114# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
115quiet_cmd_pyenvinstall = PYENV install $2
117 if ! cat $(PY_ENV)/requirements.sha256 2>/dev/null | sha256sum --check --status 2>/dev/null; then \
118 rm -f $(PY_ENV)/requirements.sha256; \
119 $(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS) &&\
120 sha256sum requirements*.txt > $(PY_ENV)/requirements.sha256 ;\
122 echo "PYENV $2 already installed"; \
125# Uninstall the package. Since pip does not uninstall the no longer needed
126# depencies (something like autoremove) the depencies remain.
128# $2 package name to uninstall, this uses pip from the OS.
129quiet_cmd_pyuninstall = UNINSTALL $2
130 cmd_pyuninstall = $(PIP) $(PIP_VERBOSE) uninstall --yes $2
132# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
133quiet_cmd_pyenvuninstall = PYENV uninstall $2
134 cmd_pyenvuninstall = $(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) uninstall --yes $2
136# $2 path to folder where virtualenv take place
137quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
139 if [ -d "./$(PY_ENV)" -a -x "./$(PY_ENV_BIN)/python" ]; then \
140 echo "PYENV using virtualenv from $2"; \
142 $(PYTHON) -m venv $(VTENV_OPTS) $2; \
143 $(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -U pip wheel setuptools; \
144 $(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -r requirements.txt; \
148quiet_cmd_pylint = LINT $@
149 cmd_pylint = $(PY_ENV_BIN)/python -m pylint -j 0 --rcfile $(PYLINT_RC) $2
151quiet_cmd_pytest = TEST $@
152 cmd_pytest = $(PY_ENV_BIN)/python -m tox -vv
154# setuptools, pip, easy_install its a mess full of cracks, a documentation hell
155# and broken by design ... all sucks, I really, really hate all this ... aaargh!
157# About python packaging see `Python Packaging Authority`_. Most of the names
158# here are mapped to ``setup(<name1>=..., <name2>=...)`` arguments in
159# ``setup.py``. See `Packaging and distributing projects`_ about ``setup(...)``
160# arguments. If this is all new for you, start with `PyPI Quick and Dirty`_.
170# .. _`Python Packaging Authority`: https://www.pypa.io
171# .. _`Packaging and distributing projects`: https://packaging.python.org/guides/distributing-packages-using-setuptools/
172# .. _`PyPI Quick and Dirty`: https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
173# .. _pythonwheels: https://pythonwheels.com/
174# .. _setuptools: https://setuptools.readthedocs.io/en/latest/setuptools.html
175# .. _packaging: https://packaging.python.org/guides/distributing-packages-using-setuptools/#packaging-and-distributing-projects
176# .. _sdist: https://packaging.python.org/guides/distributing-packages-using-setuptools/#source-distributions
177# .. _bdist_wheel: https://packaging.python.org/guides/distributing-packages-using-setuptools/#pure-python-wheels
178# .. _installing: https://packaging.python.org/tutorials/installing-packages/
180quiet_cmd_pybuild = BUILD $@
181 cmd_pybuild = $(PY_ENV_BIN)/python setup.py \
183 bdist_wheel --bdist-dir $(PYBUILD) -d $(PYDIST)
185quiet_cmd_pyclean = CLEAN $@
186# remove 'build' folder since bdist_wheel does not care the --bdist-dir
188 rm -rf $(PYDIST) $(PYBUILD) $(PY_ENV) ./.tox *.egg-info ;\
189 find . -name '*.pyc' -exec rm -f {} + ;\
190 find . -name '*.pyo' -exec rm -f {} + ;\
191 find . -name __pycache__ -exec rm -rf {} +
193# ------------------------------------------------------------------------------
195# ------------------------------------------------------------------------------
197# for installation use the pip from the OS!
200 $(call cmd,pyinstall,.)
204 $(call cmd,pyuninstall,$(PYOBJECTS))
206# for installation use the pip from PY_ENV (not the OS)!
208pyenvinstall: $(PY_ENV)
209 $(call cmd,pyenvinstall,.)
211PHONY += pyenvuninstall
212pyenvuninstall: $(PY_ENV)
213 $(call cmd,pyenvuninstall,$(PYOBJECTS))
219# to build *local* environment, python from the OS is needed!
222 $(call cmd,virtualenv,$(PY_ENV))
226 @$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install pylint
230 $(call cmd,pylint,$(PYOBJECTS))
241# set breakpoint with:
243# e.g. to run tests in debug mode in emacs use:
244# 'M-x pdb' ... 'make pydebug'
246 DEBUG=$(DEBUG) $(PY_ENV_BIN)/pytest $(DEBUG) -v $(TEST_FOLDER)/$(TEST)
248# runs python interpreter from ./local/py<N>/bin/python
249pyenv-python: pyenvinstall
250 $(PY_ENV_BIN)/python -i
252# With 'dependency_links=' setuptools supports dependencies on packages hosted
253# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
254# drawback is, due to security reasons (I don't know where the security gate on
255# PyPi is), this feature is not supported by pip [2]. Thats why an upload to
256# PyPi is required and since uploads via setuptools is not recommended, we have
257# to imstall / use twine ... its really a mess.
259# [1] https://python-packaging.readthedocs.io/en/latest/dependencies.html#packages-not-on-pypi
260# [2] https://github.com/pypa/pip/pull/1519
262# https://github.com/pypa/twine
263PHONY += upload-pypi upload-pypi-test
264upload-pypi: pyclean pyenvinstall pybuild
265 @$(PY_ENV_BIN)/twine upload $(PYDIST)/*
267upload-pypi-test: pyclean pyenvinstall pybuild
268 @$(PY_ENV_BIN)/twine upload -r testpypi $(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