-
Notifications
You must be signed in to change notification settings - Fork 766
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
Move macros into separate feature. #897
Conversation
Hmmm this is an interesting idea! In principle I am keen to give users an option to have a smaller compile for sure. I wonder - once the macros are removed then a lot of other code becomes irrelevant I think - e.g. |
Yeah, with My main goal was to avoid pulling in unnecessary dependencies, so I'm not too worried about parts of the pyo3 crate that stay unused. It would definitely be nice to split this better (maybe even separate crates?), but that's probably a lot of work. |
👍 maybe I will have a quick play with this later to see if I can find something which feels good. I'm in split opinion about separate crates. It helps with some big projects but it does separate the documentation out into multiple places, which can make it a little bit harder for users to find the docs they need... |
@m-ou-se how much of pyo3 outside of the FFI bindings does your use case exercise if it doesn't use pymodule, pyfunction, etc.? Would moving the FFI bindings into a pyo3ffi crate be useful? |
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.
Thank you!
It's a bit surprising for me that we can separate features by such a simple trick.
@@ -142,3 +144,11 @@ pub trait PyMethodsImpl { | |||
.collect() | |||
} | |||
} | |||
|
|||
#[doc(hidden)] | |||
#[cfg(not(feature = "macros"))] |
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.
Nice 👍
You mean we should separate
@ijl |
The Another crate I'm about to publish converts objects to and frorm PyO3's All the macros like |
@@ -280,6 +278,7 @@ macro_rules! wrap_pymodule { | |||
/// If you need to handle failures, please use [Python::run] directly. | |||
/// | |||
#[macro_export] | |||
#[cfg(feature = "macros")] |
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.
I'm sorry for my lazy review but could you please add this definition?
#[macro_export]
#[cfg(not(feature = "macros"))]
macro_rules! py_run {
($py:expr, $($val:ident)+, $code:expr) => {{
pyo3::py_run_impl!($py, $($val)+, &pyo3::unindent::unindent($code))
}};
}
unindent
is a really small dependency (see its Cargo.toml) and I think it's OK.
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.
then py_run
would behave differently depending on the feature? that seems confusing...
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.
That would mean that code like
let code = "asdf";
py_run!(py, a b, code);
would compile fine with feature = "macros"
disabled, but will no longer compile when it gets enabled.
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.
then py_run would behave differently depending on the feature?
No, it behaves the same.
But
- with
feature="macros"
and - string literal is passed like
py_run!(py, a, "print(a)")
it works faster thanks to indoc.
I don't have a need to separate the FFI right now. It is simple to do, though. The |
Could you please rebase on the master? |
It's enabled by default to avoid breakage, but this allows compiling pyo3 with a lot less dependencies in case the macros are not needed.
Thanks! |
This makes it possible to opt-out of all the (proc) macros, which reduces the amount of dependencies that need to be downloaded and built.
Together with #895, #896 and #899, this reduces the dependency tree from:
to:
with
--no-default-features
.