gpp-client 26.11.3.dev2__tar.gz → 26.12.0__tar.gz

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.
Files changed (119) hide show
  1. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/PKG-INFO +1 -1
  2. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/base.py +5 -2
  3. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/goats.py +1 -1
  4. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/workflow_state.py +105 -15
  5. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/exceptions.py +53 -0
  6. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/__init__.py +318 -776
  7. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/client.py +580 -1336
  8. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/custom_fields.py +18 -437
  9. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/custom_mutations.py +9 -47
  10. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/custom_queries.py +0 -55
  11. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/custom_typing_fields.py +2 -74
  12. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/enums.py +2 -9
  13. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/fragments.py +999 -0
  14. gpp_client-26.12.0/src/gpp_client/generated/get_goats_config_options.py +24 -0
  15. gpp_client-26.12.0/src/gpp_client/generated/get_goats_configuration_requests.py +25 -0
  16. gpp_client-26.12.0/src/gpp_client/generated/get_goats_observations.py +28 -0
  17. gpp_client-26.12.0/src/gpp_client/generated/get_goats_programs.py +21 -0
  18. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_observation_workflow_state_by_id.py +6 -1
  19. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_observation_workflow_state_by_reference.py +6 -1
  20. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_scheduler_programs.py +4 -49
  21. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/input_types.py +7 -323
  22. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/package_environment.py +1 -1
  23. gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_config_options.py +0 -119
  24. gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_configuration_requests.py +0 -209
  25. gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_observations.py +0 -2807
  26. gpp_client-26.11.3.dev2/src/gpp_client/generated/get_goats_programs.py +0 -49
  27. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/.gitignore +0 -0
  28. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/LICENSE +0 -0
  29. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/README.md +0 -0
  30. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/graphql/README.md +0 -0
  31. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/pyproject.toml +0 -0
  32. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/__init__.py +0 -0
  33. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/__init__.py +0 -0
  34. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/cli.py +0 -0
  35. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/__init__.py +0 -0
  36. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/attachment.py +0 -0
  37. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/goats.py +0 -0
  38. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/observation.py +0 -0
  39. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/program.py +0 -0
  40. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/scheduler.py +0 -0
  41. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/site_status.py +0 -0
  42. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/target.py +0 -0
  43. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/commands/workflow_state.py +0 -0
  44. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/console.py +0 -0
  45. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/output.py +0 -0
  46. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/cli/utils.py +0 -0
  47. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/client.py +0 -0
  48. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/constants.py +0 -0
  49. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/__init__.py +0 -0
  50. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/atom.py +0 -0
  51. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/attachment.py +0 -0
  52. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/observation.py +0 -0
  53. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/program.py +0 -0
  54. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/scheduler.py +0 -0
  55. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/site_status.py +0 -0
  56. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/domains/target.py +0 -0
  57. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/environment.py +0 -0
  58. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/async_base_client.py +0 -0
  59. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/base_model.py +0 -0
  60. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/base_operation.py +0 -0
  61. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/clone_observation.py +0 -0
  62. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/clone_target.py +0 -0
  63. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/create_call_for_proposals.py +0 -0
  64. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/create_observation.py +0 -0
  65. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/create_program.py +0 -0
  66. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/create_target_by_program_id.py +0 -0
  67. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/create_target_by_program_reference.py +0 -0
  68. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/create_target_by_proposal_reference.py +0 -0
  69. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/delete_call_for_proposals_by_id.py +0 -0
  70. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/delete_observation_by_id.py +0 -0
  71. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/delete_observation_by_reference.py +0 -0
  72. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/delete_program_by_id.py +0 -0
  73. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/delete_target_by_id.py +0 -0
  74. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/exceptions.py +0 -0
  75. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_call_for_proposals.py +0 -0
  76. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_calls_for_proposals.py +0 -0
  77. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_observation.py +0 -0
  78. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_observation_attachments_by_id.py +0 -0
  79. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_observation_attachments_by_reference.py +0 -0
  80. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_observations.py +0 -0
  81. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_program_attachments_by_id.py +0 -0
  82. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_program_attachments_by_proposal_reference.py +0 -0
  83. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_program_attachments_by_reference.py +0 -0
  84. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_program_by_id.py +0 -0
  85. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_program_by_proposal_reference.py +0 -0
  86. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_program_by_reference.py +0 -0
  87. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_programs.py +0 -0
  88. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_scheduler_all_programs_id.py +0 -0
  89. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_target_by_id.py +0 -0
  90. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/get_targets.py +0 -0
  91. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/obs_calculation_update.py +0 -0
  92. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/observation_edit.py +0 -0
  93. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/ping.py +0 -0
  94. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/program_edit.py +0 -0
  95. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/restore_call_for_proposals_by_id.py +0 -0
  96. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/restore_observation_by_id.py +0 -0
  97. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/restore_observation_by_reference.py +0 -0
  98. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/restore_program_by_id.py +0 -0
  99. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/restore_target_by_id.py +0 -0
  100. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/scheduler_executed_events.py +0 -0
  101. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/scheduler_observations_updates.py +0 -0
  102. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/set_observation_workflow_state.py +0 -0
  103. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/target_edit.py +0 -0
  104. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_call_for_proposals_by_id.py +0 -0
  105. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_calls_for_proposals.py +0 -0
  106. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_observation_by_id.py +0 -0
  107. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_observation_by_reference.py +0 -0
  108. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_observations.py +0 -0
  109. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_program_by_id.py +0 -0
  110. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_programs.py +0 -0
  111. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_target_by_id.py +0 -0
  112. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/generated/update_targets.py +0 -0
  113. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/logging_utils.py +0 -0
  114. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/rest/__init__.py +0 -0
  115. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/rest/client.py +0 -0
  116. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/rest/models.py +0 -0
  117. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/rest/utils.py +0 -0
  118. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/settings.py +0 -0
  119. {gpp_client-26.11.3.dev2 → gpp_client-26.12.0}/src/gpp_client/urls.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: gpp-client
3
- Version: 26.11.3.dev2
3
+ Version: 26.12.0
4
4
  Summary: Gemini Program Platform client.
5
5
  Project-URL: Homepage, https://github.com/gemini-hlsw/gpp-client
6
6
  Project-URL: Source, https://github.com/gemini-hlsw/gpp-client
@@ -52,6 +52,9 @@ class BaseDomain:
52
52
  """
53
53
  Raise a structured exception with contextual information.
54
54
 
55
+ The log line names the domain; the exception message does not, since
56
+ applications show it to their users.
57
+
55
58
  Parameters
56
59
  ----------
57
60
  exc_class : type[GPPError]
@@ -69,8 +72,8 @@ class BaseDomain:
69
72
  class_name = self.__class__.__name__
70
73
  # Fall back to the type name so an exception raised without a message
71
74
  # does not end up as an empty error.
72
- message = f"{class_name}: {str(exc) or type(exc).__name__}"
73
- logger.error(message, exc_info=include_traceback)
75
+ message = str(exc) or type(exc).__name__
76
+ logger.error("%s: %s", class_name, message, exc_info=include_traceback)
74
77
 
75
78
  if include_traceback:
76
79
  raise exc_class(message) from exc
@@ -24,7 +24,7 @@ class GOATSDomain(BaseDomain):
24
24
  program_id: str,
25
25
  ) -> GetGOATSObservations:
26
26
  """
27
- Get GOATS observations for a program.
27
+ Get GOATS observations for a program, and the program's time allocations.
28
28
 
29
29
  Parameters
30
30
  ----------
@@ -8,10 +8,17 @@ import asyncio
8
8
  import logging
9
9
 
10
10
  from gpp_client.domains.base import BaseDomain
11
- from gpp_client.exceptions import GPPClientError, GPPRetryableError, GPPValidationError
11
+ from gpp_client.exceptions import (
12
+ GPPClientError,
13
+ GPPRetryableError,
14
+ GPPValidationError,
15
+ GPPWorkflowTransitionError,
16
+ WorkflowReason,
17
+ )
12
18
  from gpp_client.generated.enums import CalculationState, ObservationWorkflowState
13
19
  from gpp_client.generated.get_observation_workflow_state_by_id import (
14
20
  GetObservationWorkflowStateById,
21
+ GetObservationWorkflowStateByIdObservation,
15
22
  GetObservationWorkflowStateByIdObservationWorkflow,
16
23
  )
17
24
  from gpp_client.generated.get_observation_workflow_state_by_reference import (
@@ -105,8 +112,8 @@ class WorkflowStateDomain(BaseDomain):
105
112
  ------
106
113
  GPPClientError
107
114
  If there are general client-side errors.
108
- GPPValidationError
109
- If the requested workflow state transition is invalid.
115
+ GPPWorkflowTransitionError
116
+ If GPP does not allow the requested state; it carries GPP's reasons.
110
117
  GPPRetryableError
111
118
  If the observation calculation is not ``READY``.
112
119
  """
@@ -137,11 +144,13 @@ class WorkflowStateDomain(BaseDomain):
137
144
  workflow.value.model_dump(by_alias=True)
138
145
  )
139
146
  )
140
- # Validate the requested workflow state against 'validTransitions'.
147
+ # Validate the requested workflow state against 'validTransitions'. The
148
+ # error goes out as raised, since raise_error would drop its reasons.
141
149
  try:
142
150
  _check_valid_transition(workflow, workflow_state)
143
- except ValueError as exc:
144
- self.raise_error(GPPValidationError, exc)
151
+ except GPPWorkflowTransitionError as exc:
152
+ logger.error("%s: %s", type(self).__name__, exc)
153
+ raise
145
154
 
146
155
  mutation_result = await self._graphql.set_observation_workflow_state(
147
156
  observation_id=observation_id,
@@ -222,12 +231,66 @@ class WorkflowStateDomain(BaseDomain):
222
231
  # This is the only retryable case: calculation state not READY.
223
232
  if attempt < max_attempts:
224
233
  await asyncio.sleep(retry_delay)
225
- except (GPPValidationError, GPPClientError) as exc:
226
- self.raise_error(type(exc), exc)
234
+ except (GPPValidationError, GPPClientError):
235
+ # update_by_id already logged it.
236
+ raise
227
237
 
228
238
  exc = GPPClientError("Failed to set workflow state after multiple retries.")
229
239
  self.raise_error(type(exc), exc)
230
240
 
241
+ async def get_by_id_when_ready(
242
+ self,
243
+ observation_id: str,
244
+ *,
245
+ max_attempts: int = 10,
246
+ initial_delay: float = 0.0,
247
+ retry_delay: float = 1.0,
248
+ ) -> GetObservationWorkflowStateByIdObservation:
249
+ """
250
+ Get an observation's workflow once GPP has finished calculating it.
251
+
252
+ After an edit, GPP recalculates the observation in the background, and its
253
+ workflow (state, valid transitions and validation errors) stays out of date
254
+ until the calculation state is ``READY``.
255
+
256
+ Parameters
257
+ ----------
258
+ observation_id : str
259
+ The observation ID.
260
+ max_attempts : int, default=10
261
+ Maximum number of times to ask.
262
+ initial_delay : float, default=0.0
263
+ Delay in seconds before asking the first time.
264
+ retry_delay : float, default=1.0
265
+ Delay in seconds between asks.
266
+
267
+ Returns
268
+ -------
269
+ GetObservationWorkflowStateByIdObservation
270
+ The observation, with its workflow as calculated and the warnings its
271
+ program dismissed, which do not keep it from ``READY``.
272
+
273
+ Raises
274
+ ------
275
+ GPPClientError
276
+ If GPP returns no such observation, or has not finished calculating it
277
+ after every attempt.
278
+ """
279
+ await asyncio.sleep(initial_delay)
280
+ for attempt in range(1, max_attempts + 1):
281
+ result = await self.get_by_id(observation_id=observation_id)
282
+ observation = result.observation
283
+ if observation is None or observation.workflow is None:
284
+ exc = GPPClientError(f"GPP returned no workflow for {observation_id}.")
285
+ self.raise_error(type(exc), exc)
286
+ if observation.workflow.state == CalculationState.READY:
287
+ return observation
288
+ if attempt < max_attempts:
289
+ await asyncio.sleep(retry_delay)
290
+
291
+ exc = GPPClientError("GPP did not finish calculating the observation in time.")
292
+ self.raise_error(type(exc), exc)
293
+
231
294
 
232
295
  def _check_ready(workflow: GetObservationWorkflowStateByIdObservationWorkflow) -> None:
233
296
  """
@@ -290,14 +353,41 @@ def _check_valid_transition(
290
353
 
291
354
  Raises
292
355
  ------
293
- ValueError
356
+ GPPWorkflowTransitionError
294
357
  If the requested transition is not allowed based on
295
- ``validTransitions``.
358
+ ``validTransitions``. It carries GPP's validation messages, which say
359
+ why (for example, that no science band is selected), errors first. Its
360
+ message gives them too, or else the states GPP allows.
296
361
  """
297
362
  valid_transitions = workflow.value.valid_transitions or []
298
- if workflow_state not in valid_transitions:
299
- valid_str = ", ".join(t.value for t in valid_transitions) or "None"
300
- raise ValueError(
301
- f"Cannot transition to '{workflow_state.value}'. "
302
- f"Valid transitions are: {valid_str}."
363
+ if workflow_state in valid_transitions:
364
+ return
365
+
366
+ # A code GPP sends without messages is still a reason.
367
+ reasons = [
368
+ WorkflowReason(
369
+ severity=error.severity.value,
370
+ code=error.code.value,
371
+ message=message,
372
+ )
373
+ for error in workflow.value.validation_errors or []
374
+ for message in (error.messages or [error.code.value])
375
+ ]
376
+ # Errors are what keeps the state from changing, so they come first.
377
+ reasons.sort(key=lambda reason: reason.severity != "ERROR")
378
+ allowed = [t.value for t in valid_transitions]
379
+
380
+ if reasons:
381
+ text = " ".join(reason.message for reason in reasons)
382
+ message = f"Cannot change to {workflow_state.value}: {text}"
383
+ else:
384
+ message = (
385
+ f"Cannot change to {workflow_state.value}. "
386
+ f"GPP allows: {', '.join(allowed) or 'none'}."
303
387
  )
388
+ raise GPPWorkflowTransitionError(
389
+ message,
390
+ requested=workflow_state.value,
391
+ allowed=allowed,
392
+ reasons=reasons,
393
+ )
@@ -10,9 +10,13 @@ __all__ = [
10
10
  "GPPTimeoutError",
11
11
  "GPPResponseError",
12
12
  "GPPValidationError",
13
+ "GPPWorkflowTransitionError",
13
14
  "GPPRetryableError",
15
+ "WorkflowReason",
14
16
  ]
15
17
 
18
+ from dataclasses import dataclass
19
+
16
20
 
17
21
  class GPPError(Exception):
18
22
  """
@@ -38,6 +42,55 @@ class GPPValidationError(GPPClientError):
38
42
  pass
39
43
 
40
44
 
45
+ @dataclass(frozen=True)
46
+ class WorkflowReason:
47
+ """
48
+ One of GPP's reasons about an observation's workflow, word for word.
49
+
50
+ Attributes
51
+ ----------
52
+ severity : str
53
+ ``"ERROR"`` when it has to be fixed, ``"WARNING"`` when it only has to be
54
+ reviewed (GPP keeps the observation from ``READY`` until it is dismissed).
55
+ code : str
56
+ GPP's ``ObservationValidationCode``.
57
+ message : str
58
+ GPP's text.
59
+ """
60
+
61
+ severity: str
62
+ code: str
63
+ message: str
64
+
65
+
66
+ class GPPWorkflowTransitionError(GPPValidationError):
67
+ """
68
+ Raised when GPP does not allow the requested workflow state.
69
+
70
+ Attributes
71
+ ----------
72
+ requested : str
73
+ The state asked for.
74
+ allowed : list[str]
75
+ The states GPP allows from the current one.
76
+ reasons : list[WorkflowReason]
77
+ GPP's reasons, errors before warnings. Empty when GPP gives none.
78
+ """
79
+
80
+ def __init__(
81
+ self,
82
+ message: str,
83
+ *,
84
+ requested: str,
85
+ allowed: list[str],
86
+ reasons: list[WorkflowReason],
87
+ ) -> None:
88
+ super().__init__(message)
89
+ self.requested = requested
90
+ self.allowed = allowed
91
+ self.reasons = reasons
92
+
93
+
41
94
  class GPPRetryableError(GPPError):
42
95
  """
43
96
  Raised for errors that may be transient and worth retrying.