cocoindex 0.1.57__cp313-cp313-win_amd64.whl → 0.1.58__cp313-cp313-win_amd64.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.
Binary file
cocoindex/flow.py CHANGED
@@ -5,25 +5,27 @@ Flow is the main interface for building and running flows.
5
5
  from __future__ import annotations
6
6
 
7
7
  import asyncio
8
- import re
9
- import inspect
10
8
  import datetime
11
9
  import functools
10
+ import inspect
11
+ import re
12
+
13
+ from dataclasses import dataclass
14
+ from enum import Enum
15
+ from threading import Lock
12
16
  from typing import (
13
17
  Any,
14
18
  Callable,
19
+ Generic,
20
+ NamedTuple,
15
21
  Sequence,
16
22
  TypeVar,
17
- Generic,
23
+ cast,
18
24
  get_args,
19
25
  get_origin,
20
- NamedTuple,
21
- cast,
22
26
  Iterable,
23
27
  )
24
- from threading import Lock
25
- from enum import Enum
26
- from dataclasses import dataclass
28
+
27
29
  from rich.text import Text
28
30
  from rich.tree import Tree
29
31
 
@@ -32,9 +34,10 @@ from . import index
32
34
  from . import op
33
35
  from . import setting
34
36
  from .convert import dump_engine_object, encode_engine_value, make_engine_value_decoder
35
- from .typing import encode_enriched_type
37
+ from .op import FunctionSpec
36
38
  from .runtime import execution_context
37
39
  from .setup import SetupChangeBundle
40
+ from .typing import encode_enriched_type
38
41
 
39
42
 
40
43
  class _NameBuilder:
@@ -92,6 +95,30 @@ def _spec_kind(spec: Any) -> str:
92
95
  return cast(str, spec.__class__.__name__)
93
96
 
94
97
 
98
+ def _transform_helper(
99
+ flow_builder_state: _FlowBuilderState,
100
+ fn_spec: FunctionSpec,
101
+ transform_args: list[tuple[Any, str | None]],
102
+ name: str | None = None,
103
+ ) -> DataSlice[Any]:
104
+ if not isinstance(fn_spec, FunctionSpec):
105
+ raise ValueError("transform() can only be called on a CocoIndex function")
106
+
107
+ return _create_data_slice(
108
+ flow_builder_state,
109
+ lambda target_scope, name: flow_builder_state.engine_flow_builder.transform(
110
+ _spec_kind(fn_spec),
111
+ dump_engine_object(fn_spec),
112
+ transform_args,
113
+ target_scope,
114
+ flow_builder_state.field_name_builder.build_name(
115
+ name, prefix=_to_snake_case(_spec_kind(fn_spec)) + "_"
116
+ ),
117
+ ),
118
+ name,
119
+ )
120
+
121
+
95
122
  T = TypeVar("T")
96
123
  S = TypeVar("S")
97
124
 
@@ -191,31 +218,19 @@ class DataSlice(Generic[T]):
191
218
  """
192
219
  Apply a function to the data slice.
193
220
  """
194
- if not isinstance(fn_spec, op.FunctionSpec):
195
- raise ValueError("transform() can only be called on a CocoIndex function")
196
-
197
- transform_args: list[tuple[Any, str | None]]
198
- transform_args = [(self._state.engine_data_slice, None)]
221
+ transform_args: list[tuple[Any, str | None]] = [
222
+ (self._state.engine_data_slice, None)
223
+ ]
199
224
  transform_args += [
200
225
  (self._state.flow_builder_state.get_data_slice(v), None) for v in args
201
226
  ]
202
227
  transform_args += [
203
228
  (self._state.flow_builder_state.get_data_slice(v), k)
204
- for (k, v) in kwargs.items()
229
+ for k, v in kwargs.items()
205
230
  ]
206
231
 
207
- flow_builder_state = self._state.flow_builder_state
208
- return _create_data_slice(
209
- flow_builder_state,
210
- lambda target_scope, name: flow_builder_state.engine_flow_builder.transform(
211
- _spec_kind(fn_spec),
212
- dump_engine_object(fn_spec),
213
- transform_args,
214
- target_scope,
215
- flow_builder_state.field_name_builder.build_name(
216
- name, prefix=_to_snake_case(_spec_kind(fn_spec)) + "_"
217
- ),
218
- ),
232
+ return _transform_helper(
233
+ self._state.flow_builder_state, fn_spec, transform_args
219
234
  )
220
235
 
221
236
  def call(self, func: Callable[..., S], *args: Any, **kwargs: Any) -> S:
@@ -446,6 +461,24 @@ class FlowBuilder:
446
461
  name,
447
462
  )
448
463
 
464
+ def transform(
465
+ self, fn_spec: FunctionSpec, *args: Any, **kwargs: Any
466
+ ) -> DataSlice[Any]:
467
+ """
468
+ Apply a function to inputs, returning a DataSlice.
469
+ """
470
+ transform_args: list[tuple[Any, str | None]] = [
471
+ (self._state.get_data_slice(v), None) for v in args
472
+ ]
473
+ transform_args += [
474
+ (self._state.get_data_slice(v), k) for k, v in kwargs.items()
475
+ ]
476
+
477
+ if not transform_args:
478
+ raise ValueError("At least one input is required for transformation")
479
+
480
+ return _transform_helper(self._state, fn_spec, transform_args)
481
+
449
482
  def declare(self, spec: op.DeclarationSpec) -> None:
450
483
  """
451
484
  Add a declaration to the flow.
cocoindex/op.py CHANGED
@@ -5,13 +5,12 @@ Facilities for defining cocoindex operations.
5
5
  import asyncio
6
6
  import dataclasses
7
7
  import inspect
8
-
9
- from typing import Protocol, Any, Callable, Awaitable, dataclass_transform
10
8
  from enum import Enum
9
+ from typing import Any, Awaitable, Callable, Protocol, dataclass_transform
11
10
 
12
- from .typing import encode_enriched_type, resolve_forward_ref
13
- from .convert import encode_engine_value, make_engine_value_decoder
14
11
  from . import _engine # type: ignore
12
+ from .convert import encode_engine_value, make_engine_value_decoder
13
+ from .typing import encode_enriched_type, resolve_forward_ref
15
14
 
16
15
 
17
16
  class OpCategory(Enum):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cocoindex
3
- Version: 0.1.57
3
+ Version: 0.1.58
4
4
  Requires-Dist: click>=8.1.8
5
5
  Requires-Dist: rich>=14.0.0
6
6
  Requires-Dist: python-dotenv>=1.1.0
@@ -1,18 +1,18 @@
1
- cocoindex-0.1.57.dist-info/METADATA,sha256=QEM16muhnNyoKT3A7Uf8qjaJHt17cXCSC3MxHBqv3P8,10185
2
- cocoindex-0.1.57.dist-info/WHEEL,sha256=AUbk9LW_pz5a6zxr9a09TpfZobAyvDuruoOj7fuVtLM,96
3
- cocoindex-0.1.57.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
- cocoindex-0.1.57.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
1
+ cocoindex-0.1.58.dist-info/METADATA,sha256=e7gGcZ9UjhsNZfR79TbsUgrpUJDNGjG4oAtYxicsu14,10185
2
+ cocoindex-0.1.58.dist-info/WHEEL,sha256=AUbk9LW_pz5a6zxr9a09TpfZobAyvDuruoOj7fuVtLM,96
3
+ cocoindex-0.1.58.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
+ cocoindex-0.1.58.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
5
5
  cocoindex/__init__.py,sha256=e9T2v2r1WqVNn18Vz63U5paPEQeDaXfhtuaNl8VykTA,1951
6
- cocoindex/_engine.cp313-win_amd64.pyd,sha256=tnDfdga7x4YCqYfM5SOe6LElL8z5m42hAnyOPGL5o-0,61999104
6
+ cocoindex/_engine.cp313-win_amd64.pyd,sha256=ytuvy26GaEy0KSBfLUpIQRHUbeVuOyU7EvQBNXNM8Cw,62008832
7
7
  cocoindex/auth_registry.py,sha256=LojDKoX0ccO-G3bboFMlAti50_t5GK9BS0ouPJZfyUs,745
8
8
  cocoindex/cli.py,sha256=N3GJUmqaZeqEMcJC4zXvmKyqCd_1p44H2M7jegfUx7U,22053
9
9
  cocoindex/convert.py,sha256=Gvy2bw0YrhOhqx7EQpa-bZ1TxWREy6ur2sKwMK9J_h4,10522
10
- cocoindex/flow.py,sha256=tpEvpjmndRGBZnVoitja4JOOdrwVLcFWuMmbCE4w9S4,33229
10
+ cocoindex/flow.py,sha256=MuG-LLE3YnGufRtlolVj3KW6-ShER_7ybmQZfpg9-_I,34112
11
11
  cocoindex/functions.py,sha256=ShHLmFPN8DYqxUDFm4EUJhuoKlax8HdU7q69V47ljQo,3307
12
12
  cocoindex/index.py,sha256=GrqTm1rLwICQ8hadtNvJAxVg7GWMvtMmFcbiNtNzmP0,569
13
13
  cocoindex/lib.py,sha256=o2UGq3eWsZbK5nusZEU7Y0R6NTbT0i03G2ye8N6ATNg,3015
14
14
  cocoindex/llm.py,sha256=zc-5o6qWo8KBXa6a533jbmad5QoSBtJL9b7bj9SFehY,453
15
- cocoindex/op.py,sha256=Jk1KfRNBY4TEsbbhWHB5pEzNcMo_2T-FQR1Y75OUVhU,12143
15
+ cocoindex/op.py,sha256=h1bp56NEVxCRrOjzyta1h52u6d9Vol_Qau9Pv1sUlVE,12141
16
16
  cocoindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  cocoindex/runtime.py,sha256=saKEZntVwUVQNASRhiO9bHRVIFmQccemq2f9mo4mo1A,1090
18
18
  cocoindex/setting.py,sha256=dRNdX-rPBn321zGx6GGoSMggS4F2879A6EBLOUbX8R4,3717
@@ -25,4 +25,4 @@ cocoindex/tests/test_optional_database.py,sha256=dnzmTgaJf37D3q8fQsjP5UDER6FYETa
25
25
  cocoindex/tests/test_typing.py,sha256=6W2NQmyTj4LMuWegV5m4NVP2clVNrUa5eD28_3nwzjs,15300
26
26
  cocoindex/typing.py,sha256=T5BsXOArgXK4yoDSh9Fo-dzXGYYgsnRhLVOH1Z_42Ig,12985
27
27
  cocoindex/utils.py,sha256=U3W39zD2uZpXX8v84tJD7sRmbC5ar3z_ljAP1cJrYXI,618
28
- cocoindex-0.1.57.dist-info/RECORD,,
28
+ cocoindex-0.1.58.dist-info/RECORD,,