As far as I've tried, including scripts from inside the python/package directory slows down their help messages since they always import the package first (running everything in __init__.py). Before I had a need for Rust in my library, I could avoid this via poetry with the following layout:
project
├── src
│ ├── __init__.py
│ └── ...
├── cli.py <-- app() lives in here
├── pyproject.toml
└── README.md
The cli.py script looks like this to avoid slow imports for --help:
from typer import Typer
app = Typer()
@app.command
def main(...):
import project
# do stuff
if __name__ == "__main__":
app()
And including cli:app as an entrypoint:
[tool.poetry.scripts]
project = "cli:app"
Moving to a maturin mixed project now, this breaks with the follow error:
$ project --help
Traceback...
from cli import app
ModuleNotFoundError: No module named 'cli'
Thus, I've had to go back to including the CLI in the python/project directory and this slows down the help message responsiveness by several seconds. This is not a deal breaker, but it would be great to be able to do this. Otherwise, I'm curious if there are other workarounds to improve help message responsiveness that are compatible with maturin. Thanks!
As far as I've tried, including scripts from inside the python/package directory slows down their help messages since they always import the package first (running everything in
__init__.py
). Before I had a need for Rust in my library, I could avoid this via poetry with the following layout:The
cli.py
script looks like this to avoid slow imports for--help
:And including
cli:app
as an entrypoint:Moving to a maturin mixed project now, this breaks with the follow error:
Thus, I've had to go back to including the CLI in the python/project directory and this slows down the help message responsiveness by several seconds. This is not a deal breaker, but it would be great to be able to do this. Otherwise, I'm curious if there are other workarounds to improve help message responsiveness that are compatible with maturin. Thanks!