-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
117 lines (91 loc) · 2.52 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
.ONESHELL:
SHELL:=/bin/bash
.PHONY: create-env install update run-save run-plot documentation docs-build clean-dirs
ENVIRONMENT_FILEPATH := environment.yml
OUTPUT_DIRS := bgc_data bgc_figs
SCRIPTS_DIR := scripts
CONFIG_DIR := config
CONFIG_DEFAULT_DIR := config/default
VENV := ./.venv
ifeq ($(OS), Windows_NT)
BIN = ${VENV}/Scripts/
else
BIN = ${VENV}/bin/
endif
HOOKS := ./.git/hooks
default:
@echo "Call a specific subcommand: create-env,install,update,documentation"
# Main Rules
all:
$(MAKE) -s copy-default-config
$(MAKE) -s install
clean:
rm -r -f $(VENV)
rm -r -f $(HOOKS)
.PHONY: clean-dirs
clean-dirs:
$(foreach dir, $(OUTPUT_DIRS), rm -r -f $(dir))
$(VENV): $(CONDA_EXE) $(ENVIRONMENT_FILEPATH)
$(MAKE) -s clean
$(CONDA_EXE) env create -q --file $(ENVIRONMENT_FILEPATH) --prefix $(VENV)
.PHONY: create-env
create-env:
$(MAKE) -s $(VENV)
.PHONY: poetry-install
poetry-install: poetry.lock
$(BIN)poetry install --only main
.PHONY: install
install: poetry.lock
$(MAKE) -s create-env
$(MAKE) -s poetry-install
$(CONFIG_DIR)/%.toml: $(CONFIG_DEFAULT_DIR)/%.toml
echo "Copy $(CONFIG_DEFAULT_DIR)/$*.toml to $(CONFIG_DIR)/$*.toml";\
cp $(CONFIG_DEFAULT_DIR)/$*.toml $(CONFIG_DIR)/$*.toml
@echo "# CONFIGURATION FILE COPIED FROM DEFAULT: $(CONFIG_DEFAULT_DIR)/$*.toml\n" | cat - $(CONFIG_DIR)/$*.toml | sed '1s/^#.*$$/&/' > $(CONFIG_DIR)/$*.toml.tmp
@mv $(CONFIG_DIR)/$*.toml.tmp $(CONFIG_DIR)/$*.toml
.PHONY: copy-default-config
copy-default-config: $(CONFIG_DIR) $(CONFIG_DEFAULT_DIR)
@for name in $(CONFIG_DEFAULT_DIR)/*.toml ; do\
$(MAKE) -s $(CONFIG_DIR)/$$(basename $${name});\
done
.PHONY: run-%
run-%:
@echo "Executing $(SCRIPTS_DIR)/$(subst -,_,$*).py"
$(MAKE) -s install
$(MAKE) -s copy-default-config
$(BIN)python3.11 $(SCRIPTS_DIR)/$(subst -,_,$*).py
# Documentation Rules
.PHONY: poetry-install-docs
poetry-install-docs: poetry.lock
$(BIN)poetry install --only docs
.PHONY: install-docs
install-docs:
$(MAKE) -s create-env
$(MAKE) -s poetry-install-docs
.PHONY: view-docs
view-docs:
$(MAKE) -s install-docs
$(BIN)mkdocs serve
./site:
$(MAKE) -s install-docs
$(BIN)mkdocs build
.PHONY: build-docs
build-docs:
$(MAKE) -s ./site
.PHONY: deploy-docs
deploy-docs:
$(MAKE) -s install-docs
$(BIN)mkdocs gh-deploy
rm -r -f ./site
# Development Rules
.PHONY: poetry-install-dev
poetry-install-dev: poetry.lock
$(BIN)poetry install
.PHONY: hooks
hooks: $(BIN)pre-commit
$(BIN)pre-commit install
.PHONY: install-dev
install-dev: poetry.lock
$(MAKE) -s create-env
$(MAKE) -s poetry-install-dev
$(MAKE) -s hooks