Skip to content

Commit

Permalink
conda env with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchobben committed Sep 9, 2024
1 parent 7fa8f55 commit 2c74255
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .setup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GIT_ACCOUNT = TUW-GEO
REPO_NAME = microwave-remote-sensing
GIT_BRANCH = main
GIT_REPO = https://github.com/$(GIT_ACCOUNT)/$(REPO_NAME).git
ROOT = ~/$(REPO_NAME)
ROOT = ${HOME}/$(REPO_NAME)


help:
Expand Down
40 changes: 20 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
.ONESHELL:
SHELL = /bin/bash
.PHONY: help clean environment kernel post-render data
.PHONY: help clean environment kernel teardown

YML = $(wildcard **/*.yml)
REQ = $(basename $(notdir $(YML)))
BASENAME = $(shell basename $(CURDIR))

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

PREFIX = ${HOME}/$(BASENAME)/.conda_envs
CONDA_ENV_DIR := $(foreach i,$(REQ),$(PREFIX)/$(i))
KERNEL_DIR := $(foreach i,$(REQ),$(shell jupyter --data-dir)/kernels/$(i))

help:
@echo "Makefile for setting up environment, kernel, and pulling notebooks"
Expand All @@ -25,27 +26,26 @@ clean:
rm --force --recursive .ipynb_checkpoints/

teardown:
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
$(foreach f, $(REQ), \
jupyter kernelspec uninstall -y $(f); \
conda remove -n $(f) --all -y ; \
conda deactivate; )
- conda config --remove envs_dirs $(PREFIX)

$(CONDA_ENV_DIR): $(YML)
- conda config --prepend envs_dirs $(PREFIX)
$(foreach f, $^, \
conda env create --file $(f) \
--prefix $(PREFIX)/$(basename $(notdir $(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."

0 comments on commit 2c74255

Please sign in to comment.