generated from ProjectPythia/cookbook-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a67967
commit e972e66
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.ONESHELL: | ||
SHELL = /bin/bash | ||
.PHONY: help clean environment kernel post-render data | ||
YML = $(wildcard notebooks/*.yml) | ||
QMD = $(wildcard chapters/*.qmd) | ||
REQ = $(basename $(notdir $(YML))) | ||
CONDA_ENV_DIR := $(foreach i,$(REQ),$(shell conda info --base)/envs/$(i)) | ||
KERNEL_DIR := $(foreach i,$(REQ),$(shell jupyter --data-dir)/kernels/$(i)) | ||
CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate | ||
|
||
help: | ||
@echo "make clean" | ||
@echo " clean all jupyter checkpoints" | ||
@echo "make environment" | ||
@echo " create a conda environment" | ||
@echo "make kernel" | ||
@echo " make ipykernel based on conda lock file" | ||
|
||
clean: | ||
rm --force --recursive .ipynb_checkpoints/ | ||
for i in $(REQ); do conda remove -n $$i --all -y ; jupyter kernelspec uninstall -y $$i ; done | ||
|
||
$(CONDA_ENV_DIR): | ||
for i in $(YML); do conda env create -f $$i; done | ||
|
||
environment: $(CONDA_ENV_DIR) | ||
@echo -e "conda environments are ready." | ||
|
||
$(KERNEL_DIR): $(CONDA_ENV_DIR) | ||
pip install --upgrade pip | ||
pip install jupyter | ||
for i in $(REQ); do $(CONDA_ACTIVATE) $$i ; python -m ipykernel install --user --name $$i --display-name $$i ; conda deactivate; done | ||
|
||
kernel: $(KERNEL_DIR) | ||
@echo -e "conda jupyter kernel is ready." | ||
|
||
post-render: | ||
for i in $(QMD); do quarto convert $$i; done | ||
- mv chapters/*.ipynb notebooks/ >/dev/null 2>&1 | ||
- for f in chapters/*.quarto_ipynb ; do mv -- "$f" "${f%.quarto_ipynb}.ipynb" >/dev/null 2>&1; done | ||
cp Makefile notebooks/ | ||
|
||
data: | ||
wget -q -P ./data https://cloud.geo.tuwien.ac.at/s/AezWMFwmFQJsKyr/download/floodmap.zip | ||
cd data && unzip -n floodmap.zip && rm floodmap.zip |