pthbs

Packaging Through Hashed Build Scripts
git clone https://ccx.te2000.cz/git/pthbs
Log | Files | Refs | Submodules | README

python.mk (1696B)


      1 PYTHONPATH:=$(abspath .)
      2 PYTHON_EXE:=python3
      3 # re-evaluate each time because there's no sensible way to check
      4 # whether the python interpreter changed
      5 $(eval $(shell $(PYTHON_EXE) ./make_vars.py))
      6 
      7 PY_SRC:=$(wildcard *.py)
      8 PY_REQ:=py-$(PYTHON_IMPL)-requirements.txt
      9 PY_WHL:=work/wheels/$(PYTHON_IMPL)
     10 VENV:=work/virtualenvs/$(PYTHON_IMPL)
     11 PYTHON_VENV_INSTALL=pip-tools wheel
     12 
     13 pycodestyle: $(patsubst %.py,.%.pyfmt,$(PY_SRC)) $(VENV)/.done
     14 	'$(VENV)/bin/pylama' -l 88 $(PY_SRC) || true
     15 
     16 .%.pyfmt: %.py $(VENV)/.done
     17 	'$(VENV)/bin/isort' - <'$<' >'$<.tmp1'
     18 	cp -a '$<' '$<.tmp2'
     19 	'$(VENV)/bin/black' -S - <'$<.tmp1' >'$<.tmp2'
     20 	rm '$<.tmp1'
     21 	if cmp -s '$<.tmp2' '$<'; then rm -v '$<.tmp2'; else mv -v '$<.tmp2' '$<'; fi
     22 	touch $@
     23 
     24 .PHONY: py-requirements py-wheels py-venv py-virtualenv py-genpkg
     25 py-requirements: $(PY_REQ)
     26 
     27 py-wheels: $(PY_WHL)/.done
     28 
     29 py-venv: $(VENV)/.done
     30 
     31 py-virtualenv: py-venv
     32 
     33 py-genpkg: $(VENV)/.done
     34 	'$(VENV)/bin/python' genpkg.py
     35 
     36 # -- requirement file rules
     37 
     38 $(PY_REQ): py-requirements.in $(VENV)/bin/pip-compile
     39 	'$(VENV)/bin/pip-compile' -v --annotate -o '$@.new' py-requirements.in
     40 	mv '$@.new' '$@'
     41 
     42 # -- wheel building rules
     43 
     44 $(PY_WHL)/.done: $(PY_REQ)
     45 	mkdir -p '$(PY_WHL)'
     46 	'$(VENV)/bin/python' -m pip wheel -w '$(PY_WHL)' -r '$(PY_REQ)'
     47 	touch '$@'
     48 
     49 # -- virtualenv rules
     50 
     51 $(VENV)/bin/pip-compile $(VENV)/bin/pip-sync:
     52 	if test -e '$(VENV)'; then rm -r '$(VENV)'; else true; fi
     53 	mkdir -p virtualenvs
     54 	$(PYTHON_VENV) '$(VENV)'
     55 	'$(VENV)/bin/pip' install -I $(PYTHON_VENV_INSTALL)
     56 
     57 $(VENV)/.done: $(PY_REQ) $(VENV)/bin/pip-sync $(PY_WHL)/.done
     58 	$(VENV)/bin/pip-sync --no-index -f '$(PY_WHL)' '$(PY_REQ)'
     59 	ln -sf 'virtualenvs/$(PYTHON_IMPL)' work/venv
     60 	touch '$@'