genpkgpy.mk (2575B)
1 PYTHON_EXE?=python3 2 pthbs_genpkgpy?=. 3 cache?=cache 4 variants?=variants 5 6 # re-evaluate each time because there's no sensible way to check 7 # whether the python interpreter changed 8 $(eval $(shell $(PYTHON_EXE) $(pthbs_genpkgpy)/make_vars.py '$(cache)/make')) 9 10 PY_SRC:=$(wildcard $(pthbs_genpkgpy)/*.py) 11 PY_REQ:=$(pthbs_genpkgpy)/py-$(PYTHON_IMPL)-requirements.txt 12 PY_WHL:=$(cache)/wheels/$(PYTHON_IMPL) 13 VENV:=$(cache)/virtualenvs/$(PYTHON_IMPL) 14 PYTHON_VENV_INSTALL=pip-tools wheel 15 16 pycodestyle: $(patsubst $(pthbs_genpkgpy)/%.py,$(pthbs_genpkgpy)/.%.pyfmt,$(PY_SRC)) $(VENV)/.done 17 '$(VENV)/bin/pylama' -l 88 $(PY_SRC) || true 18 19 $(pthbs_genpkgpy)/.%.pyfmt: $(pthbs_genpkgpy)/%.py $(VENV)/.done 20 '$(VENV)/bin/isort' - <'$<' >'$<.tmp1' 21 cp -a '$<' '$<.tmp2' 22 '$(VENV)/bin/black' -S - <'$<.tmp1' >'$<.tmp2' 23 rm '$<.tmp1' 24 if cmp -s '$<.tmp2' '$<'; then rm -v '$<.tmp2'; else mv -v '$<.tmp2' '$<'; fi 25 touch $@ 26 27 .PHONY: py-requirements py-wheels py-venv py-virtualenv py-genpkg 28 py-requirements: $(PY_REQ) 29 30 py-wheels: $(PY_WHL)/.done 31 32 py-venv: $(VENV)/.done 33 34 py-virtualenv: py-venv 35 36 py-genpkg: $(VENV)/.done $(cache)/link/git-commit-sha1/.local $(cache)/link/file-sha256/.local 37 '$(VENV)/bin/python' $(pthbs_genpkgpy)/genpkg.py \ 38 --package-dir='$(packages)' \ 39 --template-dir='$(templates)' \ 40 --index-dir='$(index)' \ 41 --cache-dir='$(cache)' 42 43 py-genpkgall: $(VENV)/.done $(cache)/link/git-commit-sha1/.local $(cache)/link/file-sha256/.local 44 for varsfile in '$(variants)'/*.yaml; do \ 45 mkdir -p "$${varsfile%.yaml}" && \ 46 '$(VENV)/bin/python' $(pthbs_genpkgpy)/genpkg.py \ 47 --vars-file="$${varsfile}" \ 48 --write-mkfile="$${varsfile%.yaml}.mk" \ 49 --package-dir="$${varsfile%.yaml}" \ 50 --template-dir='$(templates)' \ 51 --index-dir='$(index)' \ 52 --cache-dir='$(cache)' || exit $$?; \ 53 done 54 55 # -- requirement file rules 56 57 $(PY_REQ): $(pthbs_genpkgpy)/py-requirements.in $(VENV)/bin/pip-compile 58 '$(VENV)/bin/pip-compile' -v --annotate -o '$@.new' '$(pthbs_genpkgpy)/py-requirements.in' 59 mv '$@.new' '$@' 60 61 # -- wheel building rules 62 63 $(PY_WHL)/.done: $(PY_REQ) 64 mkdir -p '$(PY_WHL)' 65 '$(VENV)/bin/python' -m pip wheel -w '$(PY_WHL)' -r '$(PY_REQ)' 66 touch '$@' 67 68 # -- virtualenv rules 69 70 $(VENV)/bin/pip-compile $(VENV)/bin/pip-sync: 71 if test -e '$(VENV)'; then rm -r '$(VENV)'; else true; fi 72 mkdir -p virtualenvs 73 $(PYTHON_VENV) '$(VENV)' 74 '$(VENV)/bin/pip' install -I $(PYTHON_VENV_INSTALL) 75 76 $(VENV)/.done: $(PY_REQ) $(VENV)/bin/pip-sync $(PY_WHL)/.done 77 $(VENV)/bin/pip-sync --no-index -f '$(PY_WHL)' '$(PY_REQ)' 78 ln -sf 'virtualenvs/$(PYTHON_IMPL)' '$(cache)/venv' 79 touch '$@'