PyO3 / maturin

Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
https://maturin.rs
Apache License 2.0
3.96k stars 275 forks source link

Invalid exports in `__init__.py` when UniFFI project doesn't include .udl files #2294

Closed Nickersoft closed 7 hours ago

Nickersoft commented 2 weeks ago

Bug Description

Hey folks,

This issue I believe is related to unresolved issue I voiced awhile back as well as the multi-crate features added in #2208.

I currently have a Python project I'm hoping can leverage an external crate's UniFFI .udl to export Python bindings for the crate. Right now I just have the external crate added as a dependency and have the following in my lib.rs:

pub use odict::*;

odict::uniffi_reexport_scaffolding!();

Running maturin develop, the following files get generated:

Inside __init__.py, it attempts to export from a nonexistent module:

from .pyodict import *  # NOQA

Similarly, odict.py attempts to read from libpyodict.dylib, which doesn't exist unless I manually override the cdylib name to be pyodict, but that could be a separate issue.

I looked at the source code and saw this __init__.py seems to be hardcoded to use the current project's name. I think this could be fixed by #1910, as it includes a change to init.py that isn't present in #2208. Clarity on the cdylib issue would also be appreciated!

Your maturin version (maturin --version)

1.7.4

Your Python version (python -V)

3.13.0

Your pip version (pip -V)

24.3.1

What bindings you're using

uniffi

Does cargo build work?

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

Steps to Reproduce

Described above