Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poetry build does not include rust .so in wheel #1

Closed
BartoszJanuszNA opened this issue May 15, 2024 · 3 comments
Closed

poetry build does not include rust .so in wheel #1

BartoszJanuszNA opened this issue May 15, 2024 · 3 comments
Assignees

Comments

@BartoszJanuszNA
Copy link

BartoszJanuszNA commented May 15, 2024

Hello, thank you for this tutorial, it was extremely helpful during my project setup. I see one issue with it:
I need to be able to build a wheel for my project and I would like to do it through poetry with maturin as build backend. However, after the wheel produced by poetry build command does not include the compiled .so file.

On the contrary, when I use maturin build the produced wheel contains the .so file. So technically I could just use maturin to build my wheel, right?

Well there is a problem - I have to use poetry to manage my dependencies (because of the setup of other projects in out organisation) and maturin cannot read dependencies in poetry format ([tool.poetry.dependencies]) it needs the [project.dependencies] as PEP 508 specifies. Vice versa, poetry cannot read [project.dependencies]. So to have both tools working I need to duplicate the dependency list in those two formats, which works but is a pain to maintain.

The next interesting thing is, that when I install hello-maturin as the dependency in another project using 'poetry add /path/to/hello-maturin' it installs the complete project - with poetry managed dependencies AND the .so file is present in site-packages/hello-maturin. This shows me that poetry can use maturin properly as build backend, but for some reason it does not do it during poetry build.

So my question is - is there a way to build wheel using poetry build with maturin as backend and actually have the compiled .so file included in this wheel?

@BartoszJanuszNA BartoszJanuszNA changed the title poetry poetry build does not include rust .so in wheel May 15, 2024
@RaulTrombin
Copy link

RaulTrombin commented May 15, 2024

Hi @BartoszJanuszNA,

It's been a while since I finished a solution that I think does what you are looking for.
I used Hatch over Poetry, but Poetry was working fine as far as I can remember.

Please take a look at:
https://github.com/bluerobotics/navigator-lib/actions/runs/8428044353
https://github.com/bluerobotics/navigator-lib
https://github.com/bluerobotics/navigator-lib/pull/32/files

Hope it helps your project!

@kfields
Copy link
Owner

kfields commented May 16, 2024

The short answer is no, you cannot use poetry build to call maturin build.
I only used poetry for this example to make it quick and easy to create a virtual environment and install the development dependencies, mainly maturin.
I switched to hatch for my next project deeper because of the duplication issues.
In fact, I use hatch for all of my projects now even though poetry has some niceties that I miss.
I will probably replace poetry in this repo with hatch eventually.
My advice is to switch to hatch.

@kfields kfields self-assigned this May 16, 2024
@BartoszJanuszNA
Copy link
Author

So it seems that until Poetry learns to read dependencies from [project] I am stuck with duplicates 😞 Thank you for pointing me to hatch, I see it can do the above.

@RaulTrombin I can see your project's python part does not have any dependencies (I assume [tool.hatch.envs.dev] is only for development environment and not used during wheel build?) . In my project I have those and that is where the problem arises. Thank you nonetheless :-)

@kfields That's exactly what I was suspecting, thanks for resolving my doubts. Well, to be absolutely fair I saw recently a solution using custom build.py script, but it looks like forcing poetry to do smth it doesn't want to. Simpler to just build wheels with maturin.

Thank you guys!

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

No branches or pull requests

3 participants