-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotebook.Makefile
More file actions
50 lines (43 loc) · 1.65 KB
/
notebook.Makefile
File metadata and controls
50 lines (43 loc) · 1.65 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
RUN := uv run
# Configurable parameters via environment variables
KERNEL_NAME ?= dm-bip
NB_FILE ?= notebooks/LinkML-Map_tutorial.ipynb
.PHONY: add-jupyter-kernel
add-jupyter-kernel: $(PYTHON)
$(RUN) python -m ipykernel install --user --name=dm-bip --display-name "Python (dm-bip)"
ONESHELL:
.PHONY: jupyter-notebook
jupyter-notebook:
if jupyter kernelspec list 2>/dev/null | grep -q "$(KERNEL_NAME)"; then \
echo "Kernel '$(KERNEL_NAME)' already installed."; \
INSTALLED_BEFORE=yes; \
else \
echo "Installing kernel '$(KERNEL_NAME)'..."; \
$(MAKE) add-jupyter-kernel; \
fi; \
echo "Launching notebook..."; \
$(RUN) jupyter notebook $(NB_FILE); \
if [ "$$INSTALLED_BEFORE" != "no" ]; then \
echo "Removing temporary kernel '$(KERNEL_NAME)'..."; \
$(MAKE) remove-jupyter-kernel; \
fi
.PHONY: remove-jupyter-kernel
remove-jupyter-kernel:
jupyter kernelspec uninstall dm-bip -f
.PHONY: lint-notebooks
lint-notebooks:
@OUTPUTS=$$(find . -name '*.ipynb' ! -path './.venv/*' -exec grep -l '"output_type":' {} \;); \
if [ -n "$$OUTPUTS" ]; then \
echo "Notebooks contain outputs. Run 'make fix-notebook-lint'."; \
exit 1; \
fi
$(RUN) ruff check $(if $(CI),--output-format=github,) --exit-zero notebooks/*.ipynb \
$(if $(CI),| sed -e 's/^::error/::warning/',)
$(RUN) ruff format --diff notebooks/*.ipynb
.PHONY: fix-notebook-lint
fix-notebook-lint:
@echo "Stripping outputs from notebooks..."
@find . -name '*.ipynb' ! -path "./.venv/*" ! -path "./.ipynb_checkpoints/*" -exec \
$(RUN) jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace --to notebook {} \;
-$(RUN) ruff check --fix notebooks/*.ipynb
-$(RUN) ruff format notebooks/*.ipynb