diff --git a/Changelog.md b/Changelog.md index f7e2c38f4..d56ea103c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +* Re-export `__all__` for pure Rust projects in [#886](https://github.com/PyO3/maturin/pull/886) + ## [0.12.14] - 2022-04-25 * Fix PyPy pep517 build when abi3 feature is enabled in [#883](https://github.com/PyO3/maturin/pull/883) diff --git a/guide/src/project_layout.md b/guide/src/project_layout.md index 6d0e36cfc..d1f17fd98 100644 --- a/guide/src/project_layout.md +++ b/guide/src/project_layout.md @@ -22,7 +22,9 @@ wheel. For convenience, this file includes the following: ```python from .my_project import * -__doc__ = .my_project.__doc__ +__doc__ = my_project.__doc__ +if hasattr(my_project, "__all__"): + __all__ = my_project.__all__ ``` such that the module functions may be called directly with: diff --git a/src/module_writer.rs b/src/module_writer.rs index 267486e95..8cc8f3b83 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -656,7 +656,11 @@ pub fn write_bindings_module( writer.add_bytes( &module.join("__init__.py"), format!( - "from .{module_name} import *\n\n__doc__ = {module_name}.__doc__\n", + r#"from .{module_name} import * + +__doc__ = {module_name}.__doc__ +if hasattr({module_name}, "__all__"): + __all__ = {module_name}.__all__"#, module_name = module_name ) .as_bytes(), diff --git a/src/templates/__init__.py.j2 b/src/templates/__init__.py.j2 index 145182845..a64034451 100644 --- a/src/templates/__init__.py.j2 +++ b/src/templates/__init__.py.j2 @@ -2,3 +2,5 @@ from .{{ crate_name }} import * __doc__ = {{ crate_name }}.__doc__ +if hasattr({{ crate_name }}, "__all__"): + __all__ = {{ crate_name }}.__all__