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

import_hook doesn't rebuild and reinstall the package if the Rust code changes #1694

Closed
2 tasks
itamarst opened this issue Jul 18, 2023 · 1 comment · Fixed by #1695
Closed
2 tasks

import_hook doesn't rebuild and reinstall the package if the Rust code changes #1694

itamarst opened this issue Jul 18, 2023 · 1 comment · Fixed by #1695
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@itamarst
Copy link
Contributor

itamarst commented Jul 18, 2023

Bug Description

If I edit the Rust source code I am importing with maturin.import_hook, I would expect that a new Python process would rebuild the code when importing in the new process. Instead, the package is only ever compiled once.

Your maturin version (maturin --version)

1.1.0

Your Python version (python -V)

3.11.4

Your pip version (pip -V)

23.2

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

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

  • Yes

Steps to Reproduce

I have a rust_pointvec.rs with PyO3 module defined.

I run:

import maturin.import_hook
maturin.import_hook.install()
import rust_pointvec

It compiles and installs.

I then modify the Rust code, and rerun the Python script. No rebuild or recompilation happens, the old compiled module is imported, and there is no maturin logging, unlike the initial run.

My guess at the problem: now that the package is installed, the import hook is bypassed since it can just use the default importer. Perhaps instead of sys.meta_path.append() the hook should be inserted earlier in sys.meta_path, e.g. rustimport makes sure to be first: https://github.com/mityax/rustimport/blob/master/rustimport/import_hook.py#L65C2-L65C2

@itamarst itamarst added the bug Something isn't working label Jul 18, 2023
@messense
Copy link
Member

Thanks for the report, pull requests are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
2 participants