Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export __all__ in __init__.py for pure Rust project #886

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion guide/src/project_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/templates/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ from .{{ crate_name }} import *


__doc__ = {{ crate_name }}.__doc__
if hasattr({{ crate_name }}, "__all__"):
__all__ = {{ crate_name }}.__all__