Skip to content

fix(python): install the _zvec extension inside the zvec package#511

Open
Cuiyus wants to merge 1 commit into
alibaba:mainfrom
Cuiyus:fix/wheel-extension-into-package
Open

fix(python): install the _zvec extension inside the zvec package#511
Cuiyus wants to merge 1 commit into
alibaba:mainfrom
Cuiyus:fix/wheel-extension-into-package

Conversation

@Cuiyus

@Cuiyus Cuiyus commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

The compiled extension _zvec*.so was installed at the site-packages root (and the DiskANN plugin next to it), polluting the top-level namespace. It was imported everywhere as the bare top-level module _zvec.

This moves the extension into the package (zvec/_zvec*.so) and imports it as zvec._zvec.

Changes

  • CMakeLists.txt: install _zvec (and the DiskANN plugin) into ${ZVEC_PY_INSTALL_DIR}/zvec instead of the platlib root. The plugin stays next to _zvec.so, so the existing $ORIGIN rpath (src/binding/python/CMakeLists.txt) still resolves it at runtime.
  • Import sites updated (19 files total):
    • 16 .py files: from _zvec[...] importfrom zvec._zvec[...] import
    • 2 .pyi stubs: import _zvec.* and qualified annotations (_zvec.typing.DataType, …) → zvec._zvec.*

pybind11 3.0 names its def_submodules by the actual import path, so from zvec._zvec.param import _SearchQuery resolves correctly — confirmed empirically before the rewrite.

Docstrings / error strings that merely mention _zvec were intentionally left as prose.

Verification (macOS arm64)

  • ✅ Wheel places the extension at zvec/_zvec.cpython-311-darwin.so; nothing left at the site-packages root
  • import zvec, import zvec._zvec, from zvec._zvec.param import _SearchQuery, and the public API all import
  • ✅ Full Python test suite: 1092 passed, 70 skipped (skips are libaio/DiskANN-only cases, expected on macOS)

Note: this branch is cut from main and is independent of the two sibling packaging PRs (exclude SDK include/+lib/; gate the DiskANN stub). They touch the same install block and will need a trivial rebase depending on merge order.

@Cuiyus Cuiyus requested a review from feihongxu0824 as a code owner June 22, 2026 09:35
@Cuiyus Cuiyus force-pushed the fix/wheel-extension-into-package branch from 93d2861 to 46cad84 Compare June 22, 2026 09:54
The compiled extension `_zvec*.so` (and the DiskANN plugin next to it) was
installed at the site-packages root, polluting the top-level namespace and
importing as the bare top-level module `_zvec`.

Install it into the package directory instead (`zvec/_zvec*.so`) and import it
as `zvec._zvec`. All import sites are updated accordingly:

- 16 `.py` files: `from _zvec[...] import` -> `from zvec._zvec[...] import`
- 2 `.pyi` stubs: `import _zvec.*` and qualified annotations
  (`_zvec.typing.DataType`, ...) -> `zvec._zvec.*`

The DiskANN plugin install destination moves to `${...}/zvec` too, so it stays
next to `_zvec.so` and is still found via the `$ORIGIN` rpath at runtime.

pybind11 3.0 names its `def_submodule`s by the actual import path, so
`from zvec._zvec.param import _SearchQuery` resolves correctly (verified).

Verified on macOS arm64: wheel places the extension at
`zvec/_zvec.cpython-311-darwin.so` with nothing at the site-packages root;
full Python test suite passes (1092 passed, 70 skipped).
@Cuiyus Cuiyus force-pushed the fix/wheel-extension-into-package branch from 46cad84 to c15290b Compare June 22, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant