Skip to content

Commit

Permalink
fix quarto ordering and make kernel target
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchobben committed Nov 25, 2024
1 parent b3cee36 commit c3c36e6
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 1,096 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
.env

# Temporary and binary files
/.quarto/
/_book/
/data/
.quarto/
_book/
data/
_freeze/
notebooks/
*_files/
.jupyter_cache/
*~
Expand Down Expand Up @@ -60,6 +62,7 @@ MANIFEST
# Per-project virtualenvs
.venv*/
venv
.conda_envs/

# Make file markers
.install*
50 changes: 33 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
.ONESHELL:
SHELL = /bin/bash
.PHONY: help clean environment kernel post-render data
.PHONY: help clean environment kernel teardown 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))
BASENAME = $(CURDIR)

CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate
PREFIX = $(BASENAME)/.conda_envs
CONDA_ENV_DIR := $(foreach i,$(REQ),$(PREFIX)/$(i))
KERNEL_DIR := $(foreach i,$(REQ),$(shell jupyter --data-dir)/kernels/$(i))

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"
@echo "Makefile for setting up environment, kernel, and pulling notebooks"
@echo ""
@echo "Usage:"
@echo " make environment - Create Conda environments"
@echo " make kernel - Create Conda environments and Jupyter kernels"
@echo " "
@echo " make teardown - Remove Conda environments and Jupyter kernels"
@echo " make clean - Removes ipynb_checkpoints"
@echo " make help - Display this help message"

clean:
rm --force --recursive .ipynb_checkpoints/
for i in $(REQ); do conda remove -n $$i --all -y ; jupyter kernelspec uninstall -y $$i ; done
rm --force --recursive .ipynb_checkpoints/ **/.ipynb_checkpoints/ _book/ \
_freeze/ .quarto/

teardown:
$(foreach f, $(REQ), \
$(CONDA_ACTIVATE) $(f); \
jupyter kernelspec uninstall -y $(f); \
conda deactivate; \
conda remove -n $(f) --all -y ; \
conda deactivate; )

$(CONDA_ENV_DIR):
for i in $(YML); do conda env create -f $$i; done
$(CONDA_ENV_DIR): $(YML)
- conda update -n base -c conda-forge conda -y
$(foreach f, $^, conda env create --file $(f); )

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
$(foreach f, $(REQ), \
$(CONDA_ACTIVATE) $(f); \
python -m ipykernel install --user --name $(f) --display-name $(f); \
conda deactivate; )

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/
Expand Down
14 changes: 10 additions & 4 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ book:
date: "7/10/2024"
chapters:
- index.qmd
- chapters/Courses
- chapter/Microwave Remote Sensing
- chapters/01_classification.qmd
- chapters/02_floodmapping.qmd
- part: "Courses"
chapters:
- chapters/01_classification.qmd
- chapters/02_floodmapping.qmd
- part: "Tutorials"
- part: "Lessons"
- chapters/references.qmd
navbar:
logo: assets/images/tuw-geo-logo.svg
Expand All @@ -27,3 +29,7 @@ format:
theme: cosmo
title-block-banner: "#006699"
title-block-banner-color: white

execute:
freeze: auto
keep-ipynb: true
Loading

0 comments on commit c3c36e6

Please sign in to comment.