-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile.venv
80 lines (65 loc) · 1.41 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
VENV_NAME=venv
VENV=$(VENV_NAME)/bin
ACTIVATE_FILE=$(VENV)/activate
PYTHON=$(VENV)/python3
#
# Interactive shells
#
.PHONY: python
python: venv
exec $(VENV)/python
.PHONY: ipython
ipython: $(VENV)/ipython
exec $(VENV)/ipython
.PHONY: shell
shell: venv
. $(VENV)/activate && exec $(notdir $(SHELL))
.PHONY: bash zsh
bash zsh: venv
. $(VENV)/activate && exec $@
#
# Python interpreter detection
#
_PY_AUTODETECT_MSG=Detected Python interpreter: $(PY). Use PY environment variable to override
ifeq (ok,$(shell test -e /dev/null 2>&1 && echo ok))
NULL_STDERR=2>/dev/null
else
NULL_STDERR=2>NUL
endif
ifndef PY
_PY_OPTION:=python3
ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
PY=$(_PY_OPTION)
endif
endif
ifndef PY
_PY_OPTION:=$(VENVDIR)/bin/python
ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
PY=$(_PY_OPTION)
$(info $(_PY_AUTODETECT_MSG))
endif
endif
ifndef PY
_PY_OPTION:=python
ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
PY=$(_PY_OPTION)
$(info $(_PY_AUTODETECT_MSG))
endif
endif
ifndef PY
define _PY_AUTODETECT_ERR
Could not detect Python interpreter automatically.
Please specify path to interpreter via PY environment variable.
endef
$(error $(_PY_AUTODETECT_ERR))
endif
#
# Virtual environment
#
.PHONY: venv
venv:
$(PY) -m venv $(VENV_NAME)
$(VENV)/python -m pip install --upgrade pip setuptools wheel
.PHONY: venv-clean
venv-clean:
rm -fr $(VENV_NAME)