-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.makefile
191 lines (171 loc) · 5.52 KB
/
common.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# # USER OPTIONS
# PYTHON2_VERSION=system
# PYTHON2_VIRTUAL_ENV:=
# PYPI2_PACKAGE:=
# PYTHON3_VERSION:=
# PYTHON3_VIRTUAL_ENV:=
# PYPI3_PACKAGE:=
# USE_PROXY=false
# PROXY_SERVER :=
# PORT :=
# MAKE_SOURCE_DIR:=
# Variable definitions
SHELL:=/bin/bash
SUDO:=sudo -E
YES:=-y --allow-unauthenticated
APT:=apt-get
# Public targets
help: ## Show this help
@for f in $(MAKEFILE_LIST); do \
grep -E '^[a-zA-Z_-]+:.*?## .*$$' $$f | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}';\
done
SETUP-DEPS=
# Python2
ifeq ($(PYTHON2_VIRTUAL_ENV),)
else
SETUP-DEPS += $(PYENV_ROOT)/versions/$(PYTHON2_VIRTUAL_ENV)/
endif
ifeq ($(PYPI2_PACKAGE),)
else
SETUP-DEPS += python2-packages
endif
# Python3
ifeq ($(PYTHON3_VIRTUAL_ENV),)
else
SETUP-DEPS += $(PYENV_ROOT)/versions/$(PYTHON3_VIRTUAL_ENV)/
endif
ifeq ($(PYPI3_PACKAGE),)
else
SETUP-DEPS += python3-packages
endif
SETUP-DEPS += /usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf # For Japanese characters in matplotlib
SETUP-DEPS += notebooks
${PYENV_ROOT}/versions/$(PYTHON2_VIRTUAL_ENV)/:
-@echo "checking $@";\
if [ -d $@ ]; then \
echo "OK"; \
else \
# export http_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
# export https_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
if [ -n $(PYTHON2_VERSION) ]; then \
CONFIGURE_OPTS="--enable-shared" pyenv install $(PYTHON2_VERSION) -v;\
fi; \
if [ -n $(PYTHON2_VIRTUAL_ENV) ]; then \
pyenv virtualenv $(PYTHON2_VERSION) $(PYTHON2_VIRTUAL_ENV);\
echo "Python $(PYTHON2_VIRTUAL_ENV) was successfully installed!";\
fi; \
fi
${PYENV_ROOT}/versions/$(PYTHON3_VIRTUAL_ENV)/:
-@echo "checking $@";\
if [ -d $@ ]; then \
echo "OK"; \
else \
# export http_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
# export https_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
if [ -n $(PYTHON3_VERSION) ]; then \
CONFIGURE_OPTS="--enable-shared" pyenv install $(PYTHON3_VERSION) -v;\
fi; \
if [ -n $(PYTHON3_VIRTUAL_ENV) ]; then \
pyenv virtualenv $(PYTHON3_VERSION) $(PYTHON3_VIRTUAL_ENV);\
echo "Python $(PYTHON3_VIRTUAL_ENV) was successfully installed!";\
fi; \
fi
setup: $(SETUP-DEPS) ## Setup project
start-jupyterlab: notebooks ## Start jupyter-lab
export MAKE_SOURCE_DIR=$(shell cd $(MAKE_SOURCE_DIR); pwd); \
cd $(MAKE_SOURCE_DIR)/notebooks && jupyter lab --no-browser
start-notebook: notebooks ## Start jupyter notebook
export MAKE_SOURCE_DIR=$(shell cd $(MAKE_SOURCE_DIR); pwd); \
cd $(MAKE_SOURCE_DIR)/notebooks && jupyter notebook --no-browser
start-ipython: ## Start ipython
export MAKE_SOURCE_DIR=$(shell cd $(MAKE_SOURCE_DIR); pwd); \
cd $(MAKE_SOURCE_DIR) && ipython
debug: PROXY-SETTING
@echo "---------------------------"
@echo \# Common parameters
@echo MAKE_SOURCE_DIR: $(MAKE_SOURCE_DIR)
@echo
@echo \# Proxy variables
@echo USE_PROXY: $(USE_PROXY)
@echo USER_ID: $(USER_ID)
@echo USER_PASS: $(USER_PASS)
@echo PROXY_URL: $(PROXY_URL)
@echo
@echo \# pyenv
@echo PYENV_ROOT: ${PYENV_ROOT}
@echo
@echo \# Python environments
@echo PYTHON2_VERSION: $(PYTHON2_VERSION)
@echo PYTHON2_VIRTUAL_ENV: $(PYTHON2_VIRTUAL_ENV)
@echo PYTHON3_VERSION: $(PYTHON3_VERSION)
@echo PYTHON3_VIRTUAL_ENV: $(PYTHON3_VIRTUAL_ENV)
@echo
@echo \# PYPI2_PACKAGE:
@for p in $(PYPI2_PACKAGE); do \
echo " - $$p";\
done
@echo
@echo \# PYPI3_PACKAGE:
@for p in $(PYPI3_PACKAGE); do \
echo " - $$p";\
done
@echo
@echo \# SETUP-DEPS:
@for p in $(SETUP-DEPS); do \
echo " - $$p";\
done
# for developper
# Install python packages
python2-packages: ${PYENV_ROOT}/versions/$(PYTHON2_VIRTUAL_ENV)/ PROXY-SETTING
@echo "Installing Python2 packages...";\
if $(USE_PROXY); then \
echo "Using proxy: $(PROXY_URL)"; \
export http_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
export https_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
fi; \
if [ $(PYTHON2_VERSION) != "system" ]; then \
if [ -n $(PYTHON2_VIRTUAL_ENV) ]; then \
source ${PYENV_ROOT}/versions/$(PYTHON2_VIRTUAL_ENV)/bin/activate; \
fi; \
fi; \
for p in $(PYPI2_PACKAGE); do \
echo " - $$p";\
done; \
for p in $(PYPI2_PACKAGE); do \
echo $$p;\
pyenv exec pip install $$p;\
done
python3-packages: ${PYENV_ROOT}/versions/$(PYTHON3_VIRTUAL_ENV)/ PROXY-SETTING
@echo "$(MAKE_SOURCE_DIR)/notebooks"
echo "Install Python3 packages...";\
if $(USE_PROXY); then \
export http_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
export https_proxy=http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); \
fi; \
if [ $(PYTHON3_VERSION) != "system" ]; then \
if [ -n $(PYTHON3_VIRTUAL_ENV) ]; then \
source ${PYENV_ROOT}/versions/$(PYTHON3_VIRTUAL_ENV)/bin/activate; \
fi; \
fi; \
for p in $(PYPI3_PACKAGE); do \
echo " - $$p";\
done; \
for p in $(PYPI3_PACKAGE); do \
echo $$p;\
pyenv exec pip install $$p;\
done
/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf:
$(SUDO) $(APT) install fonts-takao-gothic $(YES)
notebooks:
cd $(MAKE_SOURCE_DIR); \
mkdir -p notebooks; \
cd notebooks; \
if [ -n $(PYTHON3_VIRTUAL_ENV) ]; then \
pyenv local $(PYTHON3_VIRTUAL_ENV); \
fi;
.PHONY: help python2-packages python3-packages PROXY-SETTING
PROXY-SETTING:
$(eval USER_ID = $(shell if $(USE_PROXY); then read -p "LOGIN ID: " USER_ID; fi; echo "$${USER_ID}"))
$(eval USER_PASS := $(shell if $(USE_PROXY); then read -s -p "LOGIN PASS: " USER_PASS; fi; echo "$${USER_PASS}"))
$(eval PROXY_URL := $(shell if $(USE_PROXY); then echo http://$(USER_ID):$(USER_PASS)@$(PROXY_SERVER):$(PORT); else echo ""; fi))
@echo ""