-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (198 loc) Β· 7.48 KB
/
Makefile
File metadata and controls
238 lines (198 loc) Β· 7.48 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
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
# Use qvm to manage quarto
QUARTO_VERSION ?= 1.7.31
QUARTO_PATH = ~/.local/share/qvm/versions/v${QUARTO_VERSION}/bin/quarto
PATH_PKG_R := pkg-r
PATH_PKG_PY := pkg-py
PATH_PKG_JS := js
.PHONY: install-quarto
install-quarto:
@echo "π΅ Installing quarto"
@if ! [ -z $(command -v qvm)]; then \
@echo "Error: qvm is not installed. Please visit https://github.com/dpastoor/qvm/releases/ to install it." >&2 \
exit 1; \
fi
qvm install v${QUARTO_VERSION}
@echo "πΉ Updating .vscode/settings.json"
@awk -v path="${QUARTO_PATH}" '/"quarto.path":/ {gsub(/"quarto.path": ".*"/, "\"quarto.path\": \"" path "\"")} 1' .vscode/settings.json > .vscode/settings.json.tmp && mv .vscode/settings.json.tmp .vscode/settings.json
@echo "πΉ Updating .github/workflows/quartodoc.yaml"
@awk -v ver="${QUARTO_VERSION}" '/QUARTO_VERSION:/ {gsub(/QUARTO_VERSION: .*/, "QUARTO_VERSION: " ver)} 1' .github/workflows/quartodoc.yaml > .github/workflows/quartodoc.yaml.tmp && mv .github/workflows/quartodoc.yaml.tmp .github/workflows/quartodoc.yaml
.PHONY: docs
docs: r-docs-render py-docs-render ## [docs] Build the documentation
.PHONY: docs-preview
docs-preview: ## [docs] Preview the documentation
@npx http-server docs -p 8080
.PHONY: js-setup
js-setup: ## [js] Install JS dependencies
@echo "π Setup JS dependencies"
cd $(PATH_PKG_JS) && npm install
.PHONY: js-setup-ci
js-setup-ci: ## [js] Install JS dependencies as CI
@echo "π Setup JS dependencies"
cd $(PATH_PKG_JS) && npm ci
.PHONY: js-lint
js-lint: ## [js] Lint JS code
@echo "π Linting JS code"
cd $(PATH_PKG_JS) && npm run lint
.PHONY: js-build
js-build: ## [js] Build JS code
@echo "π§³ Building JS code"
cd $(PATH_PKG_JS) && npm run build
.PHONY: js-build-watch
js-build-watch: ## [js] Build JS code in watch mode
@echo "π§³ Building JS code in watch mode"
cd $(PATH_PKG_JS) && npm run watch
.PHONY: update-dist
update-dist: js-build r-update-dist py-update-dist ## Update shinychat web assets in all packages
.PHONY: r-setup
r-setup: ## [r] Install R dependencies
@echo "π Updating R dependencies"
cd $(PATH_PKG_R) && Rscript -e "pak::local_install_dev_deps()"
.PHONY: r-check
r-check: r-check-format r-check-tests r-check-package ## [r] All R checks
.PHONY: r-document
r-document: ## [r] Document package
@echo "π Documenting R package"
cd $(PATH_PKG_R) && Rscript -e "devtools::document()"
.PHONY: r-format
r-format: ## [r] Format R code
air format $(PATH_PKG_R)/
.PHONY: r-check-package
r-check-package: ## [r] Check package
@echo ""
@echo "π Running R CMD Check"
cd $(PATH_PKG_R) && Rscript -e "devtools::check(document = FALSE)"
.PHONY: r-check-tests
r-check-tests: ## [r] Check tests
@echo ""
@echo "π§ͺ Running R tests"
cd $(PATH_PKG_R) && Rscript -e "devtools::test()"
.PHONY: r-check-format
r-check-format: ## [r] Check format
@echo ""
@echo "π Checking R format"
air format --check $(PATH_PKG_R)/
.PHONY: r-update-dist
r-update-dist: ## [r] Update shinychat web assets
@echo ""
@echo "π Updating shinychat web assets"
if [ -d $(PATH_PKG_R)/inst/lib/shiny ]; then \
rm -rf $(PATH_PKG_R)/inst/lib/shiny; \
fi
mkdir -p $(PATH_PKG_R)/inst/lib/shiny
cp -r $(PATH_PKG_JS)/dist/chat $(PATH_PKG_R)/inst/lib/shiny/
cp -r $(PATH_PKG_JS)/dist/markdown-stream $(PATH_PKG_R)/inst/lib/shiny/
(git rev-parse HEAD) > "$(PATH_PKG_R)/inst/lib/shiny/GIT_VERSION"
.PHONY: r-docs-render
r-docs-render: ## [r] Build R docs
@echo "π Rendering R docs with pkgdown"
cd $(PATH_PKG_R) && Rscript -e "pkgdown::build_site()"
.PHONY: r-docs-preview
r-docs-preview: ## [r] Build R docs
@echo "π Rendering R docs with pkgdown"
cd $(PATH_PKG_R) && Rscript -e "pkgdown::preview_site()"
.PHONY: py-setup
py-setup: ## [py] Setup python environment
uv sync --all-extras --all-groups --upgrade
.PHONY: py-check
py-check: py-check-format py-check-types py-check-tests ## [py] Run python checks
.PHONY: py-check-tox
py-check-tox: ## [py] Run python checks across versions with tox
@echo ""
@echo "π Running tests and type checking with tox for Python 3.10--3.14"
uv run tox run-parallel
.PHONY: py-check-tests
py-check-tests: ## [py] Run python tests
@echo ""
@echo "π§ͺ Running tests with pytest"
uv run playwright install
uv run pytest
.PHONY: py-check-types
py-check-types: ## [py] Run python type checks
@echo ""
@echo "π Checking types with pyright"
uv run pyright
.PHONY: py-check-format
py-check-format:
@echo ""
@echo "π Checking format with ruff"
uv run ruff check pkg-py --config pyproject.toml
.PHONY: py-format
py-format: ## [py] Format python code
uv run ruff check --fix pkg-py --config pyproject.toml
uv run ruff format pkg-py --config pyproject.toml
.PHONY: py-coverage
py-coverage: ## [py] Generate coverage report
@echo "π Generating coverage report"
uv run coverage run -m pytest
uv run coverage report
.PHONY: py-coverage-report
py-coverage-report: py-coverage ## [py] Generate coverage report and open it in browser
uv run coverage html
@echo ""
@echo "π‘ Serving coverage report at http://localhost:8081/"
@npx http-server htmlcov --silent -p 8081
.PHONY: py-update-snaps
py-update-snaps: ## [py] Update python test snapshots
@echo "πΈ Updating pytest snapshots"
uv run pytest --snapshot-update
.PHONY: py-docs
py-docs: py-docs-api py-docs-render ## [py] Build python docs
.PHONY: py-docs-render
py-docs-render: ## [py] Render python docs
@echo "π Rendering python docs with quarto"
@$(eval export IN_QUARTODOC=true)
${QUARTO_PATH} render pkg-py/docs
.PHONY: py-docs-preview
py-docs-preview: ## [py] Preview python docs
@echo "π Rendering python docs with quarto"
@$(eval export IN_QUARTODOC=true)
${QUARTO_PATH} preview pkg-py/docs
.PHONY: py-docs-api
py-docs-api: ## [py] Update python API docs
@echo "π Generating python docs with quartodoc"
@$(eval export IN_QUARTODOC=true)
cd pkg-py/docs && uv run quartodoc build
cd pkg-py/docs && uv run quartodoc interlinks
.PHONY: py-docs-api-watch
py-docs-api-watch: ## [py] Update python docs
@echo "π Generating python docs with quartodoc"
@$(eval export IN_QUARTODOC=true)
uv run quartodoc build --config pkg-py/docs/_quarto.yml --watch
.PHONY: py-docs-clean
py-docs-clean: ## [py] Clean python docs
@echo "π§Ή Cleaning python docs"
rm -r pkg-py/docs/api
find pkg-py/docs/py -name '*.quarto_ipynb' -delete
.PHONY: py-build
py-build: ## [py] Build python package
@echo "π§³ Building python package"
@[ -d dist ] && rm -r dist || true
uv build
.PHONY: py-update-dist
py-update-dist: ## [py] Update shinychat web assets
@echo ""
@echo "π Updating shinychat web assets"
if [ -d $(PATH_PKG_PY)/src/shinychat/www ]; then \
rm -rf $(PATH_PKG_PY)/src/shinychat/www; \
fi
mkdir -p $(PATH_PKG_PY)/src/shinychat/www
cp -r $(PATH_PKG_JS)/dist/chat $(PATH_PKG_PY)/src/shinychat/www/
cp -r $(PATH_PKG_JS)/dist/markdown-stream $(PATH_PKG_PY)/src/shinychat/www/
(git rev-parse HEAD) > "$(PATH_PKG_PY)/src/shinychat/www/GIT_VERSION"
.PHONY: help
help: ## Show help messages for make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; { \
printf "\033[32m%-18s\033[0m", $$1; \
if ($$2 ~ /^\[docs\]/) { \
printf "\033[37m[docs]\033[0m%s\n", substr($$2, 7); \
} else if ($$2 ~ /^\[py\]/) { \
printf " \033[31m[py]\033[0m%s\n", substr($$2, 5); \
} else if ($$2 ~ /^\[r\]/) { \
printf " \033[34m[r]\033[0m%s\n", substr($$2, 4); \
} else if ($$2 ~ /^\[js\]/) { \
printf " \033[33m[js]\033[0m%s\n", substr($$2, 5); \
} else { \
printf " %s\n", $$2; \
} \
}'
.DEFAULT_GOAL := help