update readme and travis

This commit is contained in:
Nikolay Kim 2017-05-12 23:01:54 -07:00
parent bf4e36d9d9
commit 03a3817878
4 changed files with 12 additions and 19 deletions

View File

@ -19,4 +19,4 @@ install:
- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PYTHON_LIB:$HOME/rust/lib"
- rustc -V
script:
- make test extensions
- make test

View File

@ -39,15 +39,11 @@ endif
doc: build
cargo doc --no-deps $(CARGO_FLAGS)
extensions: build
make -C extensions/tests PY=$(PY)
clean:
rm -r target
make -C extensions/ clean
gh-pages:
git clone --branch gh-pages git@github.com:dgrunwald/rust-cpython.git gh-pages
git clone --branch gh-pages git@github.com:PyO3/PyO3.git gh-pages
.PHONY: gh-pages-doc
gh-pages-doc: doc | gh-pages
@ -61,4 +57,3 @@ gh-pages-doc: doc | gh-pages
publish: default gh-pages-doc
cargo publish
cd gh-pages && git push

View File

@ -71,13 +71,13 @@ features = ["extension-module"]
**`src/lib.rs`**
```rust
#[macro_use] extern crate pye3;
#[macro_use] extern crate pyo3;
use pyo3::{PyResult, Python};
// add bindings to the generated python module
// N.B: names: "librust2py" must be the name of the `.so` or `.pyd` file
py_module_initializer!(librust2py, PyInit_librust2py, |py, m| {
py_module_init!(librust2py, PyInit_librust2py, |py, m| {
try!(m.add(py, "__doc__", "This module is implemented in Rust."));
try!(m.add(py, "sum_as_string", py_fn!(py, sum_as_string_py(a: i64, b:i64))));
Ok(())

View File

@ -173,7 +173,6 @@ mod pythonrun;
pub mod argparse;
mod function;
pub mod buffer;
//pub mod rustobject;
pub mod py_class;
/// Private re-exports for macros. Do not use.
@ -196,8 +195,7 @@ pub mod _detail {
/// Macro syntax: `py_module_initializer!($name, $py2_init, $py3_init, |$py, $m| $body)`
///
/// 1. `name`: The module name as a Rust identifier.
/// 2. `py2_init`: "init" + $name. Necessary because macros can't use concat_idents!().
/// 3. `py3_init`: "PyInit_" + $name. Necessary because macros can't use concat_idents!().
/// 2. `py3_init`: "PyInit_" + $name. Necessary because macros can't use concat_idents!().
/// 4. A lambda of type `Fn(Python, &PyModule) -> PyResult<()>`.
/// This function will be called when the module is imported, and is responsible
/// for adding the module's members.
@ -207,7 +205,7 @@ pub mod _detail {
/// #[macro_use] extern crate pyo3;
/// use pyo3::{Python, PyResult, PyObject};
///
/// py_module_initializer!(hello, PyInit_hello, |py, m| {
/// py_module_init!(hello, PyInit_hello, |py, m| {
/// m.add(py, "__doc__", "Module documentation string")?;
/// m.add(py, "run", py_fn!(py, run()))?;
/// Ok(())
@ -246,7 +244,7 @@ pub mod _detail {
/// ```
///
#[macro_export]
macro_rules! py_module_initializer {
macro_rules! py_module_init {
($name: ident, $py3: ident, |$py_id: ident, $m_id: ident| $body: expr) => {
#[no_mangle]
#[allow(non_snake_case)]
@ -259,17 +257,17 @@ macro_rules! py_module_initializer {
// We can't convert &'static str to *const c_char within a static initializer,
// so we'll do it here in the module initialization:
MODULE_DEF.m_name = concat!(stringify!($name), "\0").as_ptr() as *const _;
$crate::py_module_initializer_impl(&mut MODULE_DEF, init)
$crate::py_module_init_impl(&mut MODULE_DEF, init)
}
}
}
#[doc(hidden)]
pub unsafe fn py_module_initializer_impl(
pub unsafe fn py_module_init_impl(
def: *mut ffi::PyModuleDef,
init: fn(Python, &PyModule) -> PyResult<()>
) -> *mut ffi::PyObject {
let guard = function::AbortOnDrop("py_module_initializer");
init: fn(Python, &PyModule) -> PyResult<()>) -> *mut ffi::PyObject
{
let guard = function::AbortOnDrop("py_module_init");
let py = Python::assume_gil_acquired();
ffi::PyEval_InitThreads();
let module = ffi::PyModule_Create(def);