Skip to content

Commit

Permalink
Merge pull request #886 from mhils/reexport-all
Browse files Browse the repository at this point in the history
Re-export `__all__` in `__init__.py` for pure Rust project
  • Loading branch information
messense authored Apr 29, 2022
2 parents eaae476 + 86a6588 commit 4a18862
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
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__

0 comments on commit 4a18862

Please sign in to comment.