Skip to content

Commit

Permalink
Made run_start and descriptor required in Resource and StreamDatum re…
Browse files Browse the repository at this point in the history
…spectively
  • Loading branch information
evalott100 committed Jul 20, 2023
1 parent 04398b7 commit 0813db2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 32 deletions.
13 changes: 5 additions & 8 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,13 +1957,12 @@ def __call__(
root=root,
resource_kwargs=resource_kwargs,
resource_path=resource_path,
run_start=self.start["uid"] if self.start else "",
)

if validate:
schema_validators[DocumentNames.resource].validate(doc)

if self.start:
doc["run_start"] = self.start["uid"]

counter = itertools.count()
return ComposeResourceBundle(
doc,
Expand Down Expand Up @@ -2019,9 +2018,8 @@ def __call__(
data_keys=data_keys,
seq_nums=seq_nums,
indices=indices,
descriptor=descriptor["uid"] if descriptor else "",
)
if descriptor:
doc["descriptor"] = descriptor["uid"]

if validate:
schema_validators[DocumentNames.stream_datum].validate(doc)
Expand All @@ -2043,7 +2041,7 @@ def compose_stream_datum(
"""
warnings.warn(
"compose_stream_datum() will be removed in the minor version.",
DeprecationWarning
DeprecationWarning,
)
return ComposeStreamDatum(stream_resource, counter)(
data_keys,
Expand Down Expand Up @@ -2092,9 +2090,8 @@ def __call__(
resource_path=resource_path,
resource_kwargs=resource_kwargs,
path_semantics=path_semantics,
run_start=self.start["uid"] if self.start else "",
)
if self.start:
doc["run_start"] = self.start["uid"]

if validate:
schema_validators[DocumentNames.stream_resource].validate(doc)
Expand Down
1 change: 1 addition & 0 deletions event_model/documents/generate/typeddict_to_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"schema generation requires pydantic < 2.0 to run, pydantic isn't installed"
)


SCHEMA_OUT_DIR = Path("event_model") / SCHEMA_PATH


Expand Down
14 changes: 6 additions & 8 deletions event_model/documents/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ class Resource(PartialResource):
Field(description="Rules for joining paths"),
]
]
run_start: NotRequired[
Annotated[
str,
Field(
description="Globally unique ID to the run_start document this "
"resource is associated with.",
),
]
run_start: Annotated[
str,
Field(
description="Globally unique ID to the run_start document this "
"resource is associated with.",
),
]
13 changes: 6 additions & 7 deletions event_model/documents/stream_datum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from typing_extensions import Annotated, TypedDict, NotRequired
from typing_extensions import Annotated, TypedDict

from .generate.type_wrapper import Field, add_extra_schema

Expand All @@ -25,10 +25,9 @@ class StreamRange(TypedDict):
class StreamDatum(TypedDict):
"""Document to reference a quanta of an externally-stored stream of data."""

descriptor: NotRequired[
Annotated[
str, Field(description="UID of the EventDescriptor to which this Datum belongs")
]
descriptor: Annotated[
str,
Field(description="UID of the EventDescriptor to " "which this Datum belongs"),
]

block_idx: Annotated[
Expand All @@ -47,8 +46,8 @@ class StreamDatum(TypedDict):
uid: Annotated[
str,
Field(
description="Globally unique identifier for this Datum. A suggested "
"formatting being '<stream_resource>/<stream_name>/<block_id>",
description="A slice object passed to the StreamResource "
"handler so it can hand back data and timestamps."
),
]
data_keys: Annotated[
Expand Down
14 changes: 6 additions & 8 deletions event_model/documents/stream_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ class StreamResource(TypedDict):
description="Subset of resource_path that is a local detail, not semantic."
),
]
run_start: NotRequired[
Annotated[
str,
Field(
description="Globally unique ID to the run_start document "
"this Stream Resource is associated with.",
),
]
run_start: Annotated[
str,
Field(
description="Globally unique ID to the run_start document "
"this Stream Resource is associated with.",
),
]
spec: Annotated[
str,
Expand Down
1 change: 1 addition & 0 deletions event_model/schemas/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"resource_kwargs",
"resource_path",
"root",
"run_start",
"spec",
"uid"
],
Expand Down
3 changes: 2 additions & 1 deletion event_model/schemas/stream_datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@
},
"uid": {
"title": "Uid",
"description": "Globally unique identifier for this Datum. A suggested formatting being '<stream_resource>/<stream_name>/<block_id>",
"description": "A slice object passed to the StreamResource handler so it can hand back data and timestamps.",
"type": "string"
}
},
"required": [
"block_idx",
"data_keys",
"descriptor",
"indices",
"seq_nums",
"stream_resource",
Expand Down
1 change: 1 addition & 0 deletions event_model/schemas/stream_resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"resource_kwargs",
"resource_path",
"root",
"run_start",
"spec",
"uid"
],
Expand Down

0 comments on commit 0813db2

Please sign in to comment.