forked from 18F/NRC-MAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (180 loc) · 5.02 KB
/
Makefile
File metadata and controls
200 lines (180 loc) · 5.02 KB
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
192
193
194
195
196
197
198
199
200
PROJECT=nrc-map
ifeq ("$(shell uname -s)", "Linux*")
BROWSER=/usr/bin/firefox
else
BROWSER=open
endif
MOUNT_DIR=$(shell pwd)
PKG_MANAGER=pip
PORT:=$(shell awk -v min=16384 -v max=32768 'BEGIN{srand(); print int(min+rand()*(max-min+1))}')
NOTEBOOK_NAME=$(USER)_notebook_$(PORT)
SRC_DIR=/usr/src/nrc_map
USER=$(shell echo $${USER%%@*})
VERSION=$(shell echo $(shell cat nrc_map/__init__.py | \
grep "^__version__" | \
cut -d = -f 2))
.PHONY: docs upgrade-packages
deploy: docker-up
docker container exec $(PROJECT)_python \
pip3 wheel --wheel-dir=wheels .
git tag -a v$(VERSION) -m "Version $(VERSION)"
@echo
@echo
@echo Enter the following to push this tag to the repository:
@echo git push origin v$(VERSION)
docker-down:
docker-compose -f development/docker-compose.yaml down
docker-images-update:
docker image ls | grep -v REPOSITORY | cut -d ' ' -f 1 | xargs -L1 docker pull
docker-rebuild: envfile setup.py
docker-compose -f development/docker-compose.yaml up -d --build
docker-up:
docker-compose -f development/docker-compose.yaml up -d
docs: docker-up
docker container exec $(PROJECT)_python \
/bin/bash -c "pip install -e .[docs] \
&& cd docs \
&& make html"
${BROWSER} http://localhost:8080
docs-init: docker-up
rm -rf docs/*
docker container exec $(PROJECT)_python \
/bin/bash -c \
"cd docs \
&& sphinx-quickstart -q \
-p $(PROJECT) \
-a "EnterAuthorName" \
-v $(VERSION) \
--ext-autodoc \
--ext-viewcode \
--makefile \
--no-batchfile"
docker-compose -f development/docker-compose.yaml restart nginx
ifeq ("$(shell git remote)", "origin")
git fetch
git checkout origin/develop -- docs/
else
docker container run --rm \
-v `pwd`:/usr/src/$(PROJECT) \
-w /usr/src/$(PROJECT)/docs \
ubuntu \
/bin/bash -c \
"sed -i -e 's/# import os/import os/g' conf.py \
&& sed -i -e 's/# import sys/import sys/g' conf.py \
&& sed -i \"/# sys.path.insert(0, os.path.abspath('.'))/d\" \
conf.py \
&& sed -i -e \"/import sys/a \
sys.path.insert(0, os.path.abspath('../nrc_map')) \
\n\nfrom nrc_map import __version__\" \
conf.py \
&& sed -i -e \"s/version = '0.1.0'/version = __version__/g\" \
conf.py \
&& sed -i -e \"s/release = '0.1.0'/release = __version__/g\" \
conf.py \
&& sed -i -e \"s/alabaster/agogo/g\" \
conf.py \
&& sed -i \"/ :caption: Contents:/a \
\\\\\n package\" \
index.rst"
printf "%s\n" \
"Package Modules" \
"===============" \
"" \
".. toctree::" \
" :maxdepth: 2" \
"" \
"cli" \
"---" \
".. automodule:: cli" \
" :members:" \
" :show-inheritance:" \
" :synopsis: Package command line interface calls." \
"" \
"db" \
"--" \
".. automodule:: db" \
" :members:" \
" :show-inheritance:" \
" :synopsis: Package database module." \
"" \
"utils" \
"-----" \
".. automodule:: utils" \
" :members:" \
" :show-inheritance:" \
" :synopsis: Package utilities module." \
"" \
> "docs/package.rst"
endif
docs-view: docker-up
${BROWSER} http://localhost:8080
ipython: docker-up
docker container exec -it $(PROJECT)_python ipython
notebook: docker-up notebook-server
sleep 3
${BROWSER} $$(docker container exec \
$(USER)_notebook_$(PORT) \
jupyter notebook list | grep -o '^http\S*')
notebook-remove:
docker container rm -f $$(docker container ls -f name=$(USER)_notebook -q)
notebook-server:
docker container run -d --rm \
--name $(NOTEBOOK_NAME) \
-p $(PORT):$(PORT) \
-v `pwd`:/usr/src/$(PROJECT) \
$(PROJECT)_python \
/bin/bash -c "jupyter lab \
--allow-root \
--ip=0.0.0.0 \
--no-browser \
--port=$(PORT)"
docker network connect $(PROJECT) $(NOTEBOOK_NAME)
snakeviz: docker-up snakeviz-server
sleep 0.5
${BROWSER} http://0.0.0.0:$(PORT)/snakeviz/
snakeviz-remove:
docker container rm -f $$(docker container ls -f name=snakeviz -q)
snakeviz-server: docker-up
docker container run -d --rm \
--name snakeviz_$(PORT) \
-p $(PORT):$(PORT) \
-w /usr/src/$(PROJECT)/profiles \
-v `pwd`:/usr/src/$(PROJECT) \
$(PROJECT)_python \
/bin/bash -c \
"snakeviz profile.prof \
--hostname 0.0.0.0 \
--port $(PORT) \
--server"
docker network connect $(PROJECT) snakeviz_$(PORT)
tests: docker-up
docker container exec $(PROJECT)_python \
/bin/bash -c \
"pytest \
--basetemp=pytest \
--cov=. \
--cov-report html \
--ff \
-r all \
-vvv"
tests-coverage: tests
${BROWSER} htmlcov/index.html
upgrade-packages: docker-up
ifeq ("${PKG_MANAGER}", "pip")
docker container exec $(PROJECT)_python \
/bin/bash -c \
"pip3 install -U pip \
&& pip3 freeze | \
grep -v NRC-MAP | \
cut -d = -f 1 > requirements.txt \
&& pip3 install -U -r requirements.txt \
&& pip3 freeze > requirements.txt \
&& sed -i -e '/^-e/d' requirements.txt"
else ifeq ("${PKG_MANAGER}", "conda")
docker container exec $(PROJECT)_python \
/bin/bash -c \
"conda update conda \
&& conda update --all \
&& pip freeze > requirements.txt \
&& sed -i -e '/^-e/d' requirements.txt"
endif