Skip to content

Commit

Permalink
examples: export __doc__ in example projects
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Oct 1, 2021
1 parent e4b9840 commit 5d5ad25
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/maturin-starter/maturin_starter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# import the contents of the Rust library into the Python extension
from .maturin_starter import *

# optional: include the documentation from the Rust module
from . import maturin_starter

__doc__ = maturin_starter.__doc__
__all__ = maturin_starter.__all__ + ["PythonClass"]


class PythonClass:
def __init__(self, value: int) -> None:
Expand Down
1 change: 1 addition & 0 deletions examples/maturin-starter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl ExampleClass {
}
}

/// An example module implemented in Rust using PyO3.
#[pymodule]
fn maturin_starter(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<ExampleClass>()?;
Expand Down
10 changes: 9 additions & 1 deletion examples/maturin-starter/tests/test_maturin_starter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from maturin_starter import PythonClass, ExampleClass
from maturin_starter import ExampleClass, PythonClass


def test_python_class() -> None:
Expand All @@ -9,3 +9,11 @@ def test_python_class() -> None:
def test_example_class() -> None:
example = ExampleClass(value=11)
assert example.value == 11


def test_doc() -> None:
import maturin_starter

assert (
maturin_starter.__doc__ == "An example module implemented in Rust using PyO3."
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# import the contents of the Rust library into the Python extension
from ._setuptools_rust_starter import *

# optional: include the documentation from the Rust module
from . import setuptools_rust_starter

__doc__ = setuptools_rust_starter.__doc__
__all__ = setuptools_rust_starter.__all__ + ["PythonClass"]


class PythonClass:
def __init__(self, value: int) -> None:
Expand Down
1 change: 1 addition & 0 deletions examples/setuptools-rust-starter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl ExampleClass {
}
}

/// An example module implemented in Rust using PyO3.
#[pymodule]
fn _setuptools_rust_starter(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<ExampleClass>()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools_rust_starter import PythonClass, ExampleClass
from setuptools_rust_starter import ExampleClass, PythonClass


def test_python_class() -> None:
Expand All @@ -9,3 +9,12 @@ def test_python_class() -> None:
def test_example_class() -> None:
example = ExampleClass(value=11)
assert example.value == 11


def test_doc() -> None:
import setuptools_rust_starter

assert (
setuptools_rust_starter.__doc__
== "An example module implemented in Rust using PyO3."
)

0 comments on commit 5d5ad25

Please sign in to comment.