diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index cea34c65..64d591f8 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -5,6 +5,12 @@ hide: # Release Notes +## Unreleased + +### Fixed + +- Fix cli detection of wrapped esmerald instances or different ASGI servers. + ## 3.5.1 ### Changed diff --git a/esmerald/core/directives/constants.py b/esmerald/core/directives/constants.py index 5e84e9a9..7c996bcf 100644 --- a/esmerald/core/directives/constants.py +++ b/esmerald/core/directives/constants.py @@ -4,6 +4,7 @@ HELP_PARAMETER = "--help" EXCLUDED_DIRECTIVES = ["createproject", "createapp", "createdeployment"] IGNORE_DIRECTIVES = ["directives"] -DISCOVERY_FILES = ["application.py", "app.py", "main.py"] +DISCOVERY_FILES = ["application.py", "app.py", "main.py", "asgi.py"] DISCOVERY_FUNCTIONS = ["get_application", "get_app"] +DISCOVERY_ATTRS = ["application", "app"] TREAT_AS_PROJECT_DIRECTIVE = ["deployment"] diff --git a/esmerald/core/directives/env.py b/esmerald/core/directives/env.py index 8ad3f266..b7c8fadf 100644 --- a/esmerald/core/directives/env.py +++ b/esmerald/core/directives/env.py @@ -7,6 +7,7 @@ from esmerald import ChildEsmerald, Esmerald from esmerald.core.directives.constants import ( + DISCOVERY_ATTRS, DISCOVERY_FILES, DISCOVERY_FUNCTIONS, ESMERALD_DISCOVER_APP, @@ -77,9 +78,7 @@ def _get_folders(self, path: Path) -> typing.List[str]: """ return [directory.path for directory in os.scandir(path) if directory.is_dir()] - def _find_app_in_folder( - self, path: Path, cwd: Path - ) -> typing.Union[Scaffold, None]: + def _find_app_in_folder(self, path: Path, cwd: Path) -> typing.Union[Scaffold, None]: """ Iterates inside the folder and looks up to the DISCOVERY_FILES. """ @@ -94,6 +93,13 @@ def _find_app_in_folder( # Load file from module module = import_module(dotted_path) + # FIrst check some attrs + for attr in DISCOVERY_ATTRS: + value = getattr(module, attr, None) + if value is not None: + app_path = f"{dotted_path}:{attr}" + return Scaffold(app=getattr(module, attr), path=app_path) + # Iterates through the elements of the module. for attr, value in module.__dict__.items(): if isinstance(value, Esmerald):