Skip to content

Commit

Permalink
Quarto output
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchobben committed Nov 25, 2024
1 parent 0052205 commit 7468d4a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 47 deletions.
47 changes: 32 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
.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)))
BASENAME = $(CURDIR)

CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate
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"
@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 --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
9 changes: 0 additions & 9 deletions _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,4 @@ parts:
- caption: Preamble
chapters:
- file: notebooks/how-to-cite
- caption: Classification
chapters:
- file: notebooks/01_classification
- caption: Floodmapping
chapters:
- file: notebooks/02_floodmapping
- caption: References
chapters:
- file: notebooks/references
root: README
12 changes: 5 additions & 7 deletions notebooks/01_classification.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
name: 01_classification
channels:
- conda-forge
- defaults
dependencies:
- python=3.12
- pip
- mamba
- jupyter
- cmcrameri
- dask
- geopandas
- ipykernel
- jupyter
- mamba
- matplotlib
- nbformat
- numpy
- odc-stac
- openssl
- python==3.10
- rasterio
- rioxarray
- scikit-learn
- seaborn
- stackstac
- xarray
- pip:
- pystac-client
- pystac-client
2 changes: 1 addition & 1 deletion notebooks/02_floodmapping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 02_floodmapping
channels:
- conda-forge
dependencies:
- python=3.10
- python=3.12
- pip
- mamba
- jupyter
Expand Down
47 changes: 32 additions & 15 deletions notebooks/Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
.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)))
BASENAME = $(CURDIR)

CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate
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"
@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 --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

0 comments on commit 7468d4a

Please sign in to comment.