Skip to content

Commit

Permalink
only re-export __all__ if it's set
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Apr 29, 2022
1 parent a78b3fd commit c06742f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion guide/src/project_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ wheel. For convenience, this file includes the following:
from .my_project import *

__doc__ = my_project.__doc__
__all__ = my_project.__all__
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__all__ = {module_name}.__all__\n",
"from .{module_name} import *\n\
\n\
__doc__ = {module_name}.__doc__\n\
if hasattr({module_name}, \"__all__\"):\n\
\t__all__ = {module_name}.__all__\n",
module_name = module_name
)
.as_bytes(),
Expand Down
3 changes: 2 additions & 1 deletion src/templates/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ from .{{ crate_name }} import *


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

0 comments on commit c06742f

Please sign in to comment.