Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
115 lines (95 loc) · 3.4 KB
/
Copy path__init__.py
File metadata and controls
115 lines (95 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Python bindings for the ``lance-graph`` crate.
Provides two query interfaces:
- **Cypher**: ``CypherQuery`` and ``CypherEngine`` for graph-pattern queries
(requires a ``GraphConfig`` with node/relationship mappings).
- **SQL**: ``SqlQuery`` and ``SqlEngine`` for standard SQL queries executed
directly against datasets via DataFusion (no ``GraphConfig`` needed).
"""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types import ModuleType
def _load_bindings() -> ModuleType:
try:
from . import _internal as bindings # type: ignore[attr-defined]
except ImportError:
try:
import _internal as bindings # type: ignore[import-not-found]
except ImportError:
bindings = _load_dev_build()
return bindings
def _load_dev_build() -> ModuleType:
package_dir = Path(__file__).resolve().parent
project_root = package_dir.parent.parent # .../python
repo_root = project_root.parent
search_paths = [
project_root / "target" / "debug",
project_root / "target" / "debug" / "deps",
project_root / "target" / "release",
project_root / "target" / "release" / "deps",
project_root / "target" / "maturin",
repo_root / "target" / "debug",
repo_root / "target" / "debug" / "deps",
repo_root / "target" / "release",
repo_root / "target" / "release" / "deps",
repo_root / "target" / "maturin",
]
candidates = []
for base in search_paths:
candidates.extend(base.glob("_internal*.so"))
candidates.extend(base.glob("lib_internal*.so"))
candidates.extend(base.glob("_internal*.pyd"))
candidates.extend(base.glob("lib_internal*.pyd"))
for candidate in candidates:
if not candidate.exists():
continue
spec = importlib.util.spec_from_file_location(
f"{__name__}._internal", candidate
)
if spec is None or spec.loader is None:
continue
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore[call-arg]
sys.modules[spec.name] = module
return module
raise ImportError(
"Unable to locate the compiled lance-graph extension. "
"Run `maturin develop` (or install the package) before importing."
)
_bindings = _load_bindings()
GraphConfig = _bindings.graph.GraphConfig
GraphConfigBuilder = _bindings.graph.GraphConfigBuilder
CypherQuery = _bindings.graph.CypherQuery
CypherEngine = _bindings.graph.CypherEngine
SqlQuery = _bindings.graph.SqlQuery
SqlEngine = _bindings.graph.SqlEngine
ExecutionStrategy = _bindings.graph.ExecutionStrategy
SqlDialect = _bindings.graph.SqlDialect
VectorSearch = _bindings.graph.VectorSearch
DistanceMetric = _bindings.graph.DistanceMetric
DirNamespace = _bindings.graph.DirNamespace
UnityCatalog = _bindings.graph.UnityCatalog
CatalogInfo = _bindings.graph.CatalogInfo
SchemaInfo = _bindings.graph.SchemaInfo
TableInfo = _bindings.graph.TableInfo
__all__ = [
"GraphConfig",
"GraphConfigBuilder",
"CypherQuery",
"CypherEngine",
"SqlQuery",
"SqlEngine",
"ExecutionStrategy",
"SqlDialect",
"VectorSearch",
"DistanceMetric",
"DirNamespace",
"UnityCatalog",
"CatalogInfo",
"SchemaInfo",
"TableInfo",
]
__version__ = _bindings.__version__