-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
117 lines (105 loc) · 3.32 KB
/
Makefile
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# The help comments are based on https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
# Color Definitions
C_RED := \033[31m
C_GREEN := \033[32m
C_YELLOW := \033[33m
C_BLUE := \033[34m
C_MAGENTA := \033[35m
C_CYAN := \033[36m
C_WHITE := \033[37m
T_RESET := \033[0m
T_BOLD := \033[1m
# Helpful Icons
T_OK_ICON := [${T_BOLD}${C_GREEN}✓${T_RESET}]
T_ERR_ICON := [${T_BOLD}${C_RED}✗${T_RESET}]
T_INFO_ICON := [${T_BOLD}${C_YELLOW}i${T_RESET}]
# run commands in a single shell, otherwise venv may not work
.ONESHELL:
# set some environment variables
CURRENT_PYTHON = which python3
VENV := $(notdir $(CURDIR)).venv
VENV_PYTHON := $(VENV)/bin/python
QUIET_PIP := pip -q --exists-action i
.DEFAULT_GOAL := help
.PHONY: help env show-env clean
define check_venv
printf "$(C_BLUE)$(VENV)$(T_RESET)"
if [ -d "$(VENV)" ]; then \
printf " exists $(T_OK_ICON)\n"; \
if [ -f "$(VENV)/bin/activate" ]; then \
printf "$(C_BLUE)$(VENV)$(T_RESET) activate exists $(T_OK_ICON)\n"; \
else \
printf "$(C_BLUE)$(VENV)$(T_RESET) activate NOT found $(T_ERR_ICON)\n"; \
printf "Maybe run:\n make clean && make dev-env\n\n" ; \
exit 1;\
fi;
else
printf " does not exist $(T_ERR_ICON)\n"; \
printf " \n$(T_INFO_ICON) Have you run?\n make dev-env\n\n"; \
exit 1; \
fi
endef
help: ##@ show help contents
@printf "$(C_BLUE)%-12s$(T_RESET) %s\n" "Target" "Description"
@printf "%-12s %s\n" "------" "-----------"
@grep -E '^[a-zA-Z_-]+:.*?##@ .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?##@ "}; {printf "\033[34m%-12s\033[0m %s\n", $$1, $$2}'
env: ##@ setup a virtual environment
@printf "Setting up a $(C_YELLOW)Virtual Environment$(T_RESET) in $(C_BLUE)$(VENV)$(T_RESET)\n"
@(
if [ -d "$(VENV)" ]; then \
printf "$(C_BLUE)$(VENV)$(T_RESET) exists, skipping $(T_OK_ICON)\n"; \
else \
printf "Creating $(C_BLUE)$(VENV)$(T_RESET) "; \
python3 -m venv $(VENV); \
if [ $$? -ne 0 ]; then \
printf "$(T_ERR_ICON) FAILED\n"; \
exit 1; \
else \
printf "$(T_OK_ICON)\n"; \
fi; \
echo "*" > $(VENV)/.gitignore ; \
fi
)
@$(call check_venv)
@printf "Activate $(C_BLUE)$(VENV)$(T_RESET) "
@. $(VENV)/bin/activate
if [ $$? -ne 0 ]; then \
printf "$(T_ERR_ICON) FAILED\n"; \
else \
printf "$(T_OK_ICON)\n"; \
fi
@printf "Using python:\n "
@which python
@printf "\nInstall pip "
@$(VENV_PYTHON) -m $(QUIET_PIP) install --upgrade pip
if [ $$? -ne 0 ]; then \
printf "$(T_ERR_ICON) FAILED\n"; \
else \
printf "$(T_OK_ICON)\n"; \
fi
@printf "Install requirements "
@$(QUIET_PIP) install -r requirements.txt
if [ $$? -ne 0 ]; then \
printf "$(T_ERR_ICON) FAILED\n"; \
else \
printf "$(T_OK_ICON)\n"; \
fi
printf "\n$(T_INFO_ICON) To $(C_GREEN)enable$(T_RESET) the virtual environment, type:\n"
printf " source $(VENV)/bin/activate \n\n"
show-env: ##@ Show paths used by python
@(
if [ -d "$(VENV)" ]; then \
$(call check_venv); \
else \
printf "$(T_INFO_ICON) $(C_BLUE)$(VENV)$(T_RESET) Not Found\n"; \
fi
)
@printf "current python:\n "
@which python3
clean: ##@ delete the .venv environment
@(if [ -d "$(VENV)" ]; then \
printf "$(T_OK_ICON) $(C_BLUE)$(VENV)$(T_RESET) Found, $(C_RED)Removing$(T_RESET) Dev Environment\n"
rm -rf "$(VENV)"; \
else \
printf "$(T_INFO_ICON) $(C_BLUE)$(VENV)$(T_RESET) Not Found, nothing to do\n"; \
fi)