-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
165 lines (133 loc) · 4.4 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
# SYSTEM DEPENENDENCIES #######################################################
.PHONY: bootstrap
bootstrap: ## Attempt to install system dependencies
asdf plugin add python || asdf plugin update python
asdf plugin add poetry || asdf plugin update poetry
asdf install
.PHONY: doctor
doctor: ## System | Check for the required system dependencies
bin/verchew --exit-code
.PHONY: .envrc
.envrc:
echo "export PORT=8000" >> $@
echo "export PYTHONBREAKPOINT=ipdb.set_trace" >> $@
echo >> $@
echo "export REDIS_URL=redis://localhost:6379" >> $@
# PROJECT DEPENDENCIES ########################################################
.PHONY: install
install: .venv/flag ## Project | Install project dependencies
.venv/flag: poetry.lock
@ rm -rf ~/Library/Preferences/pypoetry
@ poetry config virtualenvs.in-project true
poetry install
@ mkdir -p staticfiles
@ touch $@
ifndef CI
poetry.lock: pyproject.toml
poetry lock --no-update
@ touch $@
endif
.PHONY: clean
clean:
rm -rf .venv
# LOCAL COMMANDS ##############################################################
.PHONY: run
run: install migrate ## Project | Run the development server
@ echo
poetry run python manage.py runserver $(PORT)
.PHONY: shell
shell: install migrate ## Project | Open the Django shell
@ echo
poetry run python manage.py shell_plus
# VALIDATION COMMANDS #########################################################
PACKAGES := config elections tests
.PHONY: all
all: check test ## CI | Run all validation targets
.PHONY: format
format: install ## CI | Format the code
poetry run isort $(PACKAGES)
poetry run black $(PACKAGES)
.PHONY: check
check: format ## CI | Run static analysis
@ echo
ifdef CI
git diff --exit-code
endif
poetry run mypy $(PACKAGES)
poetry run pylint $(PACKAGES) --rcfile=.pylint.ini
.PHONY: test
test: install ## CI | Run all tests
poetry run pytest elections tests
poetry run coveragespace update overall --exit-code
ifdef COVERALLS_REPO_TOKEN
poetry run coveralls
endif
.PHONY: dev
dev: install
@ rm -f .cache/v/cache/lastfailed
poetry run ptw
.PHONY: notebook
notebook: install
poetry run jupyter notebook --notebook-dir=notebooks --browser=safari
# DATA COMMANDS ###############################################################
.PHONY: migrations
migrations: install ## Data | Generate database migrations
poetry run python manage.py makemigrations
.PHONY: migrate
migrate: install ## Data | Run database migrations
ifndef DATABASE_URL
poetry run python manage.py migrate
@ echo
poetry run python manage.py migrate_data
endif
.PHONY: data
data: migrate ## Data | Seed data for manual testing
@ echo
poetry run python manage.py seed_data
@ echo
poetry run python manage.py scrape_data --ballot-limit=3
@ echo
poetry run python manage.py parse_data
.PHONY: data/crawl
data/crawl: install ## Data | Run crawler to scrape and parse all ballots
@ echo
poetry run python manage.py scrape_data
@ echo
poetry run python manage.py parse_data
.PHONY: data/reset
data/reset: install ## Data | Create a new database, migrate, and seed it
- dropdb elections_dev
createdb elections_dev
@ echo
@ make data
.PHONY: data/production
data/production: install ## Data | Pull data as it exists on production
- dropdb elections_dev
heroku pg:pull DATABASE_URL elections_dev
psql elections_dev -c 'TRUNCATE auth_user CASCADE'
poetry run python manage.py seed_data
.PHONY: uml
uml: install
poetry install --extras uml
@ echo
poetry run pyreverse elections -p elections -a 1 -f ALL -o png --ignore admin.py,migrations,management,tests
mv -f classes_elections.png docs/classes.png
mv -f packages_elections.png docs/packages.png
poetry run python manage.py graph_models elections --output=docs/tables.png --exclude-models=TimeStampedModel
# DELIVERY TASKS ##############################################################
.PHONY: promote
promote: install
@ echo
SITE=https://staging.michiganelections.io poetry run pytest tests/test_deployment.py --verbose --no-cov
@ echo
heroku pipelines:promote --app mi-elections-staging --to mi-elections
@ echo
SITE=https://michiganelections.io poetry run pytest tests/test_deployment.py --verbose --no-cov
.PHONY: crawl
crawl:
heroku run bin/crawl
# HELP ########################################################################
.PHONY: help
help: install
@ grep -E '^[a-zA-Z/_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help