-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
105 lines (94 loc) · 3.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
# Ancient Makefile implicit rule disabler
(%): %
%:: %,v
%:: RCS/%,v
%:: s.%
%:: SCCS/s.%
%.out: %
%.c: %.w %.ch
%.tex: %.w %.ch
%.mk:
# Variables
DOC_DIR := docs
SRC_DIR := src/vtp/web/api
TEST_DIR := tests
BUILD_FILES := pyproject.toml poetry.lock
HOST := 127.0.0.1
PORT := 8000
# for uvicorn console logging: [critical|error|warning|info|debug|trace]
VERBOSITY :=
# when set to non nil, will merge the ballots as they are cast, but this
# ONLY works when sequentially casting ballots in demo/test mode
MERGE_CONTESTS :=
# Use colors for errors and warnings when in an interactive terminal
INTERACTIVE := $(shell test -t 0 && echo 1)
ifdef INTERACTIVE
RED := \033[0;31m
END := \033[0m
else
RED :=
END :=
endif
ifdef VERBOSITY
LOG_LEVEL := --log-level ${VERBOSITY}
else
LOG_LEVEL :=
endif
# Let there be no default target
.PHONY: help
help:
@echo "${RED}There is no default make target.${END} Specify one of:"
@echo "pylint - runs pylint"
@echo "pytest - runs pytest"
@echo "poetry-build - performs a poetry local install"
@echo "poetry-list-latest - will show which poetry packages have updates"
@echo "requirements.txt - updates the python requirements file"
@echo "etags - constructs an emacs tags table"
@echo "conjoin - conjoins the VoteTrackerPlus repos via"
@echo " symlinks"
@echo "run - will run the uvicorn web-api server (main:app) with"
@echo " host='${HOST}' for localhost operation only. Set"
@echo " HOST=0.0.0.0 for LAN operation - ${RED}REQUIRES A FIREWALL${END}"
@echo " ${RED}FOR SECURITY${END}. See https://www.uvicorn.org/settings"
@echo " for more info."
@echo ""
@echo "See ${BUILD_DIR}/README.md for more details and info"
# Run pylint
.PHONY: pylint
pylint:
@echo "${RED}NOTE - isort and black disagree on 3 files${END} - let black win"
isort ${SRC_DIR} ${TEST_DIR}
black ${SRC_DIR} ${TEST_DIR}
pylint --recursive y ${SRC_DIR} ${TEST_DIR}
.PHONY: poetry-build poetry-list-latest
poetry-build:
poetry shell && poetry install
poetry-list-latest:
poetry show -o
# Generate a requirements.txt for dependabot (ignoring the symlinks)
requirements.txt: ${BUILD_FILES}
poetry export --with dev -f requirements.txt --output requirements.txt
.PHONY: run
run:
@/bin/echo -n "Local IP = "
@ifconfig | awk '/inet /&&!/127.0.0.1/{print $$2}'
@/bin/echo -n "Public IP = "
@dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"'
cd src/vtp/web/api && MERGE_CONTESTS=${MERGE_CONTESTS} uvicorn main:app --host ${HOST} --port ${PORT} ${LOG_LEVEL} --reload-dir ../../../../../VTP-web-client/static --reload-dir . --reload-include "*.py" --reload-include "*.js"
# Connect this repo to the VoteTrackerPlus repo assuming normal layout.
# This allows this repo to run without a VoteTrackerPlus install proper
# and to run out of the connected git repo directly.
.PHONY: conjoin
conjoin:
ln -s ../../../VoteTrackerPlus/src/vtp/core src/vtp/core
ln -s ../../../VoteTrackerPlus/src/vtp/ops src/vtp/ops
ln -s ../../../../../VTP-web-client/static src/vtp/web/api/static
# Run tests
.PHONY: pytest
pytest:
pytest ${TEST_DIR}
# emacs tags
ETAG_SRCS := $(shell find * -type f -name '*.py' -o -name '*.md' | grep -v defunct)
.PHONY: etags
etags: ${ETAG_SRCS}
etags ${ETAG_SRCS}