dkist-processing-common 10.6.1rc3__py3-none-any.whl → 10.6.1rc4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
changelog/236.misc.1.rst CHANGED
@@ -1 +1,2 @@
1
- Change returns from the metadata store queries into Pydantic BaseModel instances. Remove unnecessary parsing and error checking.
1
+ Change returns from the metadata store queries into Pydantic BaseModel instances. Remove unnecessary parsing
2
+ and error checking in the metadata store mixin.
changelog/236.misc.rst CHANGED
@@ -1 +1,3 @@
1
- Convert dataclasses in the graphql model to Pydantic BaseModels for additional validation. In the RecipeRunResponse class, configuration is now returned as a dictionary. In the InputDatasetPartResponse class, inputDatasetPartDocument is now returned as a list of dictionaries.
1
+ Convert dataclasses in the graphql model to Pydantic BaseModels for additional validation. In the
2
+ RecipeRunResponse class, configuration is converted from a JSON dictionary to its own Pydantic BaseModel.
3
+ In the InputDatasetPartResponse class, the inputDatasetPartDocument is now returned as a list of dictionaries.
@@ -1,6 +1,6 @@
1
1
  """GraphQL Data models for the metadata store api."""
2
2
  from pydantic import BaseModel
3
- from pydantic import Field
3
+ from pydantic import field_validator
4
4
  from pydantic import Json
5
5
 
6
6
 
@@ -85,13 +85,32 @@ class RecipeRunProvenanceResponse(BaseModel):
85
85
  isTaskManual: bool
86
86
 
87
87
 
88
+ class RecipeRunConfiguration(BaseModel):
89
+ """Response class for a recipe run configuration dictionary."""
90
+
91
+ validate_l1_on_write: bool = True
92
+ destination_bucket: str = "data"
93
+ tile_size: int | None = None
94
+ trial_directory_name: str | None = None
95
+ trial_root_directory_name: str | None = None
96
+ teardown_enabled: bool = True
97
+ trial_exclusive_transfer_tag_lists: list[str] | None = None
98
+
99
+
88
100
  class RecipeRunResponse(BaseModel):
89
101
  """Recipe run query response."""
90
102
 
91
103
  recipeInstance: RecipeInstanceResponse
92
104
  recipeInstanceId: int
93
105
  recipeRunProvenances: list[RecipeRunProvenanceResponse]
94
- configuration: Json[dict] | None = Field(default_factory=dict)
106
+ configuration: Json[RecipeRunConfiguration] | None
107
+
108
+ @field_validator("configuration", mode="after")
109
+ @classmethod
110
+ def _use_default_configuration_model(cls, value):
111
+ if value is None:
112
+ return RecipeRunConfiguration()
113
+ return value
95
114
 
96
115
 
97
116
  class RecipeRunMutationResponse(BaseModel):
@@ -4,6 +4,8 @@ import logging
4
4
  from functools import cached_property
5
5
  from typing import Literal
6
6
 
7
+ from pydantic import validate_call
8
+
7
9
  from dkist_processing_common._util.graphql import GraphQLClient
8
10
  from dkist_processing_common.codecs.quality import QualityDataEncoder
9
11
  from dkist_processing_common.config import common_configurations
@@ -61,6 +63,7 @@ class MetadataStoreMixin:
61
63
  if len(response) > 0:
62
64
  return response[0].recipeRunStatusId
63
65
 
66
+ @validate_call
64
67
  def _metadata_store_create_recipe_run_status(self, status: str, is_complete: bool) -> int:
65
68
  """
66
69
  Add a new recipe run status to the db.
@@ -75,10 +78,6 @@ class MetadataStoreMixin:
75
78
  "marked complete.",
76
79
  }
77
80
 
78
- if not isinstance(status, str):
79
- raise TypeError(f"status must be of type str: {status}")
80
- if not isinstance(is_complete, bool):
81
- raise TypeError(f"is_complete must be of type bool: {is_complete}")
82
81
  params = RecipeRunStatusMutation(
83
82
  recipeRunStatusName=status,
84
83
  isComplete=is_complete,
@@ -197,7 +196,7 @@ class MetadataStoreMixin:
197
196
  # INPUT DATASET RECIPE RUN
198
197
 
199
198
  @cached_property
200
- def metadata_store_input_dataset_recipe_run_response(self) -> InputDatasetRecipeRunResponse:
199
+ def metadata_store_input_dataset_recipe_run(self) -> InputDatasetRecipeRunResponse:
201
200
  """Get the input dataset recipe run response from the metadata store."""
202
201
  params = RecipeRunQuery(recipeRunId=self.recipe_run_id)
203
202
  response = self.metadata_store_client.execute_gql_query(
@@ -213,7 +212,7 @@ class MetadataStoreMixin:
213
212
  """Get the input dataset part by input dataset part type name."""
214
213
  part_type_dict = {}
215
214
  parts = (
216
- self.metadata_store_input_dataset_recipe_run_response.recipeInstance.inputDataset.inputDatasetInputDatasetParts
215
+ self.metadata_store_input_dataset_recipe_run.recipeInstance.inputDataset.inputDatasetInputDatasetParts
217
216
  )
218
217
  for part in parts:
219
218
  part_type_name = part.inputDatasetPart.inputDatasetPartType.inputDatasetPartTypeName
@@ -19,7 +19,7 @@ class OutputDataBase(WorkflowTaskBase, ABC):
19
19
  @cached_property
20
20
  def destination_bucket(self) -> str:
21
21
  """Get the destination bucket."""
22
- return self.metadata_store_recipe_run.configuration.get("destination_bucket", "data")
22
+ return self.metadata_store_recipe_run.configuration.destination_bucket
23
23
 
24
24
  def format_object_key(self, path: Path) -> str:
25
25
  """
@@ -22,7 +22,7 @@ class TeardownBase(WorkflowTaskBase, ABC):
22
22
  @property
23
23
  def teardown_enabled(self) -> bool:
24
24
  """Recipe run configuration indicating if data should be removed at the end of a run."""
25
- return self.metadata_store_recipe_run.configuration.get("teardown_enabled", True)
25
+ return self.metadata_store_recipe_run.configuration.teardown_enabled
26
26
 
27
27
  def run(self) -> None:
28
28
  """Run method for Teardown class."""
@@ -2,6 +2,7 @@
2
2
  import logging
3
3
  from pathlib import Path
4
4
 
5
+ from dkist_processing_common.codecs.json import json_encoder
5
6
  from dkist_processing_common.models.tags import Tag
6
7
  from dkist_processing_common.tasks.base import WorkflowTaskBase
7
8
  from dkist_processing_common.tasks.mixin.globus import GlobusMixin
@@ -20,11 +21,11 @@ class TransferL0Data(WorkflowTaskBase, GlobusMixin, InputDatasetMixin):
20
21
  def download_input_dataset(self):
21
22
  """Get the input dataset document parts and save it to scratch with the appropriate tags."""
22
23
  if doc := self.metadata_store_input_dataset_observe_frames.inputDatasetPartDocument:
23
- self.write(doc.encode("utf-8"), tags=Tag.input_dataset_observe_frames())
24
+ self.write(doc, tags=Tag.input_dataset_observe_frames(), encoder=json_encoder)
24
25
  if doc := self.metadata_store_input_dataset_calibration_frames.inputDatasetPartDocument:
25
- self.write(doc.encode("utf-8"), tags=Tag.input_dataset_calibration_frames())
26
+ self.write(doc, tags=Tag.input_dataset_calibration_frames(), encoder=json_encoder)
26
27
  if doc := self.metadata_store_input_dataset_parameters.inputDatasetPartDocument:
27
- self.write(doc.encode("utf-8"), tags=Tag.input_dataset_parameters())
28
+ self.write(doc, tags=Tag.input_dataset_parameters(), encoder=json_encoder)
28
29
 
29
30
  def format_transfer_items(
30
31
  self, input_dataset_objects: list[InputDatasetObject]
@@ -43,25 +43,23 @@ class TransferTrialData(TransferDataBase, GlobusMixin):
43
43
 
44
44
  @cached_property
45
45
  def destination_bucket(self) -> str:
46
- """Get the destination bucket with a trial default."""
47
- return self.metadata_store_recipe_run.configuration.get("destination_bucket", "etc")
46
+ """Get the destination bucket."""
47
+ return self.metadata_store_recipe_run.configuration.destination_bucket
48
48
 
49
49
  @property
50
50
  def destination_root_folder(self) -> Path:
51
51
  """Format the destination root folder with a value that can be set in the recipe run configuration."""
52
- root_name_from_configuration = self.metadata_store_recipe_run.configuration.get(
53
- "trial_root_directory_name"
52
+ root_name_from_config = (
53
+ self.metadata_store_recipe_run.configuration.trial_root_directory_name
54
54
  )
55
- root_name = Path(root_name_from_configuration or super().destination_root_folder)
56
-
55
+ root_name = Path(root_name_from_config or super().destination_root_folder)
57
56
  return root_name
58
57
 
59
58
  @property
60
59
  def destination_folder(self) -> Path:
61
60
  """Format the destination folder with a parent that can be set by the recipe run configuration."""
62
- dir_name = self.metadata_store_recipe_run.configuration.get("trial_directory_name") or Path(
63
- self.constants.dataset_id
64
- )
61
+ dir_name_from_config = self.metadata_store_recipe_run.configuration.trial_directory_name
62
+ dir_name = dir_name_from_config or Path(self.constants.dataset_id)
65
63
  return self.destination_root_folder / dir_name
66
64
 
67
65
  @property
@@ -71,9 +69,12 @@ class TransferTrialData(TransferDataBase, GlobusMixin):
71
69
  Defaults to transferring all product files. Setting `trial_exclusive_transfer_tag_lists` in the
72
70
  recipe run configuration to a list of tag lists will override the default.
73
71
  """
74
- return self.metadata_store_recipe_run.configuration.get(
75
- "trial_exclusive_transfer_tag_lists", self.default_transfer_tag_lists
72
+ tag_list_from_config = (
73
+ self.metadata_store_recipe_run.configuration.trial_exclusive_transfer_tag_lists
76
74
  )
75
+ if tag_list_from_config is not None:
76
+ return tag_list_from_config
77
+ return self.default_transfer_tag_lists
77
78
 
78
79
  @property
79
80
  def output_frame_tag_list(self) -> list[list[str]]:
@@ -105,14 +105,14 @@ class WriteL1Frame(WorkflowTaskBase, MetadataStoreMixin, ABC):
105
105
  spec214_validator.validate(self.scratch.absolute_path(relative_path))
106
106
 
107
107
  @cached_property
108
- def tile_size_param(self) -> int:
108
+ def tile_size_param(self) -> int | None:
109
109
  """Get the tile size parameter for compression."""
110
- return self.metadata_store_recipe_run.configuration.get("tile_size", None)
110
+ return self.metadata_store_recipe_run.configuration.tile_size
111
111
 
112
112
  @cached_property
113
113
  def validate_l1_on_write(self) -> bool:
114
114
  """Check for validate on write."""
115
- return self.metadata_store_recipe_run.configuration.get("validate_l1_on_write", True)
115
+ return self.metadata_store_recipe_run.configuration.validate_l1_on_write
116
116
 
117
117
  @cached_property
118
118
  def workflow_had_manual_intervention(self):
@@ -333,6 +333,79 @@ def max_cs_step_time_sec() -> float:
333
333
 
334
334
 
335
335
  class FakeGQLClient:
336
+
337
+ observe_frames_doc_object = [
338
+ {
339
+ "bucket": uuid4().hex[:6],
340
+ "object_keys": [Path(uuid4().hex[:6]).as_posix() for _ in range(3)],
341
+ }
342
+ ]
343
+
344
+ calibration_frames_doc_object = [
345
+ {
346
+ "bucket": uuid4().hex[:6],
347
+ "object_keys": [Path(uuid4().hex[:6]).as_posix() for _ in range(3)],
348
+ },
349
+ {
350
+ "bucket": uuid4().hex[:6],
351
+ "object_keys": [Path(uuid4().hex[:6]).as_posix() for _ in range(3)],
352
+ },
353
+ ]
354
+
355
+ parameters_doc_object = [
356
+ {
357
+ "parameterName": "param_name_1",
358
+ "parameterValues": [
359
+ {
360
+ "parameterValueId": 1,
361
+ "parameterValue": json.dumps([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
362
+ "parameterValueStartDate": "2000-01-01",
363
+ }
364
+ ],
365
+ },
366
+ {
367
+ "parameterName": "param_name_2",
368
+ "parameterValues": [
369
+ {
370
+ "parameterValueId": 2,
371
+ "parameterValue": json.dumps(
372
+ {
373
+ "__file__": {
374
+ "bucket": "data",
375
+ "objectKey": f"parameters/param_name/{uuid4().hex}.dat",
376
+ }
377
+ }
378
+ ),
379
+ "parameterValueStartDate": "2000-01-01",
380
+ },
381
+ {
382
+ "parameterValueId": 3,
383
+ "parameterValue": json.dumps(
384
+ {
385
+ "__file__": {
386
+ "bucket": "data",
387
+ "objectKey": f"parameters/param_name/{uuid4().hex}.dat",
388
+ }
389
+ }
390
+ ),
391
+ "parameterValueStartDate": "2000-01-02",
392
+ },
393
+ ],
394
+ },
395
+ {
396
+ "parameterName": "param_name_4",
397
+ "parameterValues": [
398
+ {
399
+ "parameterValueId": 4,
400
+ "parameterValue": json.dumps(
401
+ {"a": 1, "b": 3.14159, "c": "foo", "d": [1, 2, 3]}
402
+ ),
403
+ "parameterValueStartDate": "2000-01-01",
404
+ }
405
+ ],
406
+ },
407
+ ]
408
+
336
409
  def __init__(self, *args, **kwargs):
337
410
  pass
338
411
 
@@ -352,7 +425,9 @@ class FakeGQLClient:
352
425
  InputDatasetInputDatasetPartResponse(
353
426
  inputDatasetPart=InputDatasetPartResponse(
354
427
  inputDatasetPartId=1,
355
- inputDatasetPartDocument='[{"parameterName": "", "parameterValues": [{"parameterValueId": 1, "parameterValue": "[[1,2,3],[4,5,6],[7,8,9]]", "parameterValueStartDate": "1/1/2000"}]}]',
428
+ inputDatasetPartDocument=json.dumps(
429
+ self.parameters_doc_object
430
+ ),
356
431
  inputDatasetPartType=InputDatasetPartTypeResponse(
357
432
  inputDatasetPartTypeName="parameters"
358
433
  ),
@@ -361,15 +436,9 @@ class FakeGQLClient:
361
436
  InputDatasetInputDatasetPartResponse(
362
437
  inputDatasetPart=InputDatasetPartResponse(
363
438
  inputDatasetPartId=2,
364
- inputDatasetPartDocument="""[
365
- {
366
- "bucket": "bucket_name",
367
- "object_keys": [
368
- "key1",
369
- "key2"
370
- ]
371
- }
372
- ]""",
439
+ inputDatasetPartDocument=json.dumps(
440
+ self.observe_frames_doc_object
441
+ ),
373
442
  inputDatasetPartType=InputDatasetPartTypeResponse(
374
443
  inputDatasetPartTypeName="observe_frames"
375
444
  ),
@@ -378,15 +447,9 @@ class FakeGQLClient:
378
447
  InputDatasetInputDatasetPartResponse(
379
448
  inputDatasetPart=InputDatasetPartResponse(
380
449
  inputDatasetPartId=3,
381
- inputDatasetPartDocument="""[
382
- {
383
- "bucket": "bucket_name",
384
- "object_keys": [
385
- "key3",
386
- "key4"
387
- ]
388
- }
389
- ]""",
450
+ inputDatasetPartDocument=json.dumps(
451
+ self.calibration_frames_doc_object
452
+ ),
390
453
  inputDatasetPartType=InputDatasetPartTypeResponse(
391
454
  inputDatasetPartTypeName="calibration_frames"
392
455
  ),
@@ -417,14 +480,6 @@ class FakeGQLClient:
417
480
  ...
418
481
 
419
482
 
420
- class FakeGQLClientNoRecipeConfiguration(FakeGQLClient):
421
- def execute_gql_query(self, **kwargs):
422
- response = super().execute_gql_query(**kwargs)
423
- if type(response[0]) == RecipeRunResponse:
424
- response[0].configuration = {}
425
- return response
426
-
427
-
428
483
  # All the following stuff is copied from dkist-processing-pac
429
484
  def compute_telgeom(time_hst: Time):
430
485
  dkist_lon = (156 + 15 / 60.0 + 21.7 / 3600.0) * (-1)
@@ -774,43 +829,21 @@ def task_with_input_dataset(
774
829
  yield task
775
830
 
776
831
 
777
- def create_parameter_files(task: WorkflowTaskBase, expected_parameters: dict):
832
+ def create_parameter_files(
833
+ task: WorkflowTaskBase, parameters_doc: list[dict] = FakeGQLClient.parameters_doc_object
834
+ ):
778
835
  """
779
- Create the parameter files required by the task.
780
-
781
- Parameters
782
- ----------
783
- task
784
- The task associated with these parameters
785
-
786
- expected_parameters
787
- A dict of parameters with the format shown below
788
-
789
- Returns
790
- -------
791
- None
792
-
793
- expected_parameters is a dict with the parameter names as the keys
794
- and the values are a list of value dicts for each parameter:
795
- expected_parameters =
796
- { 'parameter_name_1': [param_dict_1, param_dict_2, ...],
797
- 'parameter_name_2': [param_dict_1, param_dict_2, ...],
798
- ...
799
- }
800
- where the param_dicts have the following format:
801
- sample_param_dict =
802
- { "parameterValueId": <param_id>,
803
- "parameterValue": <param_value>,
804
- "parameterValueStartDate": <start_date>
805
- }
836
+ Create the parameter files specified in the parameters document returned by the metadata store.
837
+
838
+ This fixture assumes that the JSON parameters document has already been loaded into a python
839
+ structure, but the parameter values themselves are still JSON.
806
840
  """
807
- # Loop over all the parameter values. Each value is a list of parameterValue dicts
808
- for expected_parameter_values in expected_parameters.values():
809
- for value_dict in expected_parameter_values:
810
- if "__file__" not in value_dict["parameterValue"]:
841
+ for parameter in parameters_doc:
842
+ for value in parameter["parameterValues"]:
843
+ if "__file__" not in value["parameterValue"]:
811
844
  continue
812
- value = json.loads(value_dict["parameterValue"])
813
- param_path = value["__file__"]["objectKey"]
845
+ parameter_value = json.loads(value["parameterValue"])
846
+ param_path = parameter_value["__file__"]["objectKey"]
814
847
  file_path = task.scratch.workflow_base_path / Path(param_path)
815
848
  if not file_path.parent.exists():
816
849
  file_path.parent.mkdir(parents=True, exist_ok=True)
@@ -308,26 +308,8 @@ def test_input_dataset_parameters(
308
308
  task = task_with_input_dataset
309
309
  doc_part, _ = input_dataset_parts
310
310
  doc_part = doc_part or [] # None case parsing of expected values
311
- """
312
- expected_parameters is a dict with the parameter names as the keys
313
- and the values are a list of value dicts for each parameter:
314
- expected_parameters =
315
- { 'parameter_name_1': [param_dict_1, param_dict_2, ...],
316
- 'parameter_name_2': [param_dict_1, param_dict_2, ...],
317
- ...
318
- }
319
- where the param_dicts have the following format:
320
- sample_param_dict =
321
- { "parameterValueId": <param_id>,
322
- "parameterValue": <param_value>,
323
- "parameterValueStartDate": <start_date>
324
- }
325
- """
326
- expected_parameters = dict()
327
- for item in doc_part:
328
- expected_parameters[item["parameterName"]] = item["parameterValues"]
329
- create_parameter_files(task, expected_parameters)
330
- # key is param name, values is list of InputDatasetParameterValue objects
311
+ create_parameter_files(task, doc_part)
312
+ expected_parameters = {item["parameterName"]: item["parameterValues"] for item in doc_part}
331
313
  for key, values in task.input_dataset_parameters.items():
332
314
  assert key in expected_parameters
333
315
  expected_values = expected_parameters[key]
@@ -18,13 +18,14 @@ class TeardownTest(Teardown):
18
18
 
19
19
  @pytest.fixture()
20
20
  def make_mock_GQL_with_configuration():
21
- def class_generator(configuration: dict):
21
+ def class_generator(teardown_option: bool | None):
22
22
  class TeardownFakeGQLClient(FakeGQLClient):
23
23
  def execute_gql_query(self, **kwargs):
24
24
  response = super().execute_gql_query(**kwargs)
25
25
  if isinstance(response, list):
26
26
  if isinstance(response[0], RecipeRunResponse):
27
- response[0].configuration = configuration
27
+ if isinstance(teardown_option, bool):
28
+ response[0].configuration.teardown_enabled = teardown_option
28
29
  return response
29
30
 
30
31
  return TeardownFakeGQLClient
@@ -33,18 +34,18 @@ def make_mock_GQL_with_configuration():
33
34
 
34
35
 
35
36
  @pytest.fixture(scope="session")
36
- def config_with_teardown_enabled() -> dict:
37
- return {"teardown_enabled": True}
37
+ def teardown_enabled() -> bool:
38
+ return True
38
39
 
39
40
 
40
41
  @pytest.fixture(scope="session")
41
- def config_with_teardown_disabled() -> dict:
42
- return {"teardown_enabled": False}
42
+ def teardown_disabled() -> bool:
43
+ return False
43
44
 
44
45
 
45
46
  @pytest.fixture(scope="session")
46
- def config_with_no_teardown() -> dict:
47
- return dict()
47
+ def teardown_default() -> None:
48
+ return None
48
49
 
49
50
 
50
51
  @pytest.fixture(scope="function")
@@ -75,14 +76,14 @@ def teardown_task_factory(tmp_path, recipe_run_id):
75
76
 
76
77
 
77
78
  def test_purge_data(
78
- teardown_task_factory, make_mock_GQL_with_configuration, config_with_teardown_enabled, mocker
79
+ teardown_task_factory, make_mock_GQL_with_configuration, teardown_enabled, mocker
79
80
  ):
80
81
  """
81
82
  :Given: A Teardown task with files and tags linked to it and teardown enabled
82
83
  :When: Running the task
83
84
  :Then: All the files are deleted and the tags are removed
84
85
  """
85
- FakeGQLClass = make_mock_GQL_with_configuration(config_with_teardown_enabled)
86
+ FakeGQLClass = make_mock_GQL_with_configuration(teardown_enabled)
86
87
  mocker.patch(
87
88
  "dkist_processing_common.tasks.mixin.metadata_store.GraphQLClient", new=FakeGQLClass
88
89
  )
@@ -102,14 +103,14 @@ def test_purge_data(
102
103
 
103
104
 
104
105
  def test_purge_data_disabled(
105
- teardown_task_factory, make_mock_GQL_with_configuration, config_with_teardown_disabled, mocker
106
+ teardown_task_factory, make_mock_GQL_with_configuration, teardown_disabled, mocker
106
107
  ):
107
108
  """
108
109
  :Given: A Teardown task with files and tags linked to it and teardown disabled
109
110
  :When: Running the task
110
111
  :Then: All the files are not deleted and the tags remain
111
112
  """
112
- FakeGQLClass = make_mock_GQL_with_configuration(config_with_teardown_disabled)
113
+ FakeGQLClass = make_mock_GQL_with_configuration(teardown_disabled)
113
114
  mocker.patch(
114
115
  "dkist_processing_common.tasks.mixin.metadata_store.GraphQLClient", new=FakeGQLClass
115
116
  )
@@ -129,14 +130,14 @@ def test_purge_data_disabled(
129
130
 
130
131
 
131
132
  def test_purge_data_no_config(
132
- teardown_task_factory, make_mock_GQL_with_configuration, config_with_no_teardown, mocker
133
+ teardown_task_factory, make_mock_GQL_with_configuration, teardown_default, mocker
133
134
  ):
134
135
  """
135
- :Given: A Teardown task with files and tags linked and teardown not specified in the configuration
136
+ :Given: A Teardown task with files and tags linked and default teardown configuration
136
137
  :When: Running the task
137
138
  :Then: All the files are deleted and the tags are removed
138
139
  """
139
- FakeGQLClass = make_mock_GQL_with_configuration(config_with_no_teardown)
140
+ FakeGQLClass = make_mock_GQL_with_configuration(teardown_default)
140
141
  mocker.patch(
141
142
  "dkist_processing_common.tasks.mixin.metadata_store.GraphQLClient", new=FakeGQLClass
142
143
  )