From ced4eb532c9ac7eb8b2d50fb93c09646c10e38c1 Mon Sep 17 00:00:00 2001 From: konstin Date: Sun, 1 Apr 2018 15:13:32 +0200 Subject: [PATCH] Expect the pyo3 crate to be in scope for the codegen This allows using generated code from crates that do not directly depend on pyo3. E.g.: ```rust extern crate my_pyo3_wrapper; use my_pyo3_wrapper::pyo3; #[py::modinit(rust2py)] fn init_mod(py: Python, m: &PyModule) -> PyResult<()> { // ... Ok(()) } --- pyo3-derive-backend/src/module.rs | 2 -- pyo3-derive-backend/src/py_class.rs | 4 ++-- pyo3-derive-backend/src/py_impl.rs | 2 +- pyo3-derive-backend/src/py_proto.rs | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pyo3-derive-backend/src/module.rs b/pyo3-derive-backend/src/module.rs index 0aa9993d..c3da66fe 100644 --- a/pyo3-derive-backend/src/module.rs +++ b/pyo3-derive-backend/src/module.rs @@ -44,7 +44,6 @@ pub fn py3_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens { #[no_mangle] #[allow(non_snake_case, unused_imports)] pub unsafe extern "C" fn #cb_name() -> *mut ::pyo3::ffi::PyObject { - extern crate pyo3; use std; use pyo3::{IntoPyPointer, ObjectProtocol}; @@ -121,7 +120,6 @@ pub fn py2_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens { #[no_mangle] #[allow(non_snake_case, unused_imports)] pub unsafe extern "C" fn #cb_name() { - extern crate pyo3; use std; // initialize python diff --git a/pyo3-derive-backend/src/py_class.rs b/pyo3-derive-backend/src/py_class.rs index b32d0383..1d25c025 100644 --- a/pyo3-derive-backend/src/py_class.rs +++ b/pyo3-derive-backend/src/py_class.rs @@ -41,7 +41,7 @@ pub fn build_py_class(ast: &mut syn::DeriveInput, attr: String) -> Tokens { unused_qualifications, unused_variables, non_camel_case_types)] const #dummy_const: () = { use std; - extern crate pyo3 as _pyo3; + use pyo3 as _pyo3; #tokens }; @@ -372,7 +372,7 @@ fn impl_descriptors(cls: &syn::Ty, descriptors: Vec<(syn::Field, Vec)>) #[allow(non_upper_case_globals, unused_attributes, unused_qualifications, unused_variables, unused_imports)] const #dummy_const: () = { - extern crate pyo3 as _pyo3; + use pyo3 as _pyo3; #tokens }; diff --git a/pyo3-derive-backend/src/py_impl.rs b/pyo3-derive-backend/src/py_impl.rs index 025a0f7a..c53ac69b 100644 --- a/pyo3-derive-backend/src/py_impl.rs +++ b/pyo3-derive-backend/src/py_impl.rs @@ -57,7 +57,7 @@ fn impl_methods(ty: &Box, impls: &mut Vec) -> Tokens { #[allow(non_upper_case_globals, unused_attributes, unused_qualifications, unused_variables, unused_imports)] const #dummy_const: () = { - extern crate pyo3 as _pyo3; + use pyo3 as _pyo3; #tokens }; diff --git a/pyo3-derive-backend/src/py_proto.rs b/pyo3-derive-backend/src/py_proto.rs index b012606e..b18b8709 100644 --- a/pyo3-derive-backend/src/py_proto.rs +++ b/pyo3-derive-backend/src/py_proto.rs @@ -128,7 +128,7 @@ fn impl_proto_impl(ty: &Box, #[allow(non_upper_case_globals, unused_attributes, unused_qualifications, unused_variables)] const #dummy_const: () = { - extern crate pyo3 as _pyo3; + use pyo3 as _pyo3; #tokens