forked from mintel/build-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.venv
35 lines (29 loc) · 1.54 KB
/
Makefile.venv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
BUILD_HARNESS_REQ_TEMPLATE:=$(BUILD_HARNESS_PATH)/requirements.template
BUILD_HARNESS_REQ_NAME:=.build-harness.requirements.txt
BUILD_HARNESS_REQ:=$(CURDIR)/$(BUILD_HARNESS_REQ_NAME)
BUILD_HARNESS_VENV_NAME:=.build-harness.venv
BUILD_HARNESS_VENV:=$(CURDIR)/$(BUILD_HARNESS_VENV_NAME)
WITH_BH_VENV=$(shell test -f $(BUILD_HARNESS_REQ) && echo "source $(BUILD_HARNESS_VENV)/bin/activate 2>/dev/null &&")
define which
$(shell $(WITH_BH_VENV) which $1 2>/dev/null)
endef
.PHONY: bh/venv/debug
bh/venv/debug:
$(call print-var,VENV_MODULE)
$(call print-var,BUMPVERSION)
$(call print-var,BLACK)
$(call print-var,ISORT)
.PHONY: bh/venv
bh/venv: $(BUILD_HARNESS_VENV)
$(BUILD_HARNESS_REQ_TEMPLATE):
@echo "[build-harness] MISSING: $@"
$(BUILD_HARNESS_REQ): $(BUILD_HARNESS_REQ_TEMPLATE)
@if [ -f $@ ]; then echo "Removing previously generated build-harness requirements" && rm $@; fi
@cat $(BUILD_HARNESS_REQ_TEMPLATE) | xargs -I % bash -c 'if [ -z "$$(which % 2>/dev/null)" ]; then echo "% not found" && echo "%" >> $@; fi'
$(BUILD_HARNESS_VENV): $(BUILD_HARNESS_REQ)
@if [ -s $(BUILD_HARNESS_REQ) ]; then echo "Installing: $$(cat $(BUILD_HARNESS_REQ) | tr '\n' ' ')"; fi
@test -f $(BUILD_HARNESS_REQ) \
&& ( \
$(shell if [ $$(python -c 'import platform; ver=int(platform.python_version()[0]); print(ver)' 2>/dev/null) -eq 2 ] && [ -n "$$(which python3 2>/dev/null)" ]; then echo "python3"; else echo "python"; fi) -m venv $@ \
&& source $@/bin/activate && pip install -r $(BUILD_HARNESS_REQ) --ignore-installed \
); if [ $$? -ne 0 ]; then rm -rf $@; fi