From 0813db2e400b6ea0f50f1dd8693356fd4b9f7110 Mon Sep 17 00:00:00 2001 From: Eva Lott Date: Thu, 20 Jul 2023 11:43:06 +0100 Subject: [PATCH] Made run_start and descriptor required in Resource and StreamDatum respectively --- event_model/__init__.py | 13 +++++-------- .../documents/generate/typeddict_to_schema.py | 1 + event_model/documents/resource.py | 14 ++++++-------- event_model/documents/stream_datum.py | 13 ++++++------- event_model/documents/stream_resource.py | 14 ++++++-------- event_model/schemas/resource.json | 1 + event_model/schemas/stream_datum.json | 3 ++- event_model/schemas/stream_resource.json | 1 + 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/event_model/__init__.py b/event_model/__init__.py index 43e9a3a9..b6626c53 100644 --- a/event_model/__init__.py +++ b/event_model/__init__.py @@ -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, @@ -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) @@ -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, @@ -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) diff --git a/event_model/documents/generate/typeddict_to_schema.py b/event_model/documents/generate/typeddict_to_schema.py index 0aca6465..7108d410 100644 --- a/event_model/documents/generate/typeddict_to_schema.py +++ b/event_model/documents/generate/typeddict_to_schema.py @@ -49,6 +49,7 @@ "schema generation requires pydantic < 2.0 to run, pydantic isn't installed" ) + SCHEMA_OUT_DIR = Path("event_model") / SCHEMA_PATH diff --git a/event_model/documents/resource.py b/event_model/documents/resource.py index 882ceb69..ed272362 100644 --- a/event_model/documents/resource.py +++ b/event_model/documents/resource.py @@ -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.", + ), ] diff --git a/event_model/documents/stream_datum.py b/event_model/documents/stream_datum.py index c3778bbc..f247b858 100644 --- a/event_model/documents/stream_datum.py +++ b/event_model/documents/stream_datum.py @@ -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 @@ -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[ @@ -47,8 +46,8 @@ class StreamDatum(TypedDict): uid: Annotated[ str, Field( - description="Globally unique identifier for this Datum. A suggested " - "formatting being '//", + description="A slice object passed to the StreamResource " + "handler so it can hand back data and timestamps." ), ] data_keys: Annotated[ diff --git a/event_model/documents/stream_resource.py b/event_model/documents/stream_resource.py index df4e9b07..cafcf710 100644 --- a/event_model/documents/stream_resource.py +++ b/event_model/documents/stream_resource.py @@ -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, diff --git a/event_model/schemas/resource.json b/event_model/schemas/resource.json index 5421b607..68ef0bc8 100644 --- a/event_model/schemas/resource.json +++ b/event_model/schemas/resource.json @@ -47,6 +47,7 @@ "resource_kwargs", "resource_path", "root", + "run_start", "spec", "uid" ], diff --git a/event_model/schemas/stream_datum.json b/event_model/schemas/stream_datum.json index 93791946..1c68df37 100644 --- a/event_model/schemas/stream_datum.json +++ b/event_model/schemas/stream_datum.json @@ -69,13 +69,14 @@ }, "uid": { "title": "Uid", - "description": "Globally unique identifier for this Datum. A suggested formatting being '//", + "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", diff --git a/event_model/schemas/stream_resource.json b/event_model/schemas/stream_resource.json index 7149fffe..2ab8719a 100644 --- a/event_model/schemas/stream_resource.json +++ b/event_model/schemas/stream_resource.json @@ -47,6 +47,7 @@ "resource_kwargs", "resource_path", "root", + "run_start", "spec", "uid" ],