fix(adr-117/p1): standalone Cargo.toml + python-source=. + #[pyo3(name=_native)] (P1 GREEN)

Three fixes to make maturin develop actually work locally:

1. `python/Cargo.toml` removed `*.workspace = true` inheritance —
   the python/ crate is intentionally outside the v2/ workspace
   (ADR-117 §5.2) so it needs every `[package]` field local.

2. `python/pyproject.toml` `python-source = "python"` was wrong
   because pyproject.toml lives at python/ — maturin was looking for
   python/python/. Changed to `python-source = "."` so the
   `wifi_densepose/` package directory sibling-to-pyproject is found.

3. `python/src/lib.rs` `#[pymodule] fn wifi_densepose_native` →
   `#[pymodule] #[pyo3(name = "_native")] fn wifi_densepose_native`.
   PyO3 generates `PyInit__native` from the pyo3-name attribute, which
   must match the `module-name` in pyproject.toml's [tool.maturin]
   block ("wifi_densepose._native"). Without this attribute the wheel
   builds but `import wifi_densepose._native` fails with
   ModuleNotFoundError.

## Local validation (P1 acceptance gate)

```
$ python -m venv .venv && .venv/Scripts/python -m pip install maturin pytest
$ VIRTUAL_ENV=… maturin develop --release
…
    Finished `release` profile [optimized] target(s)
📦 Built wheel for abi3 Python ≥ 3.10
🛠 Installed wifi-densepose-2.0.0a1

$ .venv/Scripts/python -c 'import wifi_densepose; print(wifi_densepose.__version__, wifi_densepose.__rust_version__, wifi_densepose.hello())'
2.0.0a1 2.0.0-alpha.1 ok

$ .venv/Scripts/python -m pytest tests/ -v
tests/test_smoke.py::test_package_imports PASSED
tests/test_smoke.py::test_version_string_well_formed PASSED
tests/test_smoke.py::test_rust_version_surfaced PASSED
tests/test_smoke.py::test_build_features_listed PASSED
tests/test_smoke.py::test_hello_returns_ok PASSED
tests/test_smoke.py::test_native_module_private PASSED
======================== 6 passed in 0.05s =========================
```

P1 closed. Moving to P2 (core type bindings).

Refs #785, ADR-117 §6.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
ruv 2026-05-24 10:48:28 -04:00
parent 5d90d4fef2
commit 4ec5b166e6
3 changed files with 19 additions and 6 deletions

View File

@ -1,11 +1,16 @@
[package]
name = "wifi-densepose-py"
version = "2.0.0-alpha.1"
edition.workspace = true
license.workspace = true
# The `python/` crate is intentionally OUTSIDE the `v2/` Cargo
# workspace (ADR-117 §5.2) so maturin's `python-source` + `module-name`
# config stays self-contained and `cargo test --workspace` in v2/
# doesn't have to compile pyo3. Hence no `*.workspace = true`
# inheritance here — every field is local.
edition = "2021"
license = "MIT"
authors = ["rUv <ruv@ruv.net>", "WiFi-DensePose Contributors"]
description = "PyO3 bindings for the WiFi-DensePose Rust core — ships as the `wifi-densepose` PyPI wheel (ADR-117)"
repository.workspace = true
repository = "https://github.com/ruvnet/RuView"
# ADR-117 §5.2: the Python wheel's compiled module name is
# `wifi_densepose._native` (the leading underscore marks it as an internal

View File

@ -69,9 +69,11 @@ Documentation = "https://github.com/ruvnet/RuView/tree/main/docs"
# wifi-densepose = "wifi_densepose.cli:main"
[tool.maturin]
# Layout: ./python/ holds the Rust crate + Python facade; the wheel
# packs `wifi_densepose/` as the top-level package.
python-source = "python"
# Layout: pyproject.toml + Cargo.toml live at `python/`; the
# python-source directory `wifi_densepose/` is a sibling (i.e. at
# `python/wifi_densepose/`). `python-source = "."` tells maturin to
# look for packages directly under the project root.
python-source = "."
module-name = "wifi_densepose._native"
features = ["pyo3/extension-module"]
# Strip debug symbols for smaller release wheels (ADR-117 §5.4 5 MB budget).

View File

@ -48,7 +48,13 @@ fn hello() -> PyResult<&'static str> {
/// package (`import wifi_densepose`) and never reach into `_native`
/// directly; the leading underscore is a Python convention marking
/// it as private.
///
/// The function name MUST match the `module-name` in pyproject.toml's
/// `[tool.maturin]` block — i.e. it must be `_native` because the
/// pyproject says `module-name = "wifi_densepose._native"`. PyO3
/// generates the `PyInit__native` symbol from this function name.
#[pymodule]
#[pyo3(name = "_native")]
fn wifi_densepose_native(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__rust_version__", RUST_CORE_VERSION)?;
m.add("__rust_build_tag__", RUST_BUILD_TAG)?;