cocoindex 0.2.9__cp311-abi3-macosx_10_12_x86_64.whl → 0.2.10__cp311-abi3-macosx_10_12_x86_64.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.
cocoindex/__init__.py CHANGED
@@ -6,7 +6,12 @@ from . import functions, sources, targets, cli, utils
6
6
 
7
7
  from . import targets as storages # Deprecated: Use targets instead
8
8
 
9
- from .auth_registry import AuthEntryReference, add_auth_entry, add_transient_auth_entry
9
+ from .auth_registry import (
10
+ AuthEntryReference,
11
+ add_auth_entry,
12
+ add_transient_auth_entry,
13
+ ref_auth_entry,
14
+ )
10
15
  from .flow import FlowBuilder, DataScope, DataSlice, Flow, transform_flow
11
16
  from .flow import flow_def
12
17
  from .flow import EvaluateAndDumpOptions, GeneratedField
@@ -14,7 +19,7 @@ from .flow import FlowLiveUpdater, FlowLiveUpdaterOptions, FlowUpdaterStatusUpda
14
19
  from .flow import open_flow
15
20
  from .flow import add_flow_def, remove_flow # DEPRECATED
16
21
  from .flow import update_all_flows_async, setup_all_flows, drop_all_flows
17
- from .lib import init, start_server, stop
22
+ from .lib import settings, init, start_server, stop
18
23
  from .llm import LlmSpec, LlmApiType
19
24
  from .index import VectorSimilarityMetric, VectorIndexDef, IndexOptions
20
25
  from .setting import DatabaseConnectionSpec, Settings, ServerSettings
@@ -65,6 +70,7 @@ __all__ = [
65
70
  "setup_all_flows",
66
71
  "drop_all_flows",
67
72
  # Lib
73
+ "settings",
68
74
  "init",
69
75
  "start_server",
70
76
  "stop",
cocoindex/_engine.abi3.so CHANGED
Binary file
cocoindex/cli.py CHANGED
@@ -91,8 +91,6 @@ def _load_user_app(app_target: str) -> None:
91
91
 
92
92
 
93
93
  def _initialize_cocoindex_in_process() -> None:
94
- settings = setting.Settings.from_env()
95
- lib.init(settings)
96
94
  atexit.register(lib.stop)
97
95
 
98
96
 
cocoindex/flow.py CHANGED
@@ -694,16 +694,11 @@ class Flow:
694
694
  """
695
695
 
696
696
  _name: str
697
- _full_name: str
698
697
  _lazy_engine_flow: Callable[[], _engine.Flow] | None
699
698
 
700
- def __init__(
701
- self, name: str, full_name: str, engine_flow_creator: Callable[[], _engine.Flow]
702
- ):
699
+ def __init__(self, name: str, engine_flow_creator: Callable[[], _engine.Flow]):
703
700
  validate_flow_name(name)
704
- validate_full_flow_name(full_name)
705
701
  self._name = name
706
- self._full_name = full_name
707
702
  engine_flow = None
708
703
  lock = Lock()
709
704
 
@@ -762,7 +757,7 @@ class Flow:
762
757
  """
763
758
  Get the full name of the flow.
764
759
  """
765
- return self._full_name
760
+ return get_flow_full_name(self._name)
766
761
 
767
762
  def update(self, /, *, reexport_targets: bool = False) -> _engine.IndexUpdateInfo:
768
763
  """
@@ -861,9 +856,10 @@ def _create_lazy_flow(
861
856
  The flow will be built the first time when it's really needed.
862
857
  """
863
858
  flow_name = _flow_name_builder.build_name(name, prefix="_flow_")
864
- flow_full_name = get_flow_full_name(flow_name)
865
859
 
866
860
  def _create_engine_flow() -> _engine.Flow:
861
+ flow_full_name = get_flow_full_name(flow_name)
862
+ validate_full_flow_name(flow_full_name)
867
863
  flow_builder_state = _FlowBuilderState(flow_full_name)
868
864
  root_scope = DataScope(
869
865
  flow_builder_state, flow_builder_state.engine_flow_builder.root_scope()
@@ -873,7 +869,7 @@ def _create_lazy_flow(
873
869
  execution_context.event_loop
874
870
  )
875
871
 
876
- return Flow(flow_name, flow_full_name, _create_engine_flow)
872
+ return Flow(flow_name, _create_engine_flow)
877
873
 
878
874
 
879
875
  _flows_lock = Lock()
cocoindex/lib.py CHANGED
@@ -2,12 +2,57 @@
2
2
  Library level functions and states.
3
3
  """
4
4
 
5
+ import threading
5
6
  import warnings
6
- from typing import Callable, Any
7
7
 
8
8
  from . import _engine # type: ignore
9
9
  from . import flow, setting
10
10
  from .convert import dump_engine_object
11
+ from .validation import validate_app_namespace_name
12
+ from typing import Any, Callable, overload
13
+
14
+
15
+ def prepare_settings(settings: setting.Settings) -> Any:
16
+ """Prepare the settings for the engine."""
17
+ if settings.app_namespace:
18
+ validate_app_namespace_name(settings.app_namespace)
19
+ return dump_engine_object(settings)
20
+
21
+
22
+ _engine.set_settings_fn(lambda: prepare_settings(setting.Settings.from_env()))
23
+
24
+
25
+ _prev_settings_fn: Callable[[], setting.Settings] | None = None
26
+ _prev_settings_fn_lock: threading.Lock = threading.Lock()
27
+
28
+
29
+ @overload
30
+ def settings(fn: Callable[[], setting.Settings]) -> Callable[[], setting.Settings]: ...
31
+ @overload
32
+ def settings(
33
+ fn: None,
34
+ ) -> Callable[[Callable[[], setting.Settings]], Callable[[], setting.Settings]]: ...
35
+ def settings(fn: Callable[[], setting.Settings] | None = None) -> Any:
36
+ """
37
+ Decorate a function that returns a settings.Settings object.
38
+ It registers the function as a settings provider.
39
+ """
40
+
41
+ def _inner(fn: Callable[[], setting.Settings]) -> Callable[[], setting.Settings]:
42
+ global _prev_settings_fn # pylint: disable=global-statement
43
+ with _prev_settings_fn_lock:
44
+ if _prev_settings_fn is not None:
45
+ warnings.warn(
46
+ f"Setting a new settings function will override the previous one {_prev_settings_fn}."
47
+ )
48
+ _prev_settings_fn = fn
49
+ _engine.set_settings_fn(lambda: prepare_settings(fn()))
50
+ return fn
51
+
52
+ if fn is not None:
53
+ return _inner(fn)
54
+ else:
55
+ return _inner
11
56
 
12
57
 
13
58
  def init(settings: setting.Settings | None = None) -> None:
@@ -16,9 +61,7 @@ def init(settings: setting.Settings | None = None) -> None:
16
61
 
17
62
  If the settings are not provided, they are loaded from the environment variables.
18
63
  """
19
- settings = settings or setting.Settings.from_env()
20
- _engine.init(dump_engine_object(settings))
21
- setting.set_app_namespace(settings.app_namespace)
64
+ _engine.init(prepare_settings(settings) if settings is not None else None)
22
65
 
23
66
 
24
67
  def start_server(settings: setting.ServerSettings) -> None:
cocoindex/setting.py CHANGED
@@ -6,16 +6,15 @@ import os
6
6
 
7
7
  from typing import Callable, Self, Any, overload
8
8
  from dataclasses import dataclass
9
- from .validation import validate_app_namespace_name
10
-
11
- _app_namespace: str = ""
9
+ from . import _engine # type: ignore
12
10
 
13
11
 
14
12
  def get_app_namespace(*, trailing_delimiter: str | None = None) -> str:
15
13
  """Get the application namespace. Append the `trailing_delimiter` if not empty."""
16
- if _app_namespace == "" or trailing_delimiter is None:
17
- return _app_namespace
18
- return f"{_app_namespace}{trailing_delimiter}"
14
+ app_namespace: str = _engine.get_app_namespace()
15
+ if app_namespace == "" or trailing_delimiter is None:
16
+ return app_namespace
17
+ return f"{app_namespace}{trailing_delimiter}"
19
18
 
20
19
 
21
20
  def split_app_namespace(full_name: str, delimiter: str) -> tuple[str, str]:
@@ -26,14 +25,6 @@ def split_app_namespace(full_name: str, delimiter: str) -> tuple[str, str]:
26
25
  return (parts[0], parts[1])
27
26
 
28
27
 
29
- def set_app_namespace(app_namespace: str) -> None:
30
- """Set the application namespace."""
31
- if app_namespace:
32
- validate_app_namespace_name(app_namespace)
33
- global _app_namespace # pylint: disable=global-statement
34
- _app_namespace = app_namespace
35
-
36
-
37
28
  @dataclass
38
29
  class DatabaseConnectionSpec:
39
30
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cocoindex
3
- Version: 0.2.9
3
+ Version: 0.2.10
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: License :: OSI Approved :: Apache Software License
6
6
  Classifier: Operating System :: OS Independent
@@ -1,21 +1,21 @@
1
- cocoindex-0.2.9.dist-info/METADATA,sha256=pAGAALnR660k-iGmmhH0NMTqmJx2eILu99lkLDXBerc,12998
2
- cocoindex-0.2.9.dist-info/WHEEL,sha256=N8W3-0eDM6igWj-H12r7VkxoMaJIqJLxUyWCFstEaGg,105
3
- cocoindex-0.2.9.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
- cocoindex-0.2.9.dist-info/licenses/THIRD_PARTY_NOTICES.html,sha256=F5Dm7y2cDyW5bZNG8a0bGXes0pVKHiaMrbcedg7chCk,716358
5
- cocoindex/__init__.py,sha256=sLpSVO5Cotgn_82lawxvXnaqfa-qj33rytWBAe2MTtU,2201
6
- cocoindex/_engine.abi3.so,sha256=RVxFkpK8U7yrI3YhtD8VnmRABOBkAdPvmpw8wmE1gPQ,69364420
1
+ cocoindex-0.2.10.dist-info/METADATA,sha256=W1EtSw4PWmq2rT-jS5OA_3x85UIXrJmgtyJLRo7Zhgc,12999
2
+ cocoindex-0.2.10.dist-info/WHEEL,sha256=N8W3-0eDM6igWj-H12r7VkxoMaJIqJLxUyWCFstEaGg,105
3
+ cocoindex-0.2.10.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
+ cocoindex-0.2.10.dist-info/licenses/THIRD_PARTY_NOTICES.html,sha256=s4PFFZPP5i9n3Gw4VuPYKYYU5pc2bK9W9ipjRkQoygw,717804
5
+ cocoindex/__init__.py,sha256=r0WRAMjHW5gq85fgvxD_EcWW1um4irffpY-ifMrnhKw,2264
6
+ cocoindex/_engine.abi3.so,sha256=MXkLdSPva8dt-wMRatsdelrGHLsCFyFqp0IyttZwuUw,69966180
7
7
  cocoindex/auth_registry.py,sha256=PE1-kVkcyC1G2C_V7b1kvYzeq73OFQehWKQP7ln7fJ8,1478
8
- cocoindex/cli.py,sha256=laLLHtEQvEt7Ua4xulsWEI_dH5IpHiaXyTWY8p1VF_c,21665
8
+ cocoindex/cli.py,sha256=69X30bFTFdM7c0_6lgIHR19CeQ7UEkobEQYihy8IdOQ,21599
9
9
  cocoindex/convert.py,sha256=Eh9Co37BtW_PK3Oi-pFEiFt8cc_6g7XLcurV-NeH6GU,22090
10
- cocoindex/flow.py,sha256=wKT_RWeB9_sm764aNrOl2XU-RJIu4EK_sIkjcyZI8jA,37669
10
+ cocoindex/flow.py,sha256=GGk2wtCGfP9cfgdk23SmwR2yBLAuoCDvBGmzmp-XEzM,37591
11
11
  cocoindex/functions.py,sha256=09erNt3WbzY9l1KER-akBF2O5-6xEahV2ORBECaL6yk,12260
12
12
  cocoindex/index.py,sha256=j93B9jEvvLXHtpzKWL88SY6wCGEoPgpsQhEGHlyYGFg,540
13
- cocoindex/lib.py,sha256=f--9dAYd84CZosbDZqNW0oGbBLsY3dXiUTR1VrfQ_QY,817
13
+ cocoindex/lib.py,sha256=0XheDF7fiFdqExpdqzU-VKun_Zll6DwZ5JfTm7u42aY,2284
14
14
  cocoindex/llm.py,sha256=Pv_cdnRngTLtuLU9AUmS8izIHhcKVnuBNolC33f9BDI,851
15
15
  cocoindex/op.py,sha256=3jTEpmzHPjg-euZhXjQqgF0i8V2LHUdkq7bp4AAIHRM,21627
16
16
  cocoindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  cocoindex/runtime.py,sha256=povilB3HH3y1JF-yxKwU-pD8n2WnAqyQxIgvXXHNc60,1080
18
- cocoindex/setting.py,sha256=rynB2qriPXysEDXp1YV_riqfyiGInR62tcWeDu8MMko,5214
18
+ cocoindex/setting.py,sha256=1Dx8ktjwf-8BiXrbsmfn5Mzudb2SQYqFdRnSNGVKaLk,4960
19
19
  cocoindex/setup.py,sha256=7uIHKN4FOCuoidPXcKyGTrkqpkl9luL49-6UcnMxYzw,3068
20
20
  cocoindex/sources.py,sha256=FYz7cWYasLGDaYoIEQ1dF2uprgUETHWsTIrIS7n6pQE,3188
21
21
  cocoindex/subprocess_exec.py,sha256=r1xO84uek4VP4I6i87JMwsH5xFm3vKW0ABvgn0jskt4,10088
@@ -30,4 +30,4 @@ cocoindex/typing.py,sha256=lEQYIzAGVKQp6RnhyeopY9Q7xEED7yQj3ZMxvTPblV8,14200
30
30
  cocoindex/user_app_loader.py,sha256=bc3Af-gYRxJ9GpObtpjegZY855oQBCv5FGkrkWV2yGY,1873
31
31
  cocoindex/utils.py,sha256=hUhX-XV6XGCtJSEIpBOuDv6VvqImwPlgBxztBTw7u0U,598
32
32
  cocoindex/validation.py,sha256=PZnJoby4sLbsmPv9fOjOQXuefjfZ7gmtsiTGU8SH-tc,3090
33
- cocoindex-0.2.9.dist-info/RECORD,,
33
+ cocoindex-0.2.10.dist-info/RECORD,,
@@ -45,7 +45,7 @@
45
45
  <h2>Overview of licenses:</h2>
46
46
  <ul class="licenses-overview">
47
47
  <li><a href="#Apache-2.0">Apache License 2.0</a> (412)</li>
48
- <li><a href="#MIT">MIT License</a> (124)</li>
48
+ <li><a href="#MIT">MIT License</a> (125)</li>
49
49
  <li><a href="#Unicode-3.0">Unicode License v3</a> (19)</li>
50
50
  <li><a href="#ISC">ISC License</a> (8)</li>
51
51
  <li><a href="#BSD-3-Clause">BSD 3-Clause &quot;New&quot; or &quot;Revised&quot; License</a> (6)</li>
@@ -2428,7 +2428,7 @@ Software.
2428
2428
  <h3 id="Apache-2.0">Apache License 2.0</h3>
2429
2429
  <h4>Used by:</h4>
2430
2430
  <ul class="license-used-by">
2431
- <li><a href=" https://crates.io/crates/cocoindex ">cocoindex 0.2.9</a></li>
2431
+ <li><a href=" https://crates.io/crates/cocoindex ">cocoindex 0.2.10</a></li>
2432
2432
  <li><a href=" https://github.com/awesomized/crc-fast-rust ">crc-fast 1.3.0</a></li>
2433
2433
  <li><a href=" https://github.com/qdrant/rust-client ">qdrant-client 1.15.0</a></li>
2434
2434
  </ul>
@@ -11376,6 +11376,20 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
11376
11376
  IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
11377
11377
  DEALINGS IN THE SOFTWARE.
11378
11378
  </pre>
11379
+ </li>
11380
+ <li class="license">
11381
+ <h3 id="MIT">MIT License</h3>
11382
+ <h4>Used by:</h4>
11383
+ <ul class="license-used-by">
11384
+ <li><a href=" https://github.com/JoranHonig/tree-sitter-solidity ">tree-sitter-solidity 1.2.13</a></li>
11385
+ </ul>
11386
+ <pre class="license-text">Copyright (c) 2020 Joran Honig
11387
+
11388
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11389
+
11390
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11391
+
11392
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</pre>
11379
11393
  </li>
11380
11394
  <li class="license">
11381
11395
  <h3 id="MIT">MIT License</h3>