mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
feat(python): add free-threaded CPython 3.15 wheel support (#4961)
## Problem The existing `cp310-abi3` wheel cannot be installed on free-threaded CPython 3.15. ## Changes - Keep `abi3-py310` in the default Cargo feature set and provide a separate native free-threaded build profile with the same Python distribution features. - Build and validate `cp315-cp315t` release wheels for Linux x86-64 and ARM64, macOS ARM64, and Windows x64; collect them with the existing release artifacts. - Add a Linux 3.15t CI job and tests for GIL state, concurrent operations, and persistence. The existing regular-Python jobs retain the full test suite. - Validate compressed manylinux platform tags against the expanded `WHEEL` metadata and use workspace-relative wheel paths in Python CI. ## Validation - Built and validated Windows x64 `lancedb-0.42.0b10-cp310-abi3-win_amd64.whl` and `lancedb-0.42.0b10-cp315-cp315t-win_amd64.whl` with Maturin 1.15.0 and `--profile ci`. - On the current PR commit `eecf193`, rebuilt the Windows x64 native wheel, installed it on official CPython 3.15.0t, and ran `python -m pytest python/python/tests/test_free_threaded.py -q`: 2 passed, including GIL state and concurrent database operations. - On the current PR commit, built a native Linux x86-64 `cp315-cp315t` wheel with Maturin 1.15.0 and `--profile ci`, validated its wheel metadata, installed it on CPython 3.15.2t, and ran `python -m pytest python/tests/test_free_threaded.py -q`: 2 passed. This local Linux wheel uses the native `linux_x86_64` platform tag, not a manylinux tag. - Cargo feature regression check, Ruff, Python syntax, workflow YAML parsing, and `git diff --check` passed. - `python -m unittest discover -s ci/tests -p test_check_python_wheel.py -v`: 4 passed on Windows and WSL Linux, including compressed manylinux tags and mismatched metadata. The workflow's corrected wheel glob was also checked from the `python` directory under WSL, and the two free-threaded runtime tests passed from that directory on Windows. The local ABI3 regression wheel was built before the rebase. The native Windows and Linux free-threaded wheels and concurrency tests were built from the current PR commit `eecf193`. The macOS and Linux manylinux release artifacts still need validation in upstream CI. The full test extra pulls optional dependencies requiring source builds on 3.15t, so the new job installs the wheel and focused test dependencies; regular jobs still run the full suite. The complete CI-script suite passed locally on WSL Linux at commit `eecf193`: `python3 -m unittest discover -s ci/tests -v` ran 39 tests successfully with Rust 1.97, a user-space GCC toolchain, and Python's `packaging` module. The upstream CI-script run is marked `action_required`. Closes #4641
This commit is contained in:
+7
-2
@@ -32,7 +32,7 @@ env_logger.workspace = true
|
||||
log.workspace = true
|
||||
# Maturin enables extension-module mode for Python builds. Keeping it out of
|
||||
# Cargo features lets Rust unit tests link against libpython.
|
||||
pyo3 = { version = "0.29", features = ["abi3-py311", "chrono", "uuid"] }
|
||||
pyo3 = { version = "0.29", features = ["chrono", "uuid"] }
|
||||
chrono.workspace = true
|
||||
pyo3-async-runtimes = { version = "0.29", features = [
|
||||
"attributes",
|
||||
@@ -53,7 +53,12 @@ libc = "0.2"
|
||||
pyo3-build-config = "0.29"
|
||||
|
||||
[features]
|
||||
default = ["remote", "lancedb/aws", "lancedb/gcs", "lancedb/azure", "lancedb/dynamodb", "lancedb/oss", "lancedb/huggingface", "lancedb/cos", "lancedb/goosefs", "lancedb/metrics-otel", "lancedb/geo"]
|
||||
default = ["stable-abi", "default-python"]
|
||||
# Keep stable ABI selection separate so the free-threaded wheel can use its
|
||||
# native CPython ABI without changing the default Python distribution.
|
||||
stable-abi = ["pyo3/abi3-py311"]
|
||||
default-python = ["remote", "lancedb/aws", "lancedb/gcs", "lancedb/azure", "lancedb/dynamodb", "lancedb/oss", "lancedb/huggingface", "lancedb/cos", "lancedb/goosefs", "lancedb/metrics-otel", "lancedb/geo"]
|
||||
free-threaded = ["default-python"]
|
||||
fp16kernels = ["lancedb/fp16kernels"]
|
||||
remote = ["lancedb/remote"]
|
||||
experimental-functions = ["lancedb/experimental-functions"]
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
||||
|
||||
import sys
|
||||
import sysconfig
|
||||
import threading
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def _require_free_threaded_runtime():
|
||||
if not sysconfig.get_config_var("Py_GIL_DISABLED"):
|
||||
pytest.skip("requires a free-threaded CPython interpreter")
|
||||
assert not sys._is_gil_enabled(), "the GIL was enabled before the test"
|
||||
|
||||
|
||||
def test_native_import_does_not_enable_the_gil():
|
||||
_require_free_threaded_runtime()
|
||||
|
||||
import lancedb
|
||||
import lancedb._lancedb
|
||||
|
||||
assert not sys._is_gil_enabled()
|
||||
assert lancedb.__version__
|
||||
assert lancedb._lancedb.__version__
|
||||
|
||||
|
||||
def test_free_threaded_database_operations_preserve_concurrent_appends(tmp_path):
|
||||
_require_free_threaded_runtime()
|
||||
|
||||
import lancedb
|
||||
|
||||
assert not sys._is_gil_enabled()
|
||||
db = lancedb.connect(tmp_path)
|
||||
table = db.create_table(
|
||||
"records",
|
||||
[{"id": -1, "vector": [1.0, 0.0], "payload": "seed"}],
|
||||
)
|
||||
|
||||
worker_count = 12
|
||||
batches_per_worker = 10
|
||||
rows_per_batch = 5
|
||||
start = threading.Barrier(worker_count)
|
||||
|
||||
def append_and_read(worker_id):
|
||||
start.wait(timeout=30)
|
||||
for batch_id in range(batches_per_worker):
|
||||
first_id = worker_id * batches_per_worker * rows_per_batch
|
||||
first_id += batch_id * rows_per_batch
|
||||
table.add(
|
||||
[
|
||||
{
|
||||
"id": first_id + offset,
|
||||
"vector": [float(worker_id), 1.0],
|
||||
"payload": f"worker-{worker_id}",
|
||||
}
|
||||
for offset in range(rows_per_batch)
|
||||
]
|
||||
)
|
||||
assert table.count_rows() >= 1
|
||||
|
||||
with ThreadPoolExecutor(max_workers=worker_count) as pool:
|
||||
list(pool.map(append_and_read, range(worker_count)))
|
||||
|
||||
assert not sys._is_gil_enabled()
|
||||
assert table.count_rows() == 1 + worker_count * batches_per_worker * rows_per_batch
|
||||
assert table.search([1.0, 0.0]).limit(1).to_list()[0]["id"] == -1
|
||||
|
||||
rows = table.to_arrow().to_pylist()
|
||||
ids = {row["id"] for row in rows}
|
||||
assert ids == {-1, *range(worker_count * batches_per_worker * rows_per_batch)}
|
||||
|
||||
table.update(where="id = -1", values={"payload": "updated"})
|
||||
table.delete("id = 0")
|
||||
db.close()
|
||||
|
||||
reopened = lancedb.connect(tmp_path)
|
||||
persisted = reopened.open_table("records")
|
||||
persisted_rows = persisted.to_arrow().to_pylist()
|
||||
persisted_by_id = {row["id"]: row for row in persisted_rows}
|
||||
|
||||
assert len(persisted_rows) == worker_count * batches_per_worker * rows_per_batch
|
||||
assert persisted_by_id[-1]["payload"] == "updated"
|
||||
assert 0 not in persisted_by_id
|
||||
assert not sys._is_gil_enabled()
|
||||
reopened.close()
|
||||
@@ -5,6 +5,7 @@ import importlib
|
||||
import importlib.metadata
|
||||
import re
|
||||
import sys
|
||||
import sysconfig
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -52,7 +53,7 @@ def test_pyo3_abi_matches_minimum_supported_python():
|
||||
|
||||
major, minor = minimum_python.groups()
|
||||
expected_abi = f"abi3-py{major}{minor}"
|
||||
configured_abis = re.findall(r'"(abi3-py\d+)"', cargo_manifest)
|
||||
configured_abis = re.findall(r'"(?:pyo3/)?(abi3-py\d+)"', cargo_manifest)
|
||||
|
||||
# PyO3 0.29 configures the ABI through the runtime dependency; its
|
||||
# build-config crate no longer exposes ABI features.
|
||||
@@ -61,6 +62,78 @@ def test_pyo3_abi_matches_minimum_supported_python():
|
||||
)
|
||||
|
||||
|
||||
def test_cargo_profiles_preserve_abi3_and_enable_native_free_threading():
|
||||
project_dir = Path(__file__).parents[2]
|
||||
cargo_manifest = (project_dir / "Cargo.toml").read_text()
|
||||
features_section = re.search(
|
||||
r"(?ms)^\[features\]\s*(.*?)(?=^\[[^]]+\]|\Z)", cargo_manifest
|
||||
)
|
||||
assert features_section is not None
|
||||
|
||||
def feature_values(name):
|
||||
match = re.search(
|
||||
rf"(?ms)^{re.escape(name)}\s*=\s*\[(.*?)\]", features_section.group(1)
|
||||
)
|
||||
assert match is not None, f"missing Cargo feature {name!r}"
|
||||
return re.findall(r'"([^"]+)"', match.group(1))
|
||||
|
||||
default_python_features = {
|
||||
"remote",
|
||||
"lancedb/aws",
|
||||
"lancedb/gcs",
|
||||
"lancedb/azure",
|
||||
"lancedb/dynamodb",
|
||||
"lancedb/oss",
|
||||
"lancedb/huggingface",
|
||||
"lancedb/cos",
|
||||
"lancedb/goosefs",
|
||||
"lancedb/metrics-otel",
|
||||
"lancedb/geo",
|
||||
}
|
||||
assert set(feature_values("default-python")) == default_python_features
|
||||
assert set(feature_values("default")) == {"stable-abi", "default-python"}
|
||||
assert feature_values("stable-abi") == ["pyo3/abi3-py311"]
|
||||
assert feature_values("free-threaded") == ["default-python"]
|
||||
|
||||
pyo3_dependency = re.search(r"(?m)^pyo3\s*=\s*\{([^}]*)\}", cargo_manifest)
|
||||
assert pyo3_dependency is not None
|
||||
assert "abi3-py311" not in pyo3_dependency.group(1)
|
||||
|
||||
|
||||
def _expected_windows_wheel_suffix(project_dir):
|
||||
if sysconfig.get_config_var("Py_GIL_DISABLED"):
|
||||
major, minor = sys.version_info[:2]
|
||||
return f"-cp{major}{minor}-cp{major}{minor}t-win_amd64.whl"
|
||||
|
||||
# The regular wheel follows the package's minimum supported Python.
|
||||
minimum_python = re.search(
|
||||
r'^requires-python\s*=\s*">=(\d+)\.(\d+)"$',
|
||||
(project_dir / "pyproject.toml").read_text(),
|
||||
re.MULTILINE,
|
||||
)
|
||||
assert minimum_python is not None
|
||||
major, minor = minimum_python.groups()
|
||||
return f"-cp{major}{minor}-abi3-win_amd64.whl"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("gil_disabled", "expected"),
|
||||
[
|
||||
(None, "-cp311-abi3-win_amd64.whl"),
|
||||
(0, "-cp311-abi3-win_amd64.whl"),
|
||||
(1, "-cp315-cp315t-win_amd64.whl"),
|
||||
],
|
||||
)
|
||||
def test_windows_wheel_suffix_for_interpreter(
|
||||
tmp_path, monkeypatch, gil_disabled, expected
|
||||
):
|
||||
(tmp_path / "pyproject.toml").write_text('requires-python = ">=3.11"\n')
|
||||
with monkeypatch.context() as patch:
|
||||
patch.setattr(sysconfig, "get_config_var", lambda name: gil_disabled)
|
||||
patch.setattr(sys, "version_info", (3, 15, 0))
|
||||
assert _expected_windows_wheel_suffix(tmp_path) == expected
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "win32", reason="Windows wheel regression test")
|
||||
def test_windows_wheel_tag_and_native_import():
|
||||
project_dir = Path(__file__).parents[2]
|
||||
@@ -68,17 +141,8 @@ def test_windows_wheel_tag_and_native_import():
|
||||
if not wheels:
|
||||
pytest.skip("no wheel artifact is available in this development environment")
|
||||
|
||||
# The wheel is tagged with the abi3 floor, which follows requires-python.
|
||||
minimum_python = re.search(
|
||||
r'^requires-python\s*=\s*">=(\d+)\.(\d+)"$',
|
||||
(project_dir / "pyproject.toml").read_text(),
|
||||
re.MULTILINE,
|
||||
)
|
||||
assert minimum_python is not None
|
||||
major, minor = minimum_python.groups()
|
||||
|
||||
assert len(wheels) == 1
|
||||
assert wheels[0].name.endswith(f"-cp{major}{minor}-abi3-win_amd64.whl")
|
||||
assert wheels[0].name.endswith(_expected_windows_wheel_suffix(project_dir))
|
||||
|
||||
native_module = importlib.import_module("lancedb._lancedb")
|
||||
assert Path(native_module.__file__).suffix == ".pyd"
|
||||
|
||||
Reference in New Issue
Block a user