-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
215 lines (157 loc) · 6.69 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
RUN = poetry -C backend run
VERSION = $(shell poetry -C backend version -s)
ROOTDIR = $(shell pwd)
SCHEMADIR = $(ROOTDIR)/backend/src/monarch_py/datamodels
### Help ###
.PHONY: help
help:
@echo "╭───────────────────────────────────────────────────────────╮"
@echo "│ Makefile for Monarch API │"
@echo "│ ──────────────────────── │"
@echo "│ Usage: │"
@echo "│ make <target> │"
@echo "│ │"
@echo "│ Targets: │"
@echo "│ help Print this help message │"
@echo "│ all Install everything │"
@echo "│ fresh Clean and install everything │"
@echo "│ clean Clean up build artifacts │"
@echo "│ clobber Clean up generated files │"
@echo "│ │"
@echo "│ docs Generate documentation │"
@echo "│ model Generate model files │"
@echo "| fixtures Generate data fixtures │"
@echo "| data Generate data files │"
@echo "| category-enums Generate category enums │"
@echo "│ │"
@echo "│ install Install backend and frontend │"
@echo "│ install-backend Install backend │"
@echo "│ install-frontend Install frontend │"
@echo "│ │"
@echo "│ test Run all tests │"
@echo "│ test-backend Run backend tests │"
@echo "│ test-frontend Run frontend tests │"
@echo "│ │"
@echo "│ dev-frontend Run frontend in development mode │"
@echo "│ dev-api Run api in development mode │"
@echo "│ │"
@echo "│ docker-build Build docker image │"
@echo "│ docker-push Push docker image │"
@echo "│ │"
@echo "│ lint Lint all code │"
@echo "│ lint-backend Lint backend code │"
@echo "│ lint-frontend Lint frontend code │"
@echo "│ │"
@echo "│ format Format all code │"
@echo "│ format-backend Format backend code │"
@echo "│ format-frontend Format frontend code │"
@echo "╰───────────────────────────────────────────────────────────╯"
### Installation and Setup ###
.PHONY: fresh
fresh: clean clobber all
.PHONY: all
all: install model docs
.PHONY: install
install: install-backend install-frontend
.PHONY: install-backend
install-backend:
cd backend && \
poetry install --with dev
.PHONY: install-frontend
install-frontend:
cd frontend && \
bun install && \
bunx playwright install
.PHONY: model
model: install-backend
$(RUN) gen-pydantic --extra-fields allow $(SCHEMADIR)/model.yaml > $(SCHEMADIR)/model.py
$(RUN) gen-typescript $(SCHEMADIR)/model.yaml > frontend/src/api/model.ts
make format
### Documentation ###
docs/Data-Model:
mkdir -p $@
.PHONY: docs
docs: install-backend docs/Data-Model
$(RUN) gen-doc -d $(ROOTDIR)/docs/Data-Model/ $(SCHEMADIR)/model.yaml
$(RUN) typer backend/src/monarch_py/cli.py utils docs --name monarch --output docs/Usage/CLI.md
$(RUN) mkdocs build
### Data/Fixtures ###
.PHONY: fixtures
fixtures:
@echo "Generating fixtures and data..."
$(RUN) python scripts/generate_fixtures.py --all-fixtures
make format
.PHONY: data
data:
@echo "Generating frontpage metadata..."
$(RUN) python scripts/generate_fixtures.py --metadata
@echo "Generating publications data..."
$(RUN) python scripts/get_publications.py update --update-data
@echo "Generating resources data..."
wget https://raw.githubusercontent.com/monarch-initiative/monarch-documentation/main/src/docs/resources/monarch-app-resources.json -O frontend/src/pages/resources/resources.json
make format-frontend
.PHONY: category-enums
category-enums:
@echo "Generating category enums..."
$(RUN) python scripts/generate_category_enums.py
make format-backend
### Testing ###
.PHONY: test
test: test-backend test-frontend
.PHONY: test-backend
test-backend:
$(RUN) pytest backend/tests
.PHONY: test-frontend
test-frontend:
cd frontend && \
bun run test
### Development ###
.PHONY: dev-frontend
dev-frontend: frontend/src/api/model.ts
cd frontend && \
VITE_API=local bun run dev
.PHONY: dev-api
dev-api:
cd backend && \
poetry run uvicorn src.monarch_py.api.main:app --reload
### Docker ###
.PHONY: docker-build
docker-build:
cd backend && \
docker build --rm --tag us-central1-docker.pkg.dev/monarch-initiative/monarch-api/monarch-api:$(VERSION) .
.PHONY: docker-push
docker-push:
docker push us-central1-docker.pkg.dev/monarch-initiative/monarch-api/monarch-api:$(VERSION)
### Linting, Formatting, and Cleaning ###
.PHONY: clean
clean:
rm -f `find . -type f -name '*.py[co]' `
rm -rf `find . -name __pycache__` \
.ruff_cache .pytest_cache **/.ipynb_checkpoints \
frontend/dist \
backend/.venv \
.PHONY: clobber
clobber:
rm -f schema/model.yaml \
backend/src/monarch_py/datamodels/model.py \
frontend/src/api/model.ts
.PHONY: lint
lint: lint-frontend lint-backend
.PHONY: lint-frontend
lint-frontend:
cd frontend && \
bun run test:lint
.PHONY: lint-backend
lint-backend:
$(RUN) ruff check --diff --exit-zero backend
$(RUN) black --check --diff -l 120 backend/src backend/tests
.PHONY: format
format: format-frontend format-backend
.PHONY: format-backend
format-backend:
$(RUN) ruff check --fix --exit-zero backend
$(RUN) black -l 120 backend/src backend/tests
.PHONY: format-frontend
format-frontend:
cd frontend && \
bun run lint