-
Notifications
You must be signed in to change notification settings - Fork 6
/
schema.py
56 lines (51 loc) · 1.65 KB
/
schema.py
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
from voluptuous import All, Any, Exclusive, Lower, Match, Optional, Required, Schema
def choices(*choices):
"""Checks that value belongs to the specified set of values"""
return Any(*choices, msg=f"expected one of {', '.join(choices)}")
Sha = All(Lower, Match(r"^[0-9a-h]{40}$"), msg="expected a length 40 commit sha")
# Supposed to be produced with:
# {"cls": f"{e.__class__.__module__}.{e.__class__.__name__}", "text": str(e)}
ERROR_SCHEMA = {Required("cls"): str, Required("text"): str}
BASE_SCHEMA = Schema(
{
Required("type"): choices("start", "done", "data"), # No "interrupt" for now
Required(
"repo_url",
): str, # TODO: use some url validator, voluptuous.Url is too strict
Required("baseline_sha"): Sha,
"name": str,
"env": dict,
"client": str,
"errors": [ERROR_SCHEMA],
"params": {str: dict},
"metrics": {str: {"data": dict, "error": ERROR_SCHEMA}},
"machine": dict,
# Required("timestamp"): iso_datetime, # TODO: decide if we need this
},
)
SCHEMAS_BY_TYPE = {
"start": BASE_SCHEMA.extend(
{
"message": str,
Optional("subdir"): str,
},
),
"data": BASE_SCHEMA.extend(
{
Required("step"): int,
"plots": {
str: {
Exclusive("data", "data"): [dict],
"props": dict,
"error": ERROR_SCHEMA,
Exclusive("image", "data"): str,
},
},
},
),
"done": BASE_SCHEMA.extend(
{
"experiment_rev": Sha,
},
),
}