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(())
}
This commit is contained in:
konstin 2018-04-01 15:13:32 +02:00
parent e570c6b9b9
commit ced4eb532c
4 changed files with 4 additions and 6 deletions

View File

@ -44,7 +44,6 @@ pub fn py3_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens {
#[no_mangle] #[no_mangle]
#[allow(non_snake_case, unused_imports)] #[allow(non_snake_case, unused_imports)]
pub unsafe extern "C" fn #cb_name() -> *mut ::pyo3::ffi::PyObject { pub unsafe extern "C" fn #cb_name() -> *mut ::pyo3::ffi::PyObject {
extern crate pyo3;
use std; use std;
use pyo3::{IntoPyPointer, ObjectProtocol}; use pyo3::{IntoPyPointer, ObjectProtocol};
@ -121,7 +120,6 @@ pub fn py2_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens {
#[no_mangle] #[no_mangle]
#[allow(non_snake_case, unused_imports)] #[allow(non_snake_case, unused_imports)]
pub unsafe extern "C" fn #cb_name() { pub unsafe extern "C" fn #cb_name() {
extern crate pyo3;
use std; use std;
// initialize python // initialize python

View File

@ -41,7 +41,7 @@ pub fn build_py_class(ast: &mut syn::DeriveInput, attr: String) -> Tokens {
unused_qualifications, unused_variables, non_camel_case_types)] unused_qualifications, unused_variables, non_camel_case_types)]
const #dummy_const: () = { const #dummy_const: () = {
use std; use std;
extern crate pyo3 as _pyo3; use pyo3 as _pyo3;
#tokens #tokens
}; };
@ -372,7 +372,7 @@ fn impl_descriptors(cls: &syn::Ty, descriptors: Vec<(syn::Field, Vec<FnType>)>)
#[allow(non_upper_case_globals, unused_attributes, #[allow(non_upper_case_globals, unused_attributes,
unused_qualifications, unused_variables, unused_imports)] unused_qualifications, unused_variables, unused_imports)]
const #dummy_const: () = { const #dummy_const: () = {
extern crate pyo3 as _pyo3; use pyo3 as _pyo3;
#tokens #tokens
}; };

View File

@ -57,7 +57,7 @@ fn impl_methods(ty: &Box<syn::Ty>, impls: &mut Vec<syn::ImplItem>) -> Tokens {
#[allow(non_upper_case_globals, unused_attributes, #[allow(non_upper_case_globals, unused_attributes,
unused_qualifications, unused_variables, unused_imports)] unused_qualifications, unused_variables, unused_imports)]
const #dummy_const: () = { const #dummy_const: () = {
extern crate pyo3 as _pyo3; use pyo3 as _pyo3;
#tokens #tokens
}; };

View File

@ -128,7 +128,7 @@ fn impl_proto_impl(ty: &Box<syn::Ty>,
#[allow(non_upper_case_globals, unused_attributes, #[allow(non_upper_case_globals, unused_attributes,
unused_qualifications, unused_variables)] unused_qualifications, unused_variables)]
const #dummy_const: () = { const #dummy_const: () = {
extern crate pyo3 as _pyo3; use pyo3 as _pyo3;
#tokens #tokens