Skip to content

Commit cea2aa3

Browse files
committed
examples: split maturin and setuptools-rust examples
1 parent 5daadd4 commit cea2aa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1133
-43
lines changed

examples/maturin_extension/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
authors = ["PyO3 Authors"]
3+
name = "maturin_extension"
4+
version = "0.1.0"
5+
description = "A Python wrapper for the Rust API for purposes of testing"
6+
edition = "2018"
7+
8+
[dependencies]
9+
10+
[dependencies.pyo3]
11+
path = "../../"
12+
features = ["extension-module"]
13+
14+
[lib]
15+
name = "maturin_extension"
16+
crate-type = ["cdylib"]
17+
18+
[package.metadata.maturin]
19+
classifier=[
20+
"License :: OSI Approved :: MIT License",
21+
"Development Status :: 3 - Alpha",
22+
"Intended Audience :: Developers",
23+
"Programming Language :: Python",
24+
"Programming Language :: Rust",
25+
"Operating System :: POSIX",
26+
"Operating System :: MacOS :: MacOS X",
27+
]

examples/rustapi_module/README.md renamed to examples/maturin_extension/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# rustapi_module
1+
# maturin_extension
22

33
A simple extension module built using PyO3.
44

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .maturin_extension import *
2+
3+
from .register_submodules import _register_submodules
4+
5+
_register_submodules()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import sys
3+
import importlib
4+
import importlib.abc
5+
6+
# Import the local extension
7+
from .maturin_extension import __file__ as rust_extension_path
8+
9+
10+
class SubmoduleFinder(importlib.abc.MetaPathFinder):
11+
def find_module(self, fullname, path):
12+
if fullname.startswith("maturin_extension."):
13+
return importlib.machinery.ExtensionFileLoader(
14+
fullname, rust_extension_path
15+
)
16+
17+
18+
def _register_submodules():
19+
"""Inject custom finder into sys.meta_path"""
20+
sys.meta_path.append(SubmoduleFinder())
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pip>=19.1
2+
hypothesis>=3.55
3+
pytest>=3.5.0
4+
psutil>=5.6

examples/rustapi_module/src/dict_iter.rs renamed to examples/maturin_extension/src/dict_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use pyo3::prelude::*;
33
use pyo3::types::PyDict;
44

55
#[pymodule]
6-
fn test_dict(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
6+
fn dict_iter(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
77
m.add_class::<DictSize>()?;
88
Ok(())
99
}

examples/maturin_extension/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use pyo3::prelude::*;
2+
use pyo3::wrap_pymodule;
3+
4+
pub mod buf_and_str;
5+
pub mod datetime;
6+
pub mod dict_iter;
7+
pub mod misc;
8+
pub mod objstore;
9+
pub mod othermod;
10+
pub mod pyclass_iter;
11+
pub mod subclassing;
12+
13+
use buf_and_str::*;
14+
use datetime::*;
15+
use dict_iter::*;
16+
use misc::*;
17+
use objstore::*;
18+
use othermod::*;
19+
use pyclass_iter::*;
20+
use subclassing::*;
21+
22+
#[pymodule]
23+
fn maturin_extension(_py: Python, m: &PyModule) -> PyResult<()> {
24+
m.add_wrapped(wrap_pymodule!(buf_and_str))?;
25+
m.add_wrapped(wrap_pymodule!(datetime))?;
26+
m.add_wrapped(wrap_pymodule!(dict_iter))?;
27+
m.add_wrapped(wrap_pymodule!(misc))?;
28+
m.add_wrapped(wrap_pymodule!(objstore))?;
29+
m.add_wrapped(wrap_pymodule!(othermod))?;
30+
m.add_wrapped(wrap_pymodule!(pyclass_iter))?;
31+
m.add_wrapped(wrap_pymodule!(subclassing))?;
32+
33+
Ok(())
34+
}

0 commit comments

Comments
 (0)