-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdescribe
More file actions
executable file
·50 lines (40 loc) · 1.69 KB
/
describe
File metadata and controls
executable file
·50 lines (40 loc) · 1.69 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
#!/usr/bin/env bash
# Describes the version of the algorithm that is currently checked out. If the
# current branch is not `main`, uses the current branch name as the version.
# Otherwise, uses the version from the `algorithm_config.yaml` file, if and only
# if the current commit is tagged with that version:
#
# bin/algo/describe
#
# Currently, this script only prints the XML response from the MAAP API, which
# is not very useful. It would be better to parse the XML and print a more
# human-readable description of the algorithm. For now, this script is used
# mainly for other scripts to check whether or not the algorithm exists.
set -euo pipefail
function stderr() {
echo >&2 "${1}"
}
# Obtain the algorithm name and version from the algorithm_config.yaml file, but
# use the current branch name as the version if the current branch is not `main`.
yaml_file=${1:-algorithm_config.yaml}
branch=$(git rev-parse --abbrev-ref HEAD)
algorithm_name=$(grep "^algorithm_name:" "${yaml_file}" | sed -E 's/algorithm_name: ([^[:space:]]+).*/\1/')
algorithm_version=$(grep "^algorithm_version:" "${yaml_file}" | sed -E 's/algorithm_version: ([^[:space:]]+).*/\1/')
[[ "${branch}" != "main" ]] && algorithm_version=${branch}
algorithm_id="${algorithm_name}:${algorithm_version}"
read -r -d '' describe_algorithm <<EOF || true
import json
import sys
import tempfile
import yaml
from maap.maap import MAAP
maap = MAAP()
if r := maap.describeAlgorithm("${algorithm_id}"):
# This response is XML, not JSON, unfortunately, so the output is not
# convenient to read.
print(r.text)
else:
print(r.text, file=sys.stderr)
sys.exit(1)
EOF
pixi run --quiet --no-progress -- python -c "${describe_algorithm}"