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 2 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
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",
"from .{module_name} import *\n\
\n\
__doc__ = {module_name}.__doc__\n\
if hasattr({module_name}, \"__all__\"):\n\
\t__all__ = {module_name}.__all__\n",
mhils marked this conversation as resolved.
Show resolved Hide resolved
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__