-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_resolve_python.sh
More file actions
66 lines (62 loc) · 1.81 KB
/
Copy path_resolve_python.sh
File metadata and controls
66 lines (62 loc) · 1.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
# shellcheck shell=bash
# Resolve a working Python interpreter (Git Bash on Windows often has a broken python3 store stub).
python_runs() {
local bin="$1"
command -v "${bin}" >/dev/null 2>&1 || return 1
"${bin}" -c "import sys" >/dev/null 2>&1
}
resolve_python() {
if [[ -n "${PYTHON:-}" ]]; then
if python_runs "${PYTHON}"; then
echo "${PYTHON}"
return 0
fi
echo "PYTHON=${PYTHON} is not runnable" >&2
return 1
fi
local candidates=(python3 python)
case "$(uname -s 2>/dev/null || true)" in
MINGW*|MSYS*|CYGWIN*)
candidates=(python python3)
;;
esac
local c
for c in "${candidates[@]}"; do
if python_runs "${c}"; then
echo "${c}"
return 0
fi
done
echo "python or python3 required (install Python or set PYTHON=...)" >&2
return 1
}
run_materialize_admission_cases() {
local root="$1"
local py
py="$(resolve_python)" || return 1
PCS_BENCHMARK_QUIET=1 "${py}" "${root}/scripts/materialize-admission-benchmark-cases.py" --quiet
}
# ensure_pcs_core_python installs pcs-core (editable) so benchmark_ingest validation can import referencing/jsonschema.
ensure_pcs_core_python() {
local pcs_core="$1"
local py
py="$(resolve_python)" || return 1
if [[ -z "${pcs_core}" || ! -d "${pcs_core}/python" ]]; then
echo "pcs-core python package not found at ${pcs_core}/python" >&2
return 1
fi
if [[ -n "${PCS_SKIP_PCS_CORE_PIP:-}" ]]; then
return 0
fi
if "${py}" -c "from pcs_core.benchmark_ingest import validate_benchmark_ingest_file" 2>/dev/null; then
return 0
fi
if "${py}" -m pip install -q -e "${pcs_core}/python" 2>/dev/null; then
return 0
fi
if "${py}" -m pip install -q --user -e "${pcs_core}/python"; then
return 0
fi
echo "failed to install pcs-core python package from ${pcs_core}/python" >&2
return 1
}