Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Fix cli detection of wrapped esmerald instances or different ASGI servers.
  • Loading branch information
devkral committed Nov 27, 2024
1 parent b1d77a4 commit 066214d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/en/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ hide:

# Release Notes

## Unreleased

### Fixed

- Fix cli detection of wrapped esmerald instances or different ASGI servers.

## 3.5.1

### Changed
Expand Down
3 changes: 2 additions & 1 deletion esmerald/core/directives/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
12 changes: 9 additions & 3 deletions esmerald/core/directives/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from esmerald import ChildEsmerald, Esmerald
from esmerald.core.directives.constants import (
DISCOVERY_ATTRS,
DISCOVERY_FILES,
DISCOVERY_FUNCTIONS,
ESMERALD_DISCOVER_APP,
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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):
Expand Down

0 comments on commit 066214d

Please sign in to comment.