Tries to import a FastStream app from a module.
PARAMETER | DESCRIPTION |
module | Path to the module containing the app. TYPE: Path |
app | Name of the FastStream app. TYPE: str |
RETURNS | DESCRIPTION |
FastStream | The imported FastStream app object. |
RAISES | DESCRIPTION |
FileNotFoundError | If the module file is not found. |
BadParameter | If the module or app name is not provided correctly. |
Source code in faststream/cli/utils/imports.py
| def try_import_app(module: Path, app: str) -> FastStream:
"""Tries to import a FastStream app from a module.
Args:
module: Path to the module containing the app.
app: Name of the FastStream app.
Returns:
The imported FastStream app object.
Raises:
FileNotFoundError: If the module file is not found.
typer.BadParameter: If the module or app name is not provided correctly.
"""
try:
app_object = import_object(module, app)
except FileNotFoundError as e:
typer.echo(e, err=True)
raise typer.BadParameter(
"Please, input module like [python_file:faststream_app_name] or [module:attribute]"
) from e
else:
return app_object # type: ignore
|