From a95de027c1968854f1068035579d6840cc45752c Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 12 May 2017 22:43:17 -0700 Subject: [PATCH] update tests --- .travis.yml | 5 +---- src/buffer.rs | 1 - src/err.rs | 4 ++-- src/ffi/README.md | 23 ++++------------------- src/function.rs | 6 +++--- src/lib.rs | 18 +++++++++--------- src/objects/tuple.rs | 6 +++--- src/py_class/py_class.rs | 14 +++++++------- src/py_class/slots.rs | 1 - src/pythonrun.rs | 4 ++-- tests/test_class.rs | 10 +++++----- tests/test_function.rs | 4 ++-- tests/test_slice.rs | 4 ++-- 13 files changed, 40 insertions(+), 60 deletions(-) diff --git a/.travis.yml b/.travis.yml index 048448c6..7460b515 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,10 @@ language: python python: - - "2.7" - - "3.3" - "3.4" - "3.5" - "3.6" env: - - RUST_VERSION=1.13.0 + - RUST_VERSION=1.15.1 - RUST_VERSION=nightly sudo: false install: @@ -22,4 +20,3 @@ install: - rustc -V script: - make test extensions - diff --git a/src/buffer.rs b/src/buffer.rs index d63bae84..5dffc47b 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -617,7 +617,6 @@ mod test { } #[test] - #[cfg(feature="python3-sys")] // array.array doesn't implement the buffer protocol in python 2.7 fn test_array_buffer() { let gil = Python::acquire_gil(); let py = gil.python(); diff --git a/src/err.rs b/src/err.rs index 51c021ab..5ffb2900 100644 --- a/src/err.rs +++ b/src/err.rs @@ -39,9 +39,9 @@ Defines a new exception type. # Example ``` #[macro_use] -extern crate cpython; +extern crate pyo3; -use cpython::{Python, PyDict}; +use pyo3::{Python, PyDict}; py_exception!(mymodule, CustomError); diff --git a/src/ffi/README.md b/src/ffi/README.md index 2b0f4a72..64dca041 100644 --- a/src/ffi/README.md +++ b/src/ffi/README.md @@ -1,30 +1,15 @@ -rust-python3-sys -==================== +rust python3 ffi +================ [Rust](http://www.rust-lang.org/) FFI declarations for Python 3. -Supports the PEP 384 stable ABI for Python 3.3 or higher. +Supports the PEP 384 stable ABI for Python 3.4 or higher. --- This [cargo -sys package](http://doc.crates.io/build-script.html#*-sys-packages) provides `python3` declarations. Licensed under the Python license (see `LICENSE`). -For a safe high-level API, see [rust-cpython](https://github.com/dgrunwald/rust-cpython). - -# Usage - -[`python3-sys` is available on crates.io](https://crates.io/crates/python3-sys) so you can use it like this (in your `Cargo.toml`): - -```toml -[dependencies.python3-sys] -version = "*" -``` - -In Rust, import the crate like this: - -```rust -extern crate python3_sys as py; -``` +For a safe high-level API, see [rust-cpython](https://github.com/PyO3/PyO3). Documentation for the python API is available on [https://docs.python.org/3/c-api/]. diff --git a/src/function.rs b/src/function.rs index 34ceee20..3ac1bb4e 100644 --- a/src/function.rs +++ b/src/function.rs @@ -78,9 +78,9 @@ macro_rules! py_method_def { /// /// # Example /// ``` -/// #[macro_use] extern crate cpython; -/// use cpython::{Python, PyResult, PyErr, PyDict}; -/// use cpython::{exc}; +/// #[macro_use] extern crate pyo3; +/// use pyo3::{Python, PyResult, PyErr, PyDict}; +/// use pyo3::{exc}; /// /// fn multiply(py: Python, lhs: i32, rhs: i32) -> PyResult { /// match lhs.checked_mul(rhs) { diff --git a/src/lib.rs b/src/lib.rs index 3d5bf4d9..d3f21ceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,14 +51,14 @@ //! The vast majority of operations in this library will return `PyResult<...>`. //! This is an alias for the type `Result<..., PyErr>`. //! -//! A `PyErr` represents a Python exception. Errors within the rust-cpython library are +//! A `PyErr` represents a Python exception. Errors within the PyO3 library are //! also exposed as Python exceptions. //! //! # Example //! ``` -//! extern crate cpython; +//! extern crate pyo3; //! -//! use cpython::{Python, PyDict, PyResult}; +//! use pyo3::{Python, PyDict, PyResult}; //! //! fn main() { //! let gil = Python::acquire_gil(); @@ -204,10 +204,10 @@ pub mod _detail { /// /// # Example /// ``` -/// #[macro_use] extern crate cpython; -/// use cpython::{Python, PyResult, PyObject}; +/// #[macro_use] extern crate pyo3; +/// use pyo3::{Python, PyResult, PyObject}; /// -/// py_module_initializer!(hello, inithello, PyInit_hello, |py, m| { +/// py_module_initializer!(hello, PyInit_hello, |py, m| { /// m.add(py, "__doc__", "Module documentation string")?; /// m.add(py, "run", py_fn!(py, run()))?; /// Ok(()) @@ -220,14 +220,14 @@ pub mod _detail { /// # fn main() {} /// ``` /// -/// In your `Cargo.toml`, use the `extension-module` feature for the `cpython` dependency: +/// In your `Cargo.toml`, use the `extension-module` feature for the `pyo3` dependency: /// ```cargo -/// [dependencies.cpython] +/// [dependencies.pyo3] /// version = "*" /// features = ["extension-module"] /// ``` /// The full example project can be found at: -/// https://github.com/dgrunwald/rust-cpython/tree/master/extensions/hello +/// https://github.com/PyO3/setuptools-rust/tree/master/example/extensions /// /// Rust will compile the code into a file named `libhello.so`, but we have to /// rename the file in order to use it with Python: diff --git a/src/objects/tuple.rs b/src/objects/tuple.rs index 842eed1b..92337b1f 100644 --- a/src/objects/tuple.rs +++ b/src/objects/tuple.rs @@ -189,10 +189,10 @@ tuple_conversion!(9, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D), /// /// # Example /// ``` -/// let gil_guard = cpython::Python::acquire_gil(); -/// let py = gil_guard.python(); +/// let gil = pyo3::Python::acquire_gil(); +/// let py = gil.python(); /// let os = py.import("os").unwrap(); -/// let pid = os.call(py, "get_pid", cpython::NoArgs, None); +/// let pid = os.call(py, "get_pid", pyo3::NoArgs, None); /// ``` #[derive(Copy, Clone, Debug)] pub struct NoArgs; diff --git a/src/py_class/py_class.rs b/src/py_class/py_class.rs index b964117a..31a08a0a 100644 --- a/src/py_class/py_class.rs +++ b/src/py_class/py_class.rs @@ -33,8 +33,8 @@ in all function bodies. # Example ``` -#[macro_use] extern crate cpython; -use cpython::{Python, PyResult, PyDict}; +#[macro_use] extern crate pyo3; +use pyo3::{Python, PyResult, PyDict}; py_class!(class MyType |py| { data number: i32; @@ -87,7 +87,7 @@ impl MyType { } ``` -* The generated type implements a number of traits from the `cpython` crate. +* The generated type implements a number of traits from the `pyo3` crate. * The inherent `create_instance` method can create new Python objects given the values for the data fields. * Private accessors functions are created for the data fields. @@ -182,9 +182,9 @@ as every cycle must contain at least one mutable reference. Example: ``` -#[macro_use] extern crate cpython; +#[macro_use] extern crate pyo3; use std::{mem, cell}; -use cpython::{PyObject, PyDrop}; +use pyo3::{PyObject, PyDrop}; py_class!(class ClassWithGCSupport |py| { data obj: cell::RefCell>; @@ -235,9 +235,9 @@ Iterators can be defined using the Python special methods `__iter__` and `__next Example: ``` -#[macro_use] extern crate cpython; +#[macro_use] extern crate pyo3; use std::cell::RefCell; -use cpython::{PyObject, PyClone, PyResult}; +use pyo3::{PyObject, PyClone, PyResult}; py_class!(class MyIterator |py| { data iter: RefCell + Send>>; diff --git a/src/py_class/slots.rs b/src/py_class/slots.rs index 2d4e57c8..d80e185e 100644 --- a/src/py_class/slots.rs +++ b/src/py_class/slots.rs @@ -72,7 +72,6 @@ macro_rules! py_class_type_object_flags { }; } -#[cfg(feature="python3-sys")] pub const TPFLAGS_DEFAULT : ::libc::c_ulong = ffi::Py_TPFLAGS_DEFAULT; #[cfg(Py_3_5)] diff --git a/src/pythonrun.rs b/src/pythonrun.rs index f8ac9242..11875eb7 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -78,7 +78,7 @@ pub fn prepare_freethreaded_python() { /// /// # Example /// ``` -/// use cpython::Python; +/// use pyo3::Python; /// /// { /// let gil_guard = Python::acquire_gil(); @@ -123,7 +123,7 @@ impl GILGuard { /// # Example /// ``` /// use std::cell::Cell; -/// use cpython::{Python, GILProtected}; +/// use pyo3::{Python, GILProtected}; /// /// let data = GILProtected::new(Cell::new(0)); /// diff --git a/tests/test_class.rs b/tests/test_class.rs index 8cbc7f52..c969bf04 100644 --- a/tests/test_class.rs +++ b/tests/test_class.rs @@ -1,13 +1,13 @@ #![allow(dead_code, unused_variables)] -#[macro_use] extern crate cpython; +#[macro_use] extern crate pyo3; -use cpython::*; +use pyo3::*; use std::{mem, isize, iter}; use std::cell::{Cell, RefCell}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; -use cpython::_detail::ffi; +use pyo3::ffi; macro_rules! py_run { ($py:expr, $val:ident, $code:expr) => {{ @@ -369,8 +369,8 @@ py_class!(class StringMethods |py| { Ok(format!("format({})", format_spec)) } - def __unicode__(&self) -> PyResult { - Ok(PyUnicode::new(py, "unicode")) + def __unicode__(&self) -> PyResult { + Ok(PyString::new(py, "unicode")) } def __bytes__(&self) -> PyResult { diff --git a/tests/test_function.rs b/tests/test_function.rs index 95852763..2e450542 100644 --- a/tests/test_function.rs +++ b/tests/test_function.rs @@ -1,6 +1,6 @@ -#[macro_use] extern crate cpython; +#[macro_use] extern crate pyo3; -use cpython::{PyResult, Python, NoArgs, ObjectProtocol, PyDict}; +use pyo3::{PyResult, Python, NoArgs, ObjectProtocol, PyDict}; use std::sync::atomic; use std::sync::atomic::Ordering::Relaxed; diff --git a/tests/test_slice.rs b/tests/test_slice.rs index e532092c..3f4f833e 100644 --- a/tests/test_slice.rs +++ b/tests/test_slice.rs @@ -1,8 +1,8 @@ #![allow(dead_code, unused_variables)] -#[macro_use] extern crate cpython; +#[macro_use] extern crate pyo3; -use cpython::*; +use pyo3::*; #[test]