Skip to content

Commit 685847e

Browse files
committed
Update to optimize imports for faster startup times
Don't import all schemas instead import the schemas we actually use. This also makes the importing of services lazy so that only schemas are imported which we actually want to use. This fixes a performance issue where just importing commercetools would import all the marshmallow schemas which is terribly slow.
1 parent d984bd4 commit 685847e

File tree

5 files changed

+151
-119
lines changed

5 files changed

+151
-119
lines changed

codegen/generate_schema.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ def get_module_nodes(self):
6565
return result
6666

6767
def generate_init_module(self, modules):
68-
nodes = [
69-
ast.ImportFrom(
70-
module=module, names=[ast.alias(name="* # noqa", asname=None)], level=1
71-
)
72-
for module in sorted(modules)
73-
]
74-
return ast.Module(body=nodes)
68+
return ast.Module(body=[])
7569

7670
def add_type_definition(self, resource):
7771
"""Create a class definition"""
@@ -277,7 +271,7 @@ def _create_schema_property(self, prop):
277271
node = self._get_property_field(prop)
278272

279273
if prop.many:
280-
if node.func.id == "marshmallow.fields.Nested":
274+
if node.func.id == "helpers.LazyNestedField":
281275
node.keywords.append(
282276
ast.keyword(
283277
arg="many", value=ast.NameConstant(value=True, kind=None)
@@ -462,8 +456,11 @@ def _create_nested_field(self, type_obj):
462456
)
463457
464458
"""
459+
self.generator.add_import_statement(
460+
self.resource.package_name, "commercetools", "helpers"
461+
)
465462
return ast.Call(
466-
func=ast.Name(id="marshmallow.fields.Nested"),
463+
func=ast.Name(id="helpers.LazyNestedField"),
467464
args=[],
468465
keywords=[
469466
ast.keyword(

0 commit comments

Comments
 (0)