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