-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: split maturin and setuptools-rust examples
- Loading branch information
1 parent
5daadd4
commit c39b0ec
Showing
55 changed files
with
1,136 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
authors = ["PyO3 Authors"] | ||
name = "maturin_extension" | ||
version = "0.1.0" | ||
description = "A Python wrapper for the Rust API for purposes of testing" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
|
||
[dependencies.pyo3] | ||
path = "../../" | ||
features = ["extension-module"] | ||
|
||
[lib] | ||
name = "maturin_extension" | ||
crate-type = ["cdylib"] | ||
|
||
[package.metadata.maturin] | ||
classifier=[ | ||
"License :: OSI Approved :: MIT License", | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Developers", | ||
"Programming Language :: Python", | ||
"Programming Language :: Rust", | ||
"Operating System :: POSIX", | ||
"Operating System :: MacOS :: MacOS X", | ||
] |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/rustapi_module/README.md → examples/maturin_extension/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# rustapi_module | ||
# maturin_extension | ||
|
||
A simple extension module built using PyO3. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .maturin_extension import * | ||
|
||
from .register_submodules import _register_submodules | ||
|
||
_register_submodules() |
20 changes: 20 additions & 0 deletions
20
examples/maturin_extension/maturin_extension/register_submodules.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
import sys | ||
import importlib | ||
import importlib.abc | ||
|
||
# Import the local extension | ||
from .maturin_extension import __file__ as rust_extension_path | ||
|
||
|
||
class SubmoduleFinder(importlib.abc.MetaPathFinder): | ||
def find_module(self, fullname, path): | ||
if fullname.startswith("maturin_extension."): | ||
return importlib.machinery.ExtensionFileLoader( | ||
fullname, rust_extension_path | ||
) | ||
|
||
|
||
def _register_submodules(): | ||
"""Inject custom finder into sys.meta_path""" | ||
sys.meta_path.append(SubmoduleFinder()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["maturin"] | ||
build-backend = "maturin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pip>=19.1 | ||
hypothesis>=3.55 | ||
pytest>=3.5.0 | ||
psutil>=5.6 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use pyo3::prelude::*; | ||
use pyo3::wrap_pymodule; | ||
|
||
pub mod buf_and_str; | ||
pub mod datetime; | ||
pub mod dict_iter; | ||
pub mod misc; | ||
pub mod objstore; | ||
pub mod othermod; | ||
pub mod pyclass_iter; | ||
pub mod subclassing; | ||
|
||
use buf_and_str::*; | ||
use datetime::*; | ||
use dict_iter::*; | ||
use misc::*; | ||
use objstore::*; | ||
use othermod::*; | ||
use pyclass_iter::*; | ||
use subclassing::*; | ||
|
||
#[pymodule] | ||
fn maturin_extension(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_wrapped(wrap_pymodule!(buf_and_str))?; | ||
m.add_wrapped(wrap_pymodule!(datetime))?; | ||
m.add_wrapped(wrap_pymodule!(dict_iter))?; | ||
m.add_wrapped(wrap_pymodule!(misc))?; | ||
m.add_wrapped(wrap_pymodule!(objstore))?; | ||
m.add_wrapped(wrap_pymodule!(othermod))?; | ||
m.add_wrapped(wrap_pymodule!(pyclass_iter))?; | ||
m.add_wrapped(wrap_pymodule!(subclassing))?; | ||
|
||
Ok(()) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/rustapi_module/tests/test_dict_iter.py → ...maturin_extension/tests/test_dict_iter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import maturin_extension.misc | ||
|
||
|
||
def test_issue_219(): | ||
# Should not deadlock | ||
maturin_extension.misc.issue_219() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...les/rustapi_module/tests/test_othermod.py → .../maturin_extension/tests/test_othermod.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rustapi_module/tests/test_pyclass_iter.py → ...urin_extension/tests/test_pyclass_iter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../rustapi_module/tests/test_subclassing.py → ...turin_extension/tests/test_subclassing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[tox] | ||
# can't install from sdist because local pyo3 repo can't be included in the sdist | ||
skipsdist = true | ||
|
||
[testenv] | ||
description = Run the unit tests under {basepython} | ||
deps = -rrequirements-dev.txt | ||
commands = | ||
# Use pip fork with in-tree-build feature (soon to be merged to master) | ||
pip install --upgrade git+https://github.com/davidhewitt/pip.git@fede74f7439f6c940f19a2357738b500372abe3d | ||
pip install . --use-feature=in-tree-build | ||
pytest {posargs} |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include pyproject.toml Cargo.toml | ||
recursive-include src * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# setuptools_rust_extension | ||
|
||
A simple extension module built using PyO3. | ||
|
||
## Build | ||
|
||
```shell | ||
python setup.py install | ||
``` | ||
|
||
## Testing | ||
|
||
To test install tox globally and run | ||
|
||
```shell | ||
tox -e py | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
examples/setuptools_rust_extension/setuptools_rust_extension/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .setuptools_rust_extension import * | ||
|
||
from .register_submodules import _register_submodules | ||
|
||
_register_submodules() |
20 changes: 20 additions & 0 deletions
20
examples/setuptools_rust_extension/setuptools_rust_extension/register_submodules.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
import sys | ||
import importlib | ||
import importlib.abc | ||
|
||
# Import the local extension | ||
from .setuptools_rust_extension import __file__ as rust_extension_path | ||
|
||
|
||
class SubmoduleFinder(importlib.abc.MetaPathFinder): | ||
def find_module(self, fullname, path): | ||
if fullname.startswith("setuptools_rust_extension."): | ||
return importlib.machinery.ExtensionFileLoader( | ||
fullname, rust_extension_path | ||
) | ||
|
||
|
||
def _register_submodules(): | ||
"""Inject custom finder into sys.meta_path""" | ||
sys.meta_path.append(SubmoduleFinder()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Objects related to PyBuffer and PyStr | ||
use pyo3::prelude::*; | ||
use pyo3::types::{PyBytes, PyString}; | ||
|
||
/// This is for confirming that PyBuffer does not cause memory leak | ||
#[pyclass] | ||
struct BytesExtractor {} | ||
|
||
#[pymethods] | ||
impl BytesExtractor { | ||
#[new] | ||
pub fn __new__() -> Self { | ||
BytesExtractor {} | ||
} | ||
|
||
pub fn from_bytes(&mut self, bytes: &PyBytes) -> PyResult<usize> { | ||
let byte_vec: Vec<u8> = bytes.extract().unwrap(); | ||
Ok(byte_vec.len()) | ||
} | ||
|
||
pub fn from_str(&mut self, string: &PyString) -> PyResult<usize> { | ||
let rust_string: String = string.extract().unwrap(); | ||
Ok(rust_string.len()) | ||
} | ||
|
||
pub fn from_str_lossy(&mut self, string: &PyString) -> PyResult<usize> { | ||
let rust_string_lossy: String = string.to_string_lossy().to_string(); | ||
Ok(rust_string_lossy.len()) | ||
} | ||
} | ||
|
||
#[pymodule] | ||
pub fn buf_and_str(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_class::<BytesExtractor>()?; | ||
Ok(()) | ||
} |
Oops, something went wrong.