-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
295 lines (235 loc) · 10.3 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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# Makefile for Planttracer web application
# - Creates CI/CD environment in GitHub
# - Manages deployemnt to AWS Linux
# - Updated to handle virtual environment
# - Simple CRUD management of local database instance for developers
PYLINT_THRESHOLD=9.5
TS_FILES := $(wildcard *.ts */*.ts)
JS_FILES := $(TS_FILES:.ts=.js)
################################################################
# Create the virtual enviornment for testing and CI/CD
REQ = venv/pyvenv.cfg
PYTHON=venv/bin/python
PIP_INSTALL=venv/bin/pip install --no-warn-script-location
ROOT_ETC=etc
DEPLOY_ETC=deploy/etc
APP_ETC=$(DEPLOY_ETC)
DBMAINT=dbutil.py
# Note: PLANTTRACER_CREDENTIALS must be set
venv:
@echo install venv for the development environment
python3 -m venv venv
$(PYTHON) -m pip install --upgrade pip
if [ -r requirements.txt ]; then $(PIP_INSTALL) -r requirements.txt ; fi
if [ -r deploy/requirements.txt ]; then $(PIP_INSTALL) -r deploy/requirements.txt ; fi
if [ -r tests/requirements.txt ]; then $(PIP_INSTALL) -r tests/requirements.txt ; fi
if [ -r docs/requirements.txt ]; then $(PIP_INSTALL) -r docs/requirements.txt ; fi
$(REQ):
make venv
.PHONY: venv
################################################################
# SAM Commands
sam-deploy:
sam validate
DOCKER_DEFAULT_PLATFORM=linux/arm64 sam build
sam deploy --no-confirm-changeset
sam logs --tail
################################################################
#
# By default, PYLINT generates an error if your code does not rank 10.0.
# This makes us tolerant of minor problems.
all:
@echo verify syntax and then restart
make pylint
check:
make pylint
make pytest
################################################################
## Program testing
##
## Static Analysis
PYLINT_OPTS:=--output-format=parseable --rcfile .pylintrc --fail-under=$(PYLINT_THRESHOLD) --verbose
pylint: $(REQ)
$(PYTHON) -m pylint $(PYLINT_OPTS) deploy
$(PYTHON) -m pylint $(PYLINT_OPTS) *.py
pylint-tests: $(REQ)
$(PYTHON) -m pylint $(PYLINT_OPTS) --init-hook="import sys;sys.path.append('tests');import conftest" tests
mypy:
mypy --show-error-codes --pretty --ignore-missing-imports --strict .
black:
black --line-length 127 .
black-check:
black --line-length 127 . --check
@echo "If this fails, simply run: make black"
isort:
isort . --profile=black
isort-check:
isort --check . --profile=black
flake:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=55 --max-line-length=127 --statistics --ignore F403,F405,E203,E231,E252,W503
################################################################
##
## Dynamic Analysis
## If you are testing just one thing, put it here!
#
# In the tests below, we always test the database connectivity first
# It makes no sense to run the tests otherwise
# Set these during development to speed testing of the one function you care about:
TEST1MODULE=tests/movie_tracker_test.py
TEST1FUNCTION="-k test_movie_tracking"
pytest1:
if [ -z "$${PLANTTRACER_CREDENTIALS}" ]; then echo PLANTTRACER_CREDENTIALS is not set; exit 1; fi
$(PYTHON) -m pytest --log-cli-level=DEBUG tests/dbreader_test.py
@echo dbreader_test is successful
$(PYTHON) -m pytest -v --log-cli-level=DEBUG --maxfail=1 $(TEST1MODULE) $(TEST1FUNCTION)
pytest: $(REQ)
if [ -z "$${PLANTTRACER_CREDENTIALS}" ]; then echo PLANTTRACER_CREDENTIALS is not set; exit 1; fi
$(PYTHON) -m pytest --log-cli-level=DEBUG tests/dbreader_test.py
@echo dbreader_test is successful
$(PYTHON) -m pytest -v --log-cli-level=INFO .
pytest-selenium:
if [ -z "$${PLANTTRACER_CREDENTIALS}" ]; then echo PLANTTRACER_CREDENTIALS is not set; exit 1; fi
$(PYTHON) -m pytest -v --log-cli-level=INFO tests/sitetitle_test.py
pytest-debug:
if [ -z "$${PLANTTRACER_CREDENTIALS}" ]; then echo PLANTTRACER_CREDENTIALS is not set; exit 1; fi
$(PYTHON) -m pytest --log-cli-level=DEBUG tests/dbreader_test.py
@echo dbreader_test is successful
$(PYTHON) -m pytest -v --log-cli-level=DEBUG
pytest-app-framework:
if [ -z "$${PLANTTRACER_CREDENTIALS}" ]; then echo PLANTTRACER_CREDENTIALS is not set; exit 1; fi
@echo validate app framework
$(PYTHON) -m pytest -x --log-cli-level=DEBUG tests/app_test.py -k test_templates
pytest-quiet:
if [ -z "$${PLANTTRACER_CREDENTIALS}" ]; then echo PLANTTRACER_CREDENTIALS is not set; exit 1; fi
@echo quietly make pytest and stop at the firt error
$(PYTHON) -m pytest --log-cli-level=ERROR tests/dbreader_test.py
@echo dbreader_test is successful
$(PYTHON) -m pytest --log-cli-level=ERROR
test-schema-upgrade:
$(PYTHON) $(DBMAINT) --rootconfig $(ROOT_ETC)/mysql-root-localhost.ini --dropdb test_db1 || echo database does not exist
$(PYTHON) $(DBMAINT) --rootconfig $(ROOT_ETC)/mysql-root-localhost.ini --createdb test_db1 --schema $(ROOT_ETC)/schema_0.sql
$(PYTHON) $(DBMAINT) --rootconfig $(ROOT_ETC)/mysql-root-localhost.ini --upgradedb test_db1
$(PYTHON) $(DBMAINT) --rootconfig $(ROOT_ETC)/mysql-root-localhost.ini --dropdb test_db1
pytest-coverage: $(REQ)
$(PIP_INSTALL) codecov pytest pytest_cov
$(PYTHON) -m pytest -v --cov=. --cov-report=xml tests
################################################################
### Debug targets run running locally
run-local:
@echo run bottle locally, storing new data in database
$(PYTHON) standalone.py --storelocal
run-local-demo:
@echo run bottle locally in demo mode, using local database
DEMO_MODE=1 $(PYTHON) standalone.py --storelocal
DEBUG:=$(PYTHON) standalone.py --loglevel DEBUG
debug:
make debug-local
debug-local:
@echo run bottle locally in debug mode, storing new data in database
PLANTTRACER_CREDENTIALS=$(APP_ETC)/credentials-localhost.ini $(DEBUG) --storelocal
debug-single:
@echo run bottle locally in debug mode single-threaded
PLANTTRACER_CREDENTIALS=$(APP_ETC)/credentials-localhost.ini $(DEBUG)
debug-multi:
@echo run bottle locally in debug mode multi-threaded
PLANTTRACER_CREDENTIALS=$(APP_ETC)/credentials-localhost.ini $(DEBUG) --multi
debug-dev:
@echo run bottle locally in debug mode, storing new data in S3, with the dev.planttracer.com database
@echo for debugging Python and Javascript with remote database
PLANTTRACER_CREDENTIALS=$(APP_ETC)/credentials-aws-dev.ini $(DEBUG)
debug-dev-api:
@echo Debug local JavaScript with remote server.
@echo run bottle locally in debug mode, storing new data in S3, with the dev.planttracer.com database and API calls
PLANTTRACER_CREDENTIALS=$(APP_ETC)/credentials-aws-dev.ini PLANTTRACER_API_BASE=https://dev.planttracer.com/ $(DEBUG)
tracker-debug:
/bin/rm -f outfile.mp4
$(PYTHON) tracker.py --moviefile="tests/data/2019-07-12 circumnutation.mp4" --outfile=outfile.mp4
open outfile.mp4
################################################################
### JavaScript
eslint:
if [ ! -d deploy/app/static ]; then echo no deploy/app/static ; exit 1 ; fi
(cd deploy/app/static;make eslint)
if [ ! -d deploy/app/templates ]; then echo no deploy/app/templates ; exit 1 ; fi
(cd deploy/app/templates;make eslint)
jscoverage:
NODE_PATH=deploy/app/static npm run coverage
NODE_PATH=deploy/app/static npm test
################################################################
# Installations are used by the CI pipeline and by developers
# $(REQ) gets made by the virtual environment installer, but you need to have python installed first.
PLANTTRACER_LOCALDB_NAME ?= actions_test
create_localdb:
@echo Creating local database, exercise the upgrade code and write credentials
@echo to $(PLANTTRACER_CREDENTIALS) using $(ROOT_ETC)/github_actions_mysql_rootconfig.ini
@echo $(PLANTTRACER_CREDENTIALS) will be used automatically by other tests
pwd
mkdir -p $(ROOT_ETC)
ls -l $(ROOT_ETC)
$(PYTHON) $(DBMAINT) --create_client=$$MYSQL_ROOT_PASSWORD --writeconfig $(ROOT_ETC)/github_actions_mysql_rootconfig.ini
ls -l $(ROOT_ETC)
$(PYTHON) $(DBMAINT) --rootconfig $(ROOT_ETC)/github_actions_mysql_rootconfig.ini \
--createdb $(PLANTTRACER_LOCALDB_NAME) \
--schema $(DEPLOY_ETC)/schema_0.sql \
--writeconfig $(PLANTTRACER_CREDENTIALS)
$(PYTHON) $(DBMAINT) --upgradedb --loglevel DEBUG
$(PYTHON) -m pytest -x --log-cli-level=DEBUG tests/dbreader_test.py
remove_localdb:
@echo Removing local database using $(ROOT_ETC)/github_actions_mysql_rootconfig.ini
$(PYTHON) $(DBMAINT) --rootconfig $(ROOT_ETC)/github_actions_mysql_rootconfig.ini --dropdb $(PLANTTRACER_LOCALDB_NAME)
install-chromium-browser-ubuntu: $(REQ)
sudo apt-get install -y chromium-browser
chromium --version
install-chromium-browser-macos: $(REQ)
brew install chromium --no-quarantine
# Includes ubuntu dependencies
install-ubuntu: $(REQ)
echo on GitHub, we use this action instead: https://github.com/marketplace/actions/setup-ffmpeg
which ffmpeg || sudo apt install ffmpeg
which node || sudo apt-get install nodejs
which npm || sudo apt-get install npm
npm ci
if [ -r requirements-ubuntu.txt ]; then $(PIP_INSTALL) -r requirements-ubuntu.txt ; fi
# Install for AWS Linux for running SAM
# Start with:
# sudo dfn install git && git clone --recursive https://github.com/Plant-Tracer/webapp && (cd webapp; make aws-install)
install-aws:
echo install for AWS Linux, for making the lambda.
echo note does not install ffmpeg currently
(cd $HOME; \
wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip; \
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation; \
sudo ./sam-installation/install )
sudo dnf install -y docker
sudo systemctl enable docker
sudo systemctl start docker
sudo dnf install -y python3.11
sudo dnf install -y nodejs npm
npm ci
make $(REQ)
if [ -r requirements-aws.txt ]; then $(PIP_INSTALL) -r requirements-ubuntu.txt ; fi
# Includes MacOS dependencies managed through Brew
install-macos:
brew update
brew upgrade
brew install python3
brew install ffmpeg
brew install node
brew install npm
npm ci
npm install -g typescript webpack webpack-cli
make $(REQ)
if [ -r requirements-macos.txt ]; then $(PIP_INSTALL) -r requirements-macos.txt ; fi
# Includes Windows dependencies
install-windows: $(REQ)
if [ -r requirements-windows.txt ]; then $(PIP_INSTALL) -r requirements-windows.txt ; fi
################################################################
### Cleanup
clean:
find . -name '*~' -exec rm {} \;
/bin/rm -rf __pycache__ */__pycache__
################################################################
### Compile JavaScript to TypeScript
%.js: %.ts
tsc $<