Skip to content

Commit 94e39d6

Browse files
committed
python: reinstate lazy imports
1 parent ad1bbdb commit 94e39d6

File tree

9 files changed

+72
-33
lines changed

9 files changed

+72
-33
lines changed
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# flake8: noqa
22

3-
# import apis into api package
4-
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
5-
{{/apis}}{{/apiInfo}}
3+
if __import__("typing").TYPE_CHECKING:
4+
{{>exports_api}}
5+
else:
6+
from lazy_imports import LazyModule, as_package, load
7+
8+
load(
9+
LazyModule(
10+
*as_package(__file__),
11+
"""{{>exports_api}}""",
12+
name=__name__,
13+
doc=__doc__,
14+
)
15+
)

modules/openapi-generator/src/main/resources/python/__init__model.mustache

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
{{>partial_header}}
55

66

7-
# import models into model package
8-
{{#models}}
9-
{{#model}}
10-
from {{modelPackage}}.{{classFilename}} import {{classname}}
11-
{{/model}}
12-
{{/models}}
7+
if __import__("typing").TYPE_CHECKING:
8+
{{>exports_model}}
9+
else:
10+
from lazy_imports import LazyModule, as_package, load
11+
12+
load(
13+
LazyModule(
14+
*as_package(__file__),
15+
"""{{>exports_model}}""",
16+
name=__name__,
17+
doc=__doc__,
18+
)
19+
)

modules/openapi-generator/src/main/resources/python/__init__package.mustache

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,21 @@ __all__ = [
2424
{{/-last}}{{#-last}},{{/-last}}{{/model}}{{/models}}
2525
]
2626

27-
# import apis into sdk package
28-
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} as {{classname}}
29-
{{/apis}}{{/apiInfo}}
30-
# import ApiClient
31-
from {{packageName}}.api_response import ApiResponse as ApiResponse
32-
from {{packageName}}.api_client import ApiClient as ApiClient
33-
from {{packageName}}.configuration import Configuration as Configuration
34-
from {{packageName}}.exceptions import OpenApiException as OpenApiException
35-
from {{packageName}}.exceptions import ApiTypeError as ApiTypeError
36-
from {{packageName}}.exceptions import ApiValueError as ApiValueError
37-
from {{packageName}}.exceptions import ApiKeyError as ApiKeyError
38-
from {{packageName}}.exceptions import ApiAttributeError as ApiAttributeError
39-
from {{packageName}}.exceptions import ApiException as ApiException
40-
{{#hasHttpSignatureMethods}}
41-
from {{packageName}}.signing import HttpSigningConfiguration as HttpSigningConfiguration
42-
{{/hasHttpSignatureMethods}}
43-
44-
# import models into sdk package
45-
{{#models}}
46-
{{#model}}
47-
from {{modelPackage}}.{{classFilename}} import {{classname}} as {{classname}}
48-
{{/model}}
49-
{{/models}}
27+
if __import__("typing").TYPE_CHECKING:
28+
{{>exports_package}}
29+
else:
30+
from lazy_imports import LazyModule, as_package, load
31+
32+
load(
33+
LazyModule(
34+
*as_package(__file__),
35+
("__version__", __version__),
36+
("__all__", __all__),
37+
"""{{>exports_package}}""",
38+
name=__name__,
39+
doc=__doc__,
40+
)
41+
)
5042
{{#recursionLimit}}
5143

5244
__import__('sys').setrecursionlimit({{{.}}})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# import apis into api package
2+
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}}
3+
{{/apis}}{{/apiInfo}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# import models into model package
2+
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}
3+
{{/model}}{{/models}}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# import apis into sdk package
2+
{{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} as {{classname}}
3+
{{/apis}}{{/apiInfo}}
4+
# import ApiClient
5+
from {{packageName}}.api_response import ApiResponse as ApiResponse
6+
from {{packageName}}.api_client import ApiClient as ApiClient
7+
from {{packageName}}.configuration import Configuration as Configuration
8+
from {{packageName}}.exceptions import OpenApiException as OpenApiException
9+
from {{packageName}}.exceptions import ApiTypeError as ApiTypeError
10+
from {{packageName}}.exceptions import ApiValueError as ApiValueError
11+
from {{packageName}}.exceptions import ApiKeyError as ApiKeyError
12+
from {{packageName}}.exceptions import ApiAttributeError as ApiAttributeError
13+
from {{packageName}}.exceptions import ApiException as ApiException
14+
{{#hasHttpSignatureMethods}}
15+
from {{packageName}}.signing import HttpSigningConfiguration as HttpSigningConfiguration
16+
{{/hasHttpSignatureMethods}}
17+
18+
# import models into sdk package
19+
{{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}} as {{classname}}
20+
{{/model}}{{/models}}

modules/openapi-generator/src/main/resources/python/pyproject.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pycryptodome = ">= 3.9.0"
4141
{{/hasHttpSignatureMethods}}
4242
pydantic = ">= 2"
4343
typing-extensions = ">= 4.7.1"
44+
lazy-imports = ">= 1, < 2"
4445
{{/poetry1}}
4546
{{^poetry1}}
4647
requires-python = "^3.9"
@@ -60,7 +61,8 @@ dependencies = [
6061
"pycryptodome (>=3.9.0)",
6162
{{/hasHttpSignatureMethods}}
6263
"pydantic (>=2)",
63-
"typing-extensions (>=4.7.1)"
64+
"typing-extensions (>=4.7.1)",
65+
"lazy-imports (>=1,<2)"
6466
]
6567
6668
[project.urls]

modules/openapi-generator/src/main/resources/python/requirements.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ pycryptodome >= 3.9.0
1313
{{/hasHttpSignatureMethods}}
1414
pydantic >= 2
1515
typing-extensions >= 4.7.1
16+
lazy-imports >= 1, < 2

modules/openapi-generator/src/main/resources/python/setup.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ REQUIRES = [
3030
{{/hasHttpSignatureMethods}}
3131
"pydantic >= 2",
3232
"typing-extensions >= 4.7.1",
33+
"lazy-imports >= 1, < 2",
3334
]
3435

3536
setup(

0 commit comments

Comments
 (0)