-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
147 lines (126 loc) · 5.22 KB
/
Makefile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
.PHONY: info conda-course-create conda-course-export conda-create conda-export clean view html-de html-fr htmlfull jupyter-de jupyter-fr help
###########################################################################
# Detect OS #
###########################################################################
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell uname)
endif
###########################################################################
# GLOBALS #
###########################################################################
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PYTHON_INTERPRETER = python
CONDA_ENV_NAME = jupyterbook-env
CONDA_ENV_FILE = jupyterbookenv.yml
CONDA_COURSE_ENV_NAME = minicourse
CONDA_COURSE_ENV_FILE = condaenv.yml
###########################################################################
# OS Specifics #
###########################################################################
ifeq ($(detected_OS),Windows)
PDFVIEWER = 'start "" /max'
ifeq (,$(shell where conda))
HAS_CONDA = False
else
HAS_CONDA = True
SEARCH_ENV = $(shell conda.bat info --envs | grep $(CONDA_ENV_NAME))
FOUND_ENV_NAME = $(word 1, $(notdir $(SEARCH_ENV)))
# check if conda environment is active
ifneq ($(CONDA_DEFAULT_ENV),$(FOUND_ENV_NAME))
CONDA_ACTIVATE := source $$(conda.bat info --base)/etc/profile.d/conda.sh ; conda activate $(CONDA_ENV_NAME)
else
CONDA_ACTIVATE := true
endif
endif
endif
ifeq ($(detected_OS),Darwin)
PDFVIEWER = open
ifeq (,$(shell which conda))
HAS_CONDA = False
else
HAS_CONDA = True
ENV_DIR = $(shell conda info --base)
MY_ENV_DIR = $(ENV_DIR)/envs/$(CONDA_ENV_NAME)
CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate $(CONDA_ENV_NAME)
endif
endif
ifeq ($(detected_OS),Linux)
PDFVIEWER = xdg-open
ifeq (,$(shell which conda))
HAS_CONDA = False
else
HAS_CONDA = True
ENV_DIR = $(shell conda info --base)
MY_ENV_DIR = $(ENV_DIR)/envs/$(CONDA_ENV_NAME)
CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate $(CONDA_ENV_NAME)
endif
endif
###########################################################################
# COMMANDS #
###########################################################################
info: ## Information about the environemnt
@echo "Environment Informations"
@echo " * Detected OS: $(detected_OS)"
@echo " * Pdfviewer: $(PDFVIEWER)"
@echo " * Conda found: $(HAS_CONDA)"
@echo " * Conda envfile: $(CONDA_ENV_FILE)"
@echo " * Conda dir: $(ENV_DIR)"
@echo " * Conda envdir: $(MY_ENV_DIR)"
conda-course-create: ## Install conda environment
ifeq (True,$(HAS_CONDA))
ifneq ("$(wildcard $(MY_ENV_DIR))","") # check if the directory is there
@echo ">>> Found $(CONDA_COURSE_ENV_NAME) environment in $(MY_ENV_DIR). Skipping installation..."
else
@echo ">>> Detected conda, but $(CONDA_COURSE_ENV_NAME) is missing in $(ENV_DIR). Installing ..."
@conda env create -f $(CONDA_COURSE_ENV_FILE) -n $(CONDA_COURSE_ENV_NAME)
endif
else
@echo ">>> Install conda first."
exit
endif
conda-course-export: ## export conda environment
@conda env export > $(CONDA_COURSE_ENV_FILE)
@echo ">>> Conda environment '$(CONDA_COURSE_ENV_NAME)' exported."
conda-create: ## Install conda environment
ifeq (True,$(HAS_CONDA))
ifneq ("$(wildcard $(MY_ENV_DIR))","") # check if the directory is there
@echo ">>> Found $(CONDA_ENV_NAME) environment in $(MY_ENV_DIR). Skipping installation..."
else
@echo ">>> Detected conda, but $(CONDA_ENV_NAME) is missing in $(ENV_DIR). Installing ..."
@conda env create -f $(CONDA_ENV_FILE) -n $(CONDA_ENV_NAME)
endif
else
@echo ">>> Install conda first."
exit
endif
conda-export: ## export conda environment
@conda env export > $(CONDA_ENV_FILE)
@echo ">>> Conda environment '$(CONDA_ENV_NAME)' exported."
html-de: ## build jupyterbook german html files
@$(CONDA_ACTIVATE) && cd jupyterbook-de && jupyter-book build .
@echo ">>> Build german Jupyterbook"
html-fr: ## build jupyterbook french html files
@$(CONDA_ACTIVATE) && cd jupyterbook-fr && jupyter-book build .
@echo ">>> Build french Jupyterbook"
htmlfull: clean ## build from scratch jupyterbook html files
@$(CONDA_ACTIVATE) && cd jupyterbook-de && jupyter-book build .
@$(CONDA_ACTIVATE) && cd jupyterbook-fr && jupyter-book build .
@echo ">>> Build All Jupyterbooks"
view: ## view html files
@$(PDFVIEWER) jupyterbook-de/_build/html/index.html &
@echo ">>> Open Jupyterbook"
clean: ## clean generated file
@rm -R jupyterbook-de/_build
@rm -R jupyterbook-fr/_build
@echo ">>> Removed jupyterbook-de/_build/ folder"
@echo ">>> Removed jupyterbook-fr/_build/ folder"
jupyter-de: ## start german jupyterlab instance
@$(CONDA_ACTIVATE) && jupyter lab --app_dir=./jupyterbook-de
jupyter-fr: ## start french jupyterlab instance
@$(CONDA_ACTIVATE) && jupyter lab --app_dir=./jupyterbook-fr
help: ## Show this help
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help