-
Notifications
You must be signed in to change notification settings - Fork 763
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
examples: split maturin and setuptools-rust examples #1269
Conversation
d499fd1
to
cea2aa3
Compare
So we keep two copies of the same example? |
Agreed; the way I see this WIP PR evolving is:
|
c39b0ec
to
ccdd66f
Compare
931646e
to
7ca6397
Compare
Looks like I have the following issues still:
I will continue to work through these. Looks like RHEL 8.3 is released and includes rust |
I've also just tested the solution you gave on my current project. I noticed here you were using I mention this because using the
changes made for this:
pub fn misc( m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(issue_219, m)?)?;
Ok(())
}
#[pymodule]
fn maturin_extension(_py: Python, m: &PyModule) -> PyResult<()> {
/*... */
// m.add_wrapped(wrap_pymodule!(misc))?;
let misc_mod = PyModule::new(_py, "misc")?;
misc(misc_mod)?;
m.add_submodule(misc_mod)?;
Ok(())
} |
from .maturin_extension import __file__ as rust_extension_path | ||
|
||
|
||
class SubmoduleFinder(importlib.abc.MetaPathFinder): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh what's that doing? I wasn't aware that maturin needs that kind of workarounds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to enable importing directly from a submodule.
E.g. this always works:
import maturin_extension
maturin_extension.datetime.foo()
But the following only works with the SubmoduleFinder
import maturin_extension.datetime
datetime.foo()
# or
from maturin_extension.datetime import foo
foo()
However I'm beginning to think this was perhaps not a good idea: it re-runs the #[pymodule]
init code which means that it's possible to create two separate modules:
>>> import maturin_extension
>>> dt = maturin_extension.datetime
>>> import maturin_extension.datetime
>>> dt == maturin_extension.datetime
False
That it's possible to create two different copies of the submodule is a bit... horrible. So I'm going to remove this from the example code.
@Progdrasil interesting - I think |
ec6fbde
to
ce52b03
Compare
😭 I can't reproduce this pypy failure locally at all. Looks like it is |
tox has a an option called `passenv` which tells it to let the env var from
outside be passed in.
…On Sun, Dec 20, 2020 at 9:14 AM David Hewitt ***@***.***> wrote:
😭 I can't reproduce this pypy failure locally at all.
Looks like it is tox which is removing the CARGO_BUILD_TARGET environment
variable, so I'm unsure what to do about that also.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1269 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAAGBDMK7QBVRX46BFEU43SVYBDPANCNFSM4TQZMGTA>
.
--
All that is necessary for evil to succeed is for good people to do nothing.
|
34518a3
to
74dae84
Compare
I'm going to be force-pushing to this branch a few times today to try to diagnose what this PyPy failure that I can't reproduce locally is. Sorry for any spam. |
da413e5
to
f94bb4c
Compare
f94bb4c
to
e9e0982
Compare
b35c24f
to
548c925
Compare
548c925
to
2cb4ada
Compare
2cb4ada
to
04d17a2
Compare
Replaced with #1537 |
This PR makes two copies of the existing
rustapi_module
example, calledmaturin_extension
andsetuptools_rust_extension
.Each example is currently a full copy of the other, except for different build configuration.
To make the output structure the same and importing work the same way, I found a solution to #759 - see theregister_submodules
bits of the code.This needs cleaning up and documenting better. We might also want to reduce the amount of code duplication (into a new maturin module, perhaps)?
Currently I think I'm hitting a bug in
maturin
failing to take cargo workspaces into account. I'm going to see if there's a fix for that I can contribute to.Closes #807