genpkgpy.mk (2731B)
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 # use older pip for compatability with pip-tools<7.5.2 17 # https://github.com/jazzband/pip-tools/issues/2252 18 #PYTHON_VENV_INSTALL:=pip-tools wheel 'pip<25' 19 20 pycodestyle: $(patsubst $(pthbs_genpkgpy)/%.py,$(pthbs_genpkgpy)/.%.pyfmt,$(PY_SRC)) $(VENV)/.done 21 '$(VENV)/bin/pylama' -l 88 $(PY_SRC) || true 22 23 $(pthbs_genpkgpy)/.%.pyfmt: $(pthbs_genpkgpy)/%.py $(VENV)/.done 24 '$(VENV)/bin/isort' - <'$<' >'$<.tmp1' 25 cp -a '$<' '$<.tmp2' 26 '$(VENV)/bin/black' -S - <'$<.tmp1' >'$<.tmp2' 27 rm '$<.tmp1' 28 if cmp -s '$<.tmp2' '$<'; then rm -v '$<.tmp2'; else mv -v '$<.tmp2' '$<'; fi 29 touch $@ 30 31 .PHONY: py-requirements py-wheels py-venv py-virtualenv py-genpkg 32 py-requirements: $(PY_REQ) 33 34 py-wheels: $(PY_WHL)/.done 35 36 py-venv: $(VENV)/.done 37 38 py-virtualenv: py-venv 39 40 py-genpkg: $(VENV)/.done $(cache)/link/git-commit-sha1/.local $(cache)/link/file-sha256/.local 41 '$(VENV)/bin/python' $(pthbs_genpkgpy)/genpkg.py \ 42 --package-dir='$(packages)' \ 43 --template-dir='$(templates)' \ 44 --index-dir='$(index)' \ 45 --cache-dir='$(cache)' 46 47 py-genpkgall: $(VENV)/.done $(cache)/link/git-commit-sha1/.local $(cache)/link/file-sha256/.local 48 for varsfile in '$(variants)'/*.yaml; do \ 49 mkdir -p "$${varsfile%.yaml}" && \ 50 '$(VENV)/bin/python' $(pthbs_genpkgpy)/genpkg.py \ 51 --vars-file="$${varsfile}" \ 52 --write-mkfile="$${varsfile%.yaml}.mk" \ 53 --package-dir="$${varsfile%.yaml}" \ 54 --template-dir='$(templates)' \ 55 --index-dir='$(index)' \ 56 --cache-dir='$(cache)' || exit $$?; \ 57 done 58 59 # -- requirement file rules 60 61 $(PY_REQ): $(pthbs_genpkgpy)/py-requirements.in $(VENV)/bin/pip-compile 62 '$(VENV)/bin/pip-compile' -v --annotate -o '$@.new' '$(pthbs_genpkgpy)/py-requirements.in' 63 mv '$@.new' '$@' 64 65 # -- wheel building rules 66 67 $(PY_WHL)/.done: $(PY_REQ) 68 mkdir -p '$(PY_WHL)' 69 '$(VENV)/bin/python' -m pip wheel -w '$(PY_WHL)' -r '$(PY_REQ)' 70 touch '$@' 71 72 # -- virtualenv rules 73 74 $(VENV)/bin/pip-compile $(VENV)/bin/pip-sync: 75 if test -e '$(VENV)'; then rm -r '$(VENV)'; else true; fi 76 mkdir -p virtualenvs 77 $(PYTHON_VENV) '$(VENV)' 78 '$(VENV)/bin/pip' install -I $(PYTHON_VENV_INSTALL) 79 80 $(VENV)/.done: $(PY_REQ) $(VENV)/bin/pip-sync $(PY_WHL)/.done 81 $(VENV)/bin/pip-sync --no-index -f '$(PY_WHL)' '$(PY_REQ)' 82 ln -sf 'virtualenvs/$(PYTHON_IMPL)' '$(cache)/venv' 83 touch '$@'