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