mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-28 22:46:14 +00:00
fix(python)!: support compat-only imports (#3973)
Read `__version__` from the native `_lancedb` module so `import lancedb` works when only `lancedb-compat` is installed. Add the type declaration and a subprocess regression test. Ruff and Linux-targeted Pyright pass. Import tests: 1 passed and 1 Linux-only test skipped on Windows. Runtime tests used the official same-version Windows native module; a fresh source build still needs CI. BREAKING CHANGE: `lancedb.__version__` now uses the native version string. Prereleases may report `0.41.0-beta.13` instead of `0.41.0b13`. Fixes #3950 --------- Co-authored-by: Xuanwo <github@xuanwo.io>
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
|
||||
import importlib.metadata
|
||||
import os
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from datetime import timedelta
|
||||
from typing import Dict, Optional, Union, Any, List, Iterable, TYPE_CHECKING
|
||||
|
||||
__version__ = importlib.metadata.version("lancedb")
|
||||
|
||||
from ._lancedb import __version__ as __version__
|
||||
from ._lancedb import connect as lancedb_connect
|
||||
from ._lancedb import FtsToken
|
||||
from ._lancedb import FunctionErrorFragment as FunctionErrorFragment
|
||||
|
||||
@@ -32,6 +32,7 @@ IvfHnswPq: type[HnswPq] = HnswPq
|
||||
IvfHnswSq: type[HnswSq] = HnswSq
|
||||
IvfHnswFlat: type[HnswFlat] = HnswFlat
|
||||
AnalyzePlanDistributedMetrics = Literal["aggregate", "per_worker", "full"]
|
||||
__version__: str
|
||||
|
||||
class MetricPoint:
|
||||
name: str
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -31,3 +32,36 @@ def test_native_extension_does_not_link_openssl():
|
||||
"the LanceDB native extension must use rustls instead of linking OpenSSL: "
|
||||
f"{openssl_libraries}"
|
||||
)
|
||||
|
||||
|
||||
def test_top_level_version_comes_from_native_module():
|
||||
child_code = """
|
||||
import importlib.metadata
|
||||
|
||||
orig_version = importlib.metadata.version
|
||||
|
||||
def fail_version_lookup(_: str) -> str:
|
||||
if _ in {"lancedb", "lancedb-compat"}:
|
||||
raise AssertionError("lancedb import should not query distribution metadata")
|
||||
return orig_version(_)
|
||||
|
||||
importlib.metadata.version = fail_version_lookup
|
||||
|
||||
import lancedb
|
||||
import lancedb._lancedb as native_module
|
||||
import lancedb.db
|
||||
|
||||
assert lancedb.__version__ == native_module.__version__
|
||||
"""
|
||||
env = os.environ.copy()
|
||||
env["PYTHONPATH"] = os.pathsep.join(path for path in sys.path if path)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", child_code],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env=env,
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
|
||||
Reference in New Issue
Block a user