Skip to content

Commit 6c4fe3e

Browse files
authored
Merge pull request #57 from python-ellar/scaffold_with_lazy
Enhancement: Scaffolding with lazy loaded modules
2 parents 5850d8b + e71641a commit 6c4fe3e

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

ellar_cli/scaffolding/project_template/project_name/server.ellar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
22

3-
from ellar.common.constants import ELLAR_CONFIG_MODULE
43
from ellar.app import AppFactory
4+
from ellar.common.constants import ELLAR_CONFIG_MODULE
5+
from ellar.core import LazyModuleImport as lazyLoad
56
# from ellar.openapi import OpenAPIDocumentModule, OpenAPIDocumentBuilder, SwaggerUI
6-
from .root_module import ApplicationModule
77

88
application = AppFactory.create_from_app_module(
9-
ApplicationModule,
9+
lazyLoad("{{project_name}}.root_module:ApplicationModule"),
1010
config_module=os.environ.get(
1111
ELLAR_CONFIG_MODULE, "{{config_prefix}}{{project_name}}.config:DevelopmentConfig"
1212
),

ellar_cli/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def import_project_meta(
145145
else ellar_py_projects.default_project
146146
)
147147

148-
_ellar_pyproject_serializer = cls.schema_cls.parse_obj(
148+
_ellar_pyproject_serializer = cls.schema_cls.model_validate(
149149
ellar_py_projects.get_project(project_to_load)
150150
)
151151

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies = [
4343
# exclude 0.11.2 and 0.11.3 due to https://github.com/sdispater/tomlkit/issues/225
4444
"tomlkit >=0.11.1,<1.0.0,!=0.11.2,!=0.11.3",
4545
"uvicorn[standard] == 0.23.2",
46-
"ellar >= 0.5.8"
46+
"ellar >= 0.6.0"
4747
]
4848

4949
[project.scripts]

tests/sample_app/example_project/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from ellar.app import AppFactory
44
from ellar.common.constants import ELLAR_CONFIG_MODULE
5+
from ellar.core import LazyModuleImport as lazyLoad
56

67
# from ellar.openapi import OpenAPIDocumentModule, OpenAPIDocumentBuilder
7-
from .root_module import ApplicationModule
88

99
application = AppFactory.create_from_app_module(
10-
ApplicationModule,
10+
lazyLoad("example_project.root_module:ApplicationModule"),
1111
config_module=os.environ.get(
1212
ELLAR_CONFIG_MODULE, "example_project.config:DevelopmentConfig"
1313
),

tests/sample_app/example_project_2/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from ellar.app import AppFactory
44
from ellar.common.constants import ELLAR_CONFIG_MODULE
5+
from ellar.core import LazyModuleImport as lazyLoad
56

67
# from ellar.openapi import OpenAPIDocumentModule, OpenAPIDocumentBuilder
7-
from .root_module import ApplicationModule
88

99
application = AppFactory.create_from_app_module(
10-
ApplicationModule,
10+
lazyLoad("example_project_2.root_module:ApplicationModule"),
1111
config_module=os.environ.get(
1212
ELLAR_CONFIG_MODULE, "example_project_2.config:DevelopmentConfig"
1313
),

tests/test_ellar_cli_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_import_application_works(tmp_path, write_empty_py_project, process_runn
155155

156156
def test_import_configuration_works(tmpdir, write_empty_py_project, process_runner):
157157
result = process_runner(["ellar", "create-project", "new_project_two"])
158-
assert result.returncode == 0
158+
assert result.returncode == 0, result.stderr
159159

160160
ellar_cli_service = EllarCLIService.import_project_meta()
161161
config = ellar_cli_service.import_configuration()
@@ -165,7 +165,7 @@ def test_import_configuration_works(tmpdir, write_empty_py_project, process_runn
165165

166166
def test_import_root_module_works(write_empty_py_project, process_runner):
167167
result = process_runner(["ellar", "create-project", "new_project_three"])
168-
assert result.returncode == 0
168+
assert result.returncode == 0, result.stderr
169169

170170
ellar_cli_service = EllarCLIService.import_project_meta()
171171
root_module = ellar_cli_service.import_root_module()

0 commit comments

Comments
 (0)