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 = ./dist$(LXC_ENV_FOLDER)
12# folder where the python intermediate build files take place
13PYBUILD = ./build$(LXC_ENV_FOLDER)
14# python version to use
20# https://www.python.org/dev/peps/pep-0508/#extras
21#PY_SETUP_EXTRAS ?= \[develop,test\]
31PY_ENV = ./local$(LXC_ENV_FOLDER)/py$(PY)
32PY_ENV_BIN = $(PY_ENV)/bin
33PY_ENV_ACT = . $(PY_ENV_BIN)/activate
35ifeq ($(OS),Windows_NT)
37 PY_ENV_BIN = $(PY_ENV)/Scripts
38 PY_ENV_ACT = $(PY_ENV_BIN)/activate
42 @echo 'makefile.python:'
43 @echo ' pyenv | pyenv[un]install'
44 @echo ' build $(PY_ENV) & [un]install python objects'
45 @echo ' targts using pyenv $(PY_ENV):'
46 @echo ' pylint - run pylint *linting*'
47 @echo ' pytest - run *tox* test on python objects'
48 @echo ' pydebug - run tests within a PDB debug session'
49 @echo ' pybuild - build python packages ($(PYDIST) $(PYBUILD))'
50 @echo ' pyclean - clean intermediate python objects'
51 @echo ' targets using system users environment:'
52 @echo ' py[un]install - [un]install python objects in editable mode'
53 @echo ' upload-pypi - upload $(PYDIST)/* files to PyPi'
55 @echo ' make PY=2 [targets] => to eval targets with python 2 ($(PY))'
56 @echo ' make PIP_INST= => to set/unset pip install options ($(PIP_INST))'
57 @echo ' make TEST=. => choose test from $(TEST_FOLDER) (default "." runs all)'
58 @echo ' make DEBUG= => target "debug": do not invoke PDB on errors'
59 @echo ' make PY_SETUP_EXTRAS => also install extras_require from setup.py \[develop,test\]'
60 @echo ' when using target "pydebug", set breakpoints within py-source by adding::'
63# ------------------------------------------------------------------------------
65# ------------------------------------------------------------------------------
67PHONY += msg-python-exe python-exe
69 @echo "\n $(PYTHON) is required\n\n\
70 Make sure you have $(PYTHON) installed, grab it from\n\
71 https://www.python.org or install it from your package\n\
72 manager. On debian based OS these requirements are\n\
74 sudo -H apt-get install $(PYTHON)\n" | $(FMT)
76ifeq ($(shell which $(PYTHON) >/dev/null 2>&1; echo $$?), 1)
77python-exe: msg-python-exe
78 $(error The '$(PYTHON)' command was not found)
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\
90 sudo -H apt-get install python$(PY)-pip\n" | $(FMT)
92ifeq ($(shell which $(PIP) >/dev/null 2>&1; echo $$?), 1)
94 $(error The '$(PIP)' command was not found)
100# ------------------------------------------------------------------------------
102# ------------------------------------------------------------------------------
104# $2 path to folder with setup.py, this uses pip from the OS
105quiet_cmd_pyinstall = INSTALL $2
106 cmd_pyinstall = $(PIP) $(PIP_VERBOSE) install $(PIP_INST) -e $2$(PY_SETUP_EXTRAS)
108# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
109quiet_cmd_pyenvinstall = PYENV install $2
110 cmd_pyenvinstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS)
112# Uninstall the package. Since pip does not uninstall the no longer needed
113# depencies (something like autoremove) the depencies remain.
115# $2 package name to uninstall, this uses pip from the OS.
116quiet_cmd_pyuninstall = UNINSTALL $2
117 cmd_pyuninstall = $(PIP) $(PIP_VERBOSE) uninstall --yes $2
119# $2 path to folder with setup.py, this uses pip from pyenv (not OS!)
120quiet_cmd_pyenvuninstall = PYENV uninstall $2
121 cmd_pyenvuninstall = $(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes $2
123# $2 path to folder where virtualenv take place
124quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate
126 if [ ! -d "./$(PY_ENV)" ];then \
127 $(PYTHON) -m venv $(VTENV_OPTS) $2; \
129 echo "PYENV using virtualenv from $2"; \
133quiet_cmd_pylint = LINT $@
134 cmd_pylint = $(PY_ENV_BIN)/pylint --rcfile $(PYLINT_RC) $2
136quiet_cmd_pytest = TEST $@
137 cmd_pytest = $(PY_ENV_BIN)/tox -vv
139# setuptools, pip, easy_install its a mess full of cracks, a documentation hell
140# and broken by design ... all sucks, I really, really hate all this ... aaargh!
142# About python packaging see `Python Packaging Authority`_. Most of the names
143# here are mapped to ``setup(<name1>=..., <name2>=...)`` arguments in
144# ``setup.py``. See `Packaging and distributing projects`_ about ``setup(...)``
145# arguments. If this is all new for you, start with `PyPI Quick and Dirty`_.
155# .. _`Python Packaging Authority`: https://www.pypa.io
156# .. _`Packaging and distributing projects`: https://packaging.python.org/guides/distributing-packages-using-setuptools/
157# .. _`PyPI Quick and Dirty`: https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
158# .. _pythonwheels: https://pythonwheels.com/
159# .. _setuptools: https://setuptools.readthedocs.io/en/latest/setuptools.html
160# .. _packaging: https://packaging.python.org/guides/distributing-packages-using-setuptools/#packaging-and-distributing-projects
161# .. _sdist: https://packaging.python.org/guides/distributing-packages-using-setuptools/#source-distributions
162# .. _bdist_wheel: https://packaging.python.org/guides/distributing-packages-using-setuptools/#pure-python-wheels
163# .. _installing: https://packaging.python.org/tutorials/installing-packages/
165quiet_cmd_pybuild = BUILD $@
166 cmd_pybuild = $(PY_ENV_BIN)/python setup.py \
168 bdist_wheel --bdist-dir $(PYBUILD) -d $(PYDIST)
170quiet_cmd_pyclean = CLEAN $@
171# remove 'build' folder since bdist_wheel does not care the --bdist-dir
173 rm -rf $(PYDIST) $(PYBUILD) $(PY_ENV) ./.tox *.egg-info ;\
174 find . -name '*.pyc' -exec rm -f {} + ;\
175 find . -name '*.pyo' -exec rm -f {} + ;\
176 find . -name __pycache__ -exec rm -rf {} +
178# ------------------------------------------------------------------------------
180# ------------------------------------------------------------------------------
182# for installation use the pip from the OS!
185 $(call cmd,pyinstall,.)
189 $(call cmd,pyuninstall,$(PYOBJECTS))
191# for installation use the pip from PY_ENV (not the OS)!
193pyenvinstall: $(PY_ENV)
194 $(call cmd,pyenvinstall,.)
196PHONY += pyenvuninstall
197pyenvuninstall: $(PY_ENV)
198 $(call cmd,pyenvuninstall,$(PYOBJECTS))
204# to build *local* environment, python and virtualenv from the OS is needed!
207 $(call cmd,virtualenv,$(PY_ENV))
208 @$(PY_ENV_BIN)/pip install $(PIP_VERBOSE) -U wheel pip setuptools
209 @$(PY_ENV_BIN)/pip install $(PIP_VERBOSE) -r requirements.txt
213 @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install pylint
217 $(call cmd,pylint,$(PYOBJECTS))
228# set breakpoint with:
230# e.g. to run tests in debug mode in emacs use:
231# 'M-x pdb' ... 'make pydebug'
233 DEBUG=$(DEBUG) $(PY_ENV_BIN)/pytest $(DEBUG) -v $(TEST_FOLDER)/$(TEST)
235# install / uninstall python objects into virtualenv (PYENV)
236pyenv-install: $(PY_ENV)
237 @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) install -e .
238 @echo "ACTIVATE $(call normpath,$(PY_ENV_ACT)) "
240pyenv-uninstall: $(PY_ENV)
241 @$(PY_ENV_BIN)/pip $(PIP_VERBOSE) uninstall --yes .
243# runs python interpreter from ./local/py<N>/bin/python
244pyenv-python: pyenv-install
245 $(PY_ENV_BIN)/python -i
247# With 'dependency_links=' setuptools supports dependencies on packages hosted
248# on other reposetories then PyPi, see "Packages Not On PyPI" [1]. The big
249# drawback is, due to security reasons (I don't know where the security gate on
250# PyPi is), this feature is not supported by pip [2]. Thats why an upload to
251# PyPi is required and since uploads via setuptools is not recommended, we have
252# to imstall / use twine ... its really a mess.
254# [1] http://python-packaging.readthedocs.io/en/latest/dependencies.html#packages-not-on-pypi
255# [2] https://github.com/pypa/pip/pull/1519
257# https://github.com/pypa/twine
259upload-pypi: pyclean pyenvinstall pybuild
260 @$(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