-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
151 lines (127 loc) · 3.81 KB
/
Copy pathMakefile
File metadata and controls
151 lines (127 loc) · 3.81 KB
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
148
149
150
151
include config.mk dev.mk
# install + run targets
.PHONY: check-python install run
# cluster admin commands to operate Warden
.PHONY: set-accessible \
ping get-logs
# Mock QPU when the actual QPU is not available
.PHONY: start-mock-qpu start-qutip-qpu
VENV=.venv
PIP_VERSION ?= 26.1
ifeq ($(WITH_PG),1)
INSTALL_FLAGS += -r requirements-pg.txt
endif
ifeq ($(WITH_MARIADB),1)
INSTALL_FLAGS += -r requirements-mariadb.txt
endif
# cluster admin commands
check-python:
@if [ -z "$(PYTHON)" ]; then \
echo "Usage: make install PYTHON=/path/to/python"; \
exit 1; \
fi
@python_version="$$( $(PYTHON) -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>/dev/null )"; \
if [ -z "$$python_version" ]; then \
echo "Error: PYTHON is set to '$(PYTHON)', but that interpreter could not be executed."; \
exit 1; \
fi; \
case "$$python_version" in \
3.11|3.12) \
echo "Detected supported Python $$python_version from PYTHON=$(PYTHON)."; \
;; \
*) \
echo "Error: PYTHON=$(PYTHON) resolves to Python $$python_version. Please use Python 3.11 or 3.12."; \
exit 1; \
;; \
esac
config.yaml:
@new_config="warden/lib/config/config.sample.yaml"; \
if [ ! -f config.yaml ]; then \
cp "$$new_config" config.yaml; \
exit 0; \
fi; \
if cmp -s "$$new_config" config.yaml; then \
exit 0; \
fi; \
last_i=0; \
i=1; \
while [ -e "config.backup-$$i.yaml" ]; do \
last_i=$$i; \
i=$$((i + 1)); \
done; \
if [ "$$last_i" -eq 0 ] || ! cmp -s config.yaml "config.backup-$$last_i.yaml"; then \
cp config.yaml "config.backup-$$i.yaml"; \
fi; \
cp "$$new_config" config.yaml
# Note: the --copies flag is used to create a copy of the binaries, since a symlink may not always work
$(VENV)/bin/python: config.yaml check-python
@if [ -d ./venv ]; then \
echo "Removing legacy ./venv"; \
rm -rf ./venv; \
fi
@if [ -d $(VENV) ] && [ -d $(VENV)/bin ] && [ -f $(VENV)/bin/python ]; then \
echo "$(VENV) already created"; \
else \
echo "Creating $(VENV) with $(PYTHON)"; \
$(PYTHON) -m venv --copies $(VENV); \
echo "Virtualenv created in $(VENV) using $(PYTHON)"; \
fi
$(VENV)/bin/python -m pip install -U pip~=$(PIP_VERSION)
install: $(VENV)/bin/python
$(VENV)/bin/python -m pip install -r requirements.txt $(INSTALL_FLAGS)
run: migrate
@bash -c '\
set -uo pipefail; \
PIDS=(); \
cleanup() { \
trap - SIGINT SIGTERM EXIT; \
if [ "$${#PIDS[@]}" -gt 0 ]; then \
kill -TERM "$${PIDS[@]}" 2>/dev/null || true; \
for pid in "$${PIDS[@]}"; do \
wait "$$pid" 2>/dev/null || true; \
done; \
fi; \
}; \
on_signal() { \
cleanup; \
exit 0; \
}; \
trap on_signal SIGINT SIGTERM; \
trap cleanup EXIT; \
$(VENV)/bin/python -m warden.api.main & PIDS+=($$!); \
$(VENV)/bin/python -m warden.scheduler & PIDS+=($$!); \
set +e; \
wait -n "$${PIDS[@]}"; \
STATUS=$$?; \
set -e; \
cleanup; \
exit $$STATUS'
migrate:
$(MAKE) alembic ARGS="upgrade head"
# cluster admin warden requests
URL ?= http://localhost:8006
MESSAGE ?= Update
define ACCESSIBLE_POST_JSON_PAYLOAD
{"is_accessible": $(IS_ACCESSIBLE), "message": "$(MESSAGE)"}
endef
set-accessible:
@if [ -z "$(IS_ACCESSIBLE)" ]; then \
echo "ERROR 'IS_ACCESSIBLE' is required."; \
echo "Usage: make set-accessible IS_ACCESSIBLE=[true|false] MESSAGE=\"Update\""; \
exit 1; \
fi
curl -X POST $(URL)/accessible \
-H "X-Munge-Cred: $$(munge -n)" \
-H "Content-Type: application/json" \
-d '$(ACCESSIBLE_POST_JSON_PAYLOAD)'
get-logs:
curl -X GET $(URL)/jobs/$(ID)/logs \
-H "X-Munge-Cred: $$(munge -n)"
ping:
curl $(URL)
# Mock QPU when the actual QPU is not available
# Set shot duration with the MOCK_QPU_SHOT_DURATION_S environment variable
start-mock-qpu: $(VENV)/bin/python
$(VENV)/bin/python -m uvicorn mock_qpu_api.app:app --app-dir tests
start-qutip-qpu: $(VENV)/bin/python
MOCK_QPU_API_EMUL=true $(MAKE) start-mock-qpu