cocoindex 0.2.3__cp311-abi3-macosx_11_0_arm64.whl → 0.2.4__cp311-abi3-macosx_11_0_arm64.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/_engine.abi3.so CHANGED
Binary file
cocoindex/cli.py CHANGED
@@ -5,6 +5,7 @@ import importlib.util
5
5
  import os
6
6
  import signal
7
7
  import threading
8
+ import sys
8
9
  from types import FrameType
9
10
  from typing import Any, Iterable
10
11
 
@@ -19,9 +20,8 @@ from . import flow, lib, setting
19
20
  from .setup import flow_names_with_setup
20
21
  from .runtime import execution_context
21
22
  from .subprocess_exec import add_user_app
22
- from .user_app_loader import load_user_app
23
+ from .user_app_loader import load_user_app, Error as UserAppLoaderError
23
24
 
24
- # Create ServerSettings lazily upon first call, as environment variables may be loaded from files, etc.
25
25
  COCOINDEX_HOST = "https://cocoindex.io"
26
26
 
27
27
 
@@ -77,7 +77,16 @@ def _get_app_ref_from_specifier(
77
77
 
78
78
 
79
79
  def _load_user_app(app_target: str) -> None:
80
- load_user_app(app_target)
80
+ if not app_target:
81
+ raise click.ClickException("Application target not provided.")
82
+
83
+ try:
84
+ load_user_app(app_target)
85
+ except UserAppLoaderError as e:
86
+ raise click.ClickException(
87
+ f"Failed to load APP_TARGET '{app_target}': {e}"
88
+ ) from e
89
+
81
90
  add_user_app(app_target)
82
91
 
83
92
 
@@ -99,7 +108,13 @@ def _initialize_cocoindex_in_process() -> None:
99
108
  default=None,
100
109
  show_default=False,
101
110
  )
102
- def cli(env_file: str | None = None) -> None:
111
+ @click.option(
112
+ "--app-dir",
113
+ help="Load apps from the specified directory. Default to the current directory.",
114
+ default="",
115
+ show_default=True,
116
+ )
117
+ def cli(env_file: str | None = None, app_dir: str | None = "") -> None:
103
118
  """
104
119
  CLI for Cocoindex.
105
120
  """
@@ -109,6 +124,9 @@ def cli(env_file: str | None = None) -> None:
109
124
  loaded_env_path = os.path.abspath(dotenv_path)
110
125
  click.echo(f"Loaded environment variables from: {loaded_env_path}\n", err=True)
111
126
 
127
+ if app_dir is not None:
128
+ sys.path.insert(0, app_dir)
129
+
112
130
  try:
113
131
  _initialize_cocoindex_in_process()
114
132
  except Exception as e:
@@ -1,23 +1,27 @@
1
1
  import os
2
2
  import sys
3
3
  import importlib
4
- import click
5
4
  import types
6
5
 
7
6
 
7
+ class Error(Exception):
8
+ """
9
+ Exception raised when a user app target is invalid or cannot be loaded.
10
+ """
11
+
12
+ pass
13
+
14
+
8
15
  def load_user_app(app_target: str) -> types.ModuleType:
9
16
  """
10
17
  Loads the user's application, which can be a file path or an installed module name.
11
18
  Exits on failure.
12
19
  """
13
- if not app_target:
14
- raise click.ClickException("Application target not provided.")
15
-
16
20
  looks_like_path = os.sep in app_target or app_target.lower().endswith(".py")
17
21
 
18
22
  if looks_like_path:
19
23
  if not os.path.isfile(app_target):
20
- raise click.ClickException(f"Application file path not found: {app_target}")
24
+ raise Error(f"Application file path not found: {app_target}")
21
25
  app_path = os.path.abspath(app_target)
22
26
  app_dir = os.path.dirname(app_path)
23
27
  module_name = os.path.splitext(os.path.basename(app_path))[0]
@@ -35,7 +39,7 @@ def load_user_app(app_target: str) -> types.ModuleType:
35
39
  spec.loader.exec_module(module)
36
40
  return module
37
41
  except (ImportError, FileNotFoundError, PermissionError) as e:
38
- raise click.ClickException(f"Failed importing file '{app_path}': {e}")
42
+ raise Error(f"Failed importing file '{app_path}': {e}") from e
39
43
  finally:
40
44
  if app_dir in sys.path and sys.path[0] == app_dir:
41
45
  sys.path.pop(0)
@@ -44,8 +48,6 @@ def load_user_app(app_target: str) -> types.ModuleType:
44
48
  try:
45
49
  return importlib.import_module(app_target)
46
50
  except ImportError as e:
47
- raise click.ClickException(f"Failed to load module '{app_target}': {e}")
51
+ raise Error(f"Failed to load module '{app_target}': {e}") from e
48
52
  except Exception as e:
49
- raise click.ClickException(
50
- f"Unexpected error importing module '{app_target}': {e}"
51
- )
53
+ raise Error(f"Unexpected error importing module '{app_target}': {e}") from e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cocoindex
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Classifier: Development Status :: 3 - Alpha
5
5
  Classifier: License :: OSI Approved :: Apache Software License
6
6
  Classifier: Operating System :: OS Independent
@@ -1,11 +1,11 @@
1
- cocoindex-0.2.3.dist-info/METADATA,sha256=TzOWNtD0v9YVOXQOdjVaZo0GrfI8QTyz1oWYVPEKbKc,12952
2
- cocoindex-0.2.3.dist-info/WHEEL,sha256=cVaoL47Ex1FxzwnkO_WCjy3a1Wl6mtZbBPTvTiNCHdY,103
3
- cocoindex-0.2.3.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
- cocoindex-0.2.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1
+ cocoindex-0.2.4.dist-info/METADATA,sha256=eEw6yQ-w-oMTQAEnQKYX4DBJ8M2JuaaGKW985yTDm6g,12952
2
+ cocoindex-0.2.4.dist-info/WHEEL,sha256=cVaoL47Ex1FxzwnkO_WCjy3a1Wl6mtZbBPTvTiNCHdY,103
3
+ cocoindex-0.2.4.dist-info/entry_points.txt,sha256=_NretjYVzBdNTn7dK-zgwr7YfG2afz1u1uSE-5bZXF8,46
4
+ cocoindex-0.2.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
5
  cocoindex/__init__.py,sha256=sLpSVO5Cotgn_82lawxvXnaqfa-qj33rytWBAe2MTtU,2201
6
- cocoindex/_engine.abi3.so,sha256=l-Eje47IkSXjijjvQD6_e-op9M5_ocfgaeO1bPsi5_E,66234864
6
+ cocoindex/_engine.abi3.so,sha256=JlDMykVQfBKOx8PSDpsz0qqoZN0dM3UbN1mdJucGk7I,66235264
7
7
  cocoindex/auth_registry.py,sha256=PE1-kVkcyC1G2C_V7b1kvYzeq73OFQehWKQP7ln7fJ8,1478
8
- cocoindex/cli.py,sha256=8Q2D0gI_yHorxfFC7tzV96oJAR7PtTn_T4qWLorPPoM,20675
8
+ cocoindex/cli.py,sha256=D-mlZrH-trT5UR3N5KfQeq2CQ95odO2FTi67WIPjzPM,21120
9
9
  cocoindex/convert.py,sha256=Eh9Co37BtW_PK3Oi-pFEiFt8cc_6g7XLcurV-NeH6GU,22090
10
10
  cocoindex/flow.py,sha256=AoWt8i05MfEnnoAQR0EWzZU-9k36UmCFuNLb3itlGO0,37204
11
11
  cocoindex/functions.py,sha256=09erNt3WbzY9l1KER-akBF2O5-6xEahV2ORBECaL6yk,12260
@@ -28,7 +28,7 @@ cocoindex/tests/test_transform_flow.py,sha256=G69w-n-vnCTo3r9hVIk2lJNAQEkGUA7PZf
28
28
  cocoindex/tests/test_typing.py,sha256=9OF3lO2uSpZBefkEJx7WRbnkXjwQtvlQIeeARYQID68,12391
29
29
  cocoindex/tests/test_validation.py,sha256=X6AQzVs-hVKIXcrHMEMQnhfUE8at7iXQnPq8nHNhZ2Q,4543
30
30
  cocoindex/typing.py,sha256=lEQYIzAGVKQp6RnhyeopY9Q7xEED7yQj3ZMxvTPblV8,14200
31
- cocoindex/user_app_loader.py,sha256=o2n25y7CGw9Qrb-RN6tiNlv2YJ9YLM8NSMhJZjLhhKQ,1914
31
+ cocoindex/user_app_loader.py,sha256=bc3Af-gYRxJ9GpObtpjegZY855oQBCv5FGkrkWV2yGY,1873
32
32
  cocoindex/utils.py,sha256=hUhX-XV6XGCtJSEIpBOuDv6VvqImwPlgBxztBTw7u0U,598
33
33
  cocoindex/validation.py,sha256=PZnJoby4sLbsmPv9fOjOQXuefjfZ7gmtsiTGU8SH-tc,3090
34
- cocoindex-0.2.3.dist-info/RECORD,,
34
+ cocoindex-0.2.4.dist-info/RECORD,,