-
Notifications
You must be signed in to change notification settings - Fork 2
/
make.inc
143 lines (117 loc) · 4.28 KB
/
make.inc
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
# Credit for ROOTDIR implementation:
# kenorb (https://stackoverflow.com/users/55075/kenorb),
# How to get current relative directory of your Makefile?,
# URL (version: 2017-05-23): https://stackoverflow.com/a/35698978
ROOTDIR = $(abspath $(patsubst %/,%,$(dir $(abspath \
$(lastword $(MAKEFILE_LIST))))))
RM = rm
FIND = find
COPY = cp
LN = ln
CONDA = conda
CONDA_ENV_FILE = environment.yaml
CONDA_ENV_NAME = cds411-dev
PY = python
PY_SETUP = setup.py
JUPYTER = jupyter
JUPYTERLAB_EXTENSIONS = jupyterlab_vim \
jupyterlab_bokeh \
jupyterlab_templates \
@jupyterlab/git \
@jupyterlab/github \
@jupyterlab/plotly-extension \
@mflevine/jupyterlab_html \
@jupyter-widgets/jupyterlab-manager \
jupyter-matplotlib \
@ryantam626/jupyterlab_code_formatter \
jupyterlab-python-file
JUPYTERLAB_SERVEREXTENSION = jupyterlab_templates \
jupyterlab_git \
jupyterlab_code_formatter
NBCONVERT_OPTS = --config $(ROOTDIR)/jupyter_notebook_config.py
R = Rscript
MD =
XARINGAN =
JUPYTER_NB2PDF =
JUPYTER_NB2RST =
BUILD_DIR = $(ROOTDIR)/build
CLASS_NUMBER =
OUTPUT_DIR = $(patsubst %/,%,$(BUILD_DIR)/$(CLASS_NUMBER))
HOMEWORK_DIR = $(patsubst %/,%,$(ROOTDIR)/homework)
FINAL_PROJECT_DIR = $(patsubst %/,%,$(ROOTDIR)/project)
MD_OUTPUT = github_document
XARINGAN_OUTPUT = xaringan::moon_reader
MD_EXT =
XARINGAN_EXT = $(OUTPUT_DIR)/%.html : %.Rmd
JUPYTER_NB2PDF_EXT = $(OUTPUT_DIR)/%.pdf : %.ipynb
JUPYTER_NB2RST_EXT = $(OUTPUT_DIR)/%.rst : %.ipynb
ALL_FILES = $(MD) \
$(XARINGAN) \
$(JUPYTER_NB2PDF) \
$(JUPYTER_NB2RST)
CLEAN_FILES = *_files/ \
*_cache/
define makefile_help
@echo 'Makefile for CDS 411 course materials '
@echo ' '
@echo 'Usage: '
@echo ' make all Compile and render all materials '
@echo ' '
@echo ' make clean remove temporary and build files '
@echo ' make help display this message '
@echo ' make slides render slides to build/ '
@echo ' make env create conda venv and install deps '
@echo ' make pdf export Jupyter nb to PDF format '
@echo ' make rst export Jupyter nb to RST format '
@echo ' '
endef
define setup_build_directory
mkdir -p "$@"
endef
define cleanup
-$(RM) -rf $(CLEAN_FILES)
-$(RM) -f $(ALL_FILES)
-$(RM) -rf $(BUILD_DIR)
endef
define pycache_cleanup
$(FIND) -name "__pycache__" -type d -exec $(RM) -rf {} +
endef
define ipynb_checkpoints_cleanup
$(FIND) -name ".ipynb_checkpoints" -type d -exec $(RM) -rf {} +
endef
define install_python_deps
bash -lc " \
$(CONDA) activate $(CONDA_ENV_NAME) && \
$(PY) -m nb_pdf_template.install --minted \
"
endef
define install_r_deps
bash -lc "$(CONDA) activate $(CONDA_ENV_NAME) && \
$(R) -e \"install.packages('remotes', repos = 'https://cran.rstudio.com')\" \
-e \"remotes::install_deps()\""
endef
define update_conda_env
bash -lc "$(CONDA) env update --file $(CONDA_ENV_FILE)"
endef
define launch_jupyter_lab
bash -lc " \
$(CONDA) activate $(CONDA_ENV_NAME) && \
$(JUPYTER) lab --ip='0.0.0.0' \
"
endef
define nbconvert
bash -lc " \
$(CONDA) activate $(CONDA_ENV_NAME) && \
$(JUPYTER) nbconvert --to $(1) --output-dir $(2) $(NBCONVERT_OPTS) $< \
"
endef
define rmarkdown_render
$(R) -e "rmarkdown::render(input = '$<', output_file = '$@', \
output_format = '$(1)')"
endef
define install_jupyterlab_extensions
$(JUPYTER) labextension install $(1)
endef
define install_serverextension
$(JUPYTER) serverextension enable --py $(1)
endef