nv-ingest-api 2025.2.23.dev20250223233319__py3-none-any.whl → 2025.2.24.dev20250224233318__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.

Potentially problematic release.


This version of nv-ingest-api might be problematic. Click here for more details.

@@ -1,10 +1,12 @@
1
+ from uuid import UUID
2
+
1
3
  from pydantic import BaseModel, Field, ConfigDict
2
- from typing import Any, Dict
4
+ from typing import Any, Dict, Union
3
5
 
4
6
 
5
7
  class ControlMessageTask(BaseModel):
6
8
  model_config = ConfigDict(extra="forbid")
7
9
 
8
- name: str
9
- id: str
10
+ type: str
11
+ id: Union[str, UUID]
10
12
  properties: Dict[str, Any] = Field(default_factory=dict)
@@ -12,6 +12,46 @@ from nv_ingest_api.primitives.control_message_task import ControlMessageTask
12
12
  logger = logging.getLogger(__name__)
13
13
 
14
14
 
15
+ def remove_task_by_type(ctrl_msg, task: str):
16
+ """
17
+ Remove a task from the control message by matching its type.
18
+
19
+ This function iterates over the tasks in the control message, and if it finds a task
20
+ whose type matches the provided task string, it removes that task (using its unique id)
21
+ and returns the task's properties.
22
+
23
+ Parameters
24
+ ----------
25
+ ctrl_msg : IngestControlMessage
26
+ The control message from which to remove the task.
27
+ task : str
28
+ The task type to remove.
29
+
30
+ Returns
31
+ -------
32
+ dict
33
+ The properties of the removed task.
34
+
35
+ Raises
36
+ ------
37
+ ValueError
38
+ If no task with the given type is found.
39
+ """
40
+ task_obj = None
41
+ for t in ctrl_msg.get_tasks():
42
+ if t.type == task:
43
+ task_obj = t
44
+ break
45
+
46
+ if task_obj is None:
47
+ err_msg = f"process_control_message: Task '{task}' not found in control message."
48
+ logger.error(err_msg)
49
+ raise ValueError(err_msg)
50
+
51
+ removed_task = ctrl_msg.remove_task(task_obj.id)
52
+ return removed_task.properties
53
+
54
+
15
55
  class IngestControlMessage:
16
56
  """
17
57
  A control message class for ingesting tasks and managing associated metadata,
@@ -53,14 +93,18 @@ class IngestControlMessage:
53
93
  """
54
94
  return task_id in self._tasks
55
95
 
56
- def remove_task(self, task_id: str) -> None:
96
+ def remove_task(self, task_id: str) -> ControlMessageTask:
57
97
  """
58
98
  Remove a task from the control message. Logs a warning if the task does not exist.
59
99
  """
60
100
  if task_id in self._tasks:
101
+ _task = self._tasks[task_id]
102
+
61
103
  del self._tasks[task_id]
104
+
105
+ return _task
62
106
  else:
63
- logger.warning(f"Attempted to remove non-existent task with id: {task_id}")
107
+ raise RuntimeError(f"Attempted to remove non-existent task with id: {task_id}")
64
108
 
65
109
  def config(self, config: Dict[str, Any] = None) -> Dict[str, Any]:
66
110
  """
@@ -154,7 +198,8 @@ class IngestControlMessage:
154
198
  Retrieve timestamps whose keys match the regex filter.
155
199
  """
156
200
  pattern = re.compile(regex_filter)
157
- return {key: ts for key, ts in self._timestamps.items() if pattern.search(key)}
201
+ timestamps_snapshot = self._timestamps.copy()
202
+ return {key: ts for key, ts in timestamps_snapshot.items() if pattern.search(key)}
158
203
 
159
204
  def get_timestamp(self, key: str, fail_if_nonexist: bool = False) -> datetime:
160
205
  """
@@ -188,12 +233,14 @@ class IngestControlMessage:
188
233
  """
189
234
  if isinstance(timestamp, datetime):
190
235
  self._timestamps[key] = timestamp
236
+
191
237
  elif isinstance(timestamp, str):
192
238
  try:
193
239
  dt = datetime.fromisoformat(timestamp)
194
240
  self._timestamps[key] = dt
195
241
  except ValueError as e:
196
242
  raise ValueError(f"Invalid timestamp format: {timestamp}") from e
243
+
197
244
  else:
198
245
  raise ValueError("timestamp must be a datetime object or ISO format string")
199
246
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nv-ingest-api
3
- Version: 2025.2.23.dev20250223233319
3
+ Version: 2025.2.24.dev20250224233318
4
4
  Summary: Python module with core document ingestion functions.
5
5
  Author-email: Jeremy Dyer <jdyer@nvidia.com>
6
6
  License: Apache License
@@ -0,0 +1,9 @@
1
+ nv_ingest_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ nv_ingest_api/primitives/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ nv_ingest_api/primitives/control_message_task.py,sha256=D2NCO6RyJyWZT6Vc2UBpZ6KdYstrTxwuVjPLEX9iQX8,295
4
+ nv_ingest_api/primitives/ingest_control_message.py,sha256=DF6ibcqPE1qiMk7isOL8x1ZlfDLCf6vWvCVUVvMq2Us,8362
5
+ nv_ingest_api-2025.2.24.dev20250224233318.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
+ nv_ingest_api-2025.2.24.dev20250224233318.dist-info/METADATA,sha256=1x2-8hcEU4DNYp4QTj2Pu9zsZHiXxY27R9f07OICZnU,13873
7
+ nv_ingest_api-2025.2.24.dev20250224233318.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ nv_ingest_api-2025.2.24.dev20250224233318.dist-info/top_level.txt,sha256=abjYMlTJGoG5tOdfIB-IWvLyKclw6HLaRSc8MxX4X6I,14
9
+ nv_ingest_api-2025.2.24.dev20250224233318.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- nv_ingest_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- nv_ingest_api/primitives/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- nv_ingest_api/primitives/control_message_task.py,sha256=ZsG-z1IZq60FxLXsb8q3riJ2gjjzb5GtuxQ_RamezNI,252
4
- nv_ingest_api/primitives/ingest_control_message.py,sha256=d5e03zg-1MEkcYZpjVfGwJabo_XnStP0b76QGBckME0,7134
5
- nv_ingest_api-2025.2.23.dev20250223233319.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- nv_ingest_api-2025.2.23.dev20250223233319.dist-info/METADATA,sha256=4HGJ5q7mpAKxvz7AtTHH1s-ZKk8oY38gNWEVVXYKwQE,13873
7
- nv_ingest_api-2025.2.23.dev20250223233319.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
- nv_ingest_api-2025.2.23.dev20250223233319.dist-info/top_level.txt,sha256=abjYMlTJGoG5tOdfIB-IWvLyKclw6HLaRSc8MxX4X6I,14
9
- nv_ingest_api-2025.2.23.dev20250223233319.dist-info/RECORD,,