@autorest/python 5.12.2 → 5.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +60 -0
- package/autorest/black/__init__.py +4 -1
- package/autorest/codegen/models/client.py +22 -19
- package/autorest/codegen/models/credential_schema.py +3 -3
- package/autorest/codegen/models/dictionary_schema.py +1 -1
- package/autorest/codegen/models/enum_schema.py +2 -2
- package/autorest/codegen/models/imports.py +90 -50
- package/autorest/codegen/models/list_schema.py +1 -1
- package/autorest/codegen/models/lro_operation.py +15 -9
- package/autorest/codegen/models/object_schema.py +2 -2
- package/autorest/codegen/models/operation.py +28 -26
- package/autorest/codegen/models/operation_group.py +5 -14
- package/autorest/codegen/models/paging_operation.py +9 -9
- package/autorest/codegen/models/parameter.py +6 -7
- package/autorest/codegen/models/parameter_list.py +1 -0
- package/autorest/codegen/models/primitive_schemas.py +2 -2
- package/autorest/codegen/models/property.py +1 -1
- package/autorest/codegen/models/request_builder.py +7 -6
- package/autorest/codegen/models/request_builder_parameter.py +0 -2
- package/autorest/codegen/models/request_builder_parameter_list.py +1 -0
- package/autorest/codegen/models/schema_response.py +1 -1
- package/autorest/codegen/serializers/builder_serializer.py +33 -26
- package/autorest/codegen/serializers/client_serializer.py +14 -3
- package/autorest/codegen/serializers/general_serializer.py +7 -7
- package/autorest/codegen/serializers/import_serializer.py +44 -46
- package/autorest/codegen/serializers/metadata_serializer.py +12 -10
- package/autorest/codegen/serializers/model_base_serializer.py +6 -6
- package/autorest/codegen/serializers/utils.py +5 -1
- package/autorest/codegen/templates/config.py.jinja2 +2 -7
- package/autorest/codegen/templates/lro_operation.py.jinja2 +3 -1
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +2 -0
- package/autorest/codegen/templates/metadata.json.jinja2 +3 -3
- package/autorest/codegen/templates/operation.py.jinja2 +8 -2
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -1
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -0
- package/autorest/codegen/templates/operation_tools.jinja2 +3 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +3 -1
- package/autorest/codegen/templates/request_builder.py.jinja2 +2 -7
- package/autorest/codegen/templates/service_client.py.jinja2 +1 -1
- package/autorest/multiapi/models/imports.py +1 -1
- package/autorest/multiapi/serializers/import_serializer.py +1 -1
- package/package.json +2 -2
package/ChangeLog.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
### 2022-02-09 - 5.12.6
|
|
4
|
+
|
|
5
|
+
| Library | Min Version
|
|
6
|
+
| --------------- | -------
|
|
7
|
+
|`@autorest/core` | `3.6.2`
|
|
8
|
+
|`@autorest/modelerfour` | `4.19.1`
|
|
9
|
+
|`azure-core` dep of generated code | `1.20.1`
|
|
10
|
+
|`msrest` dep of generated code | `0.6.21`
|
|
11
|
+
|`azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0`
|
|
12
|
+
|
|
13
|
+
**Bug Fixes**
|
|
14
|
+
|
|
15
|
+
- Remove unused `metadata` value for paging and long running operations with `version-tolerant` generations #1131
|
|
16
|
+
- Remove name conflicts with parameters called `url`, `header_parameters`, and `query_parameters` #1143
|
|
17
|
+
- Make `--version-tolerant` generated code pylint compatible in the `azure-sdk-for-python` repo when generated with the `--black` flag #1147, #1144, #1130
|
|
18
|
+
|
|
19
|
+
### 2022-01-26 - 5.12.5
|
|
20
|
+
|
|
21
|
+
| Library | Min Version
|
|
22
|
+
| --------------- | -------
|
|
23
|
+
|`@autorest/core` | `3.6.2`
|
|
24
|
+
|`@autorest/modelerfour` | `4.19.1`
|
|
25
|
+
|`azure-core` dep of generated code | `1.20.1`
|
|
26
|
+
|`msrest` dep of generated code | `0.6.21`
|
|
27
|
+
|`azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0`
|
|
28
|
+
|
|
29
|
+
**Bug Fixes**
|
|
30
|
+
|
|
31
|
+
- Fix usage of `--black` flag outside of repo #1126
|
|
32
|
+
- Remove unused `metadata` value for `version-tolerant` generations #1127
|
|
33
|
+
|
|
34
|
+
### 2022-01-14 - 5.12.4
|
|
35
|
+
|
|
36
|
+
| Library | Min Version
|
|
37
|
+
| --------------- | -------
|
|
38
|
+
|`@autorest/core` | `3.6.2`
|
|
39
|
+
|`@autorest/modelerfour` | `4.19.1`
|
|
40
|
+
|`azure-core` dep of generated code | `1.20.1`
|
|
41
|
+
|`msrest` dep of generated code | `0.6.21`
|
|
42
|
+
|`azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0`
|
|
43
|
+
|
|
44
|
+
**Bug Fixes**
|
|
45
|
+
|
|
46
|
+
- Remove duplicate generation of properties in classes that inherit from multiple classes #1120
|
|
47
|
+
|
|
48
|
+
### 2022-01-13 - 5.12.3
|
|
49
|
+
|
|
50
|
+
| Library | Min Version
|
|
51
|
+
| --------------- | -------
|
|
52
|
+
|`@autorest/core` | `3.6.2`
|
|
53
|
+
|`@autorest/modelerfour` | `4.19.1`
|
|
54
|
+
|`azure-core` dep of generated code | `1.20.1`
|
|
55
|
+
|`msrest` dep of generated code | `0.6.21`
|
|
56
|
+
|`azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.0`
|
|
57
|
+
|
|
58
|
+
**Bug Fixes**
|
|
59
|
+
|
|
60
|
+
- Unify multiapi constant behavior with single API version #1119
|
|
61
|
+
- Clean up docstrings by removing descriptions for client constants on methods and request builders #1119
|
|
62
|
+
|
|
3
63
|
### 2022-01-11 - 5.12.2
|
|
4
64
|
|
|
5
65
|
| Library | Min Version
|
|
@@ -18,7 +18,10 @@ class BlackScriptPlugin(Plugin):
|
|
|
18
18
|
|
|
19
19
|
def __init__(self, autorestapi):
|
|
20
20
|
super(BlackScriptPlugin, self).__init__(autorestapi)
|
|
21
|
-
|
|
21
|
+
output_folder_uri = self._autorestapi.get_value("outputFolderUri")
|
|
22
|
+
if output_folder_uri.startswith("file:"):
|
|
23
|
+
output_folder_uri = output_folder_uri[5:]
|
|
24
|
+
self.output_folder = Path(output_folder_uri)
|
|
22
25
|
|
|
23
26
|
def process(self) -> bool:
|
|
24
27
|
# apply format_file on every file in the output folder
|
|
@@ -33,27 +33,28 @@ class Client:
|
|
|
33
33
|
def _imports_shared(self, async_mode: bool) -> FileImport:
|
|
34
34
|
file_import = FileImport()
|
|
35
35
|
|
|
36
|
-
file_import.
|
|
37
|
-
file_import.
|
|
38
|
-
file_import.
|
|
36
|
+
file_import.add_submodule_import("msrest", "Serializer", ImportType.THIRDPARTY)
|
|
37
|
+
file_import.add_submodule_import("msrest", "Deserializer", ImportType.THIRDPARTY)
|
|
38
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
39
39
|
|
|
40
40
|
any_optional_gp = any(not gp.required for gp in self.parameters)
|
|
41
41
|
|
|
42
|
-
if
|
|
43
|
-
|
|
42
|
+
legacy = not any(g for g in ["low_level_client", "version_tolerant"] if g in self.code_model.options)
|
|
43
|
+
if any_optional_gp or (legacy and self.code_model.service_client.parameters.host):
|
|
44
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
44
45
|
|
|
45
46
|
if self.code_model.options["azure_arm"]:
|
|
46
|
-
file_import.
|
|
47
|
+
file_import.add_submodule_import(
|
|
47
48
|
"azure.mgmt.core", self.pipeline_class(async_mode), ImportType.AZURECORE
|
|
48
49
|
)
|
|
49
50
|
else:
|
|
50
|
-
file_import.
|
|
51
|
+
file_import.add_submodule_import(
|
|
51
52
|
"azure.core", self.pipeline_class(async_mode), ImportType.AZURECORE
|
|
52
53
|
)
|
|
53
54
|
|
|
54
55
|
for gp in self.code_model.global_parameters:
|
|
55
56
|
file_import.merge(gp.imports())
|
|
56
|
-
file_import.
|
|
57
|
+
file_import.add_submodule_import(
|
|
57
58
|
"._configuration", f"{self.code_model.class_name}Configuration",
|
|
58
59
|
ImportType.LOCAL
|
|
59
60
|
)
|
|
@@ -63,39 +64,41 @@ class Client:
|
|
|
63
64
|
def imports(self, async_mode: bool) -> FileImport:
|
|
64
65
|
file_import = self._imports_shared(async_mode)
|
|
65
66
|
if async_mode:
|
|
66
|
-
file_import.
|
|
67
|
-
file_import.
|
|
67
|
+
file_import.add_submodule_import("typing", "Awaitable", ImportType.STDLIB)
|
|
68
|
+
file_import.add_submodule_import(
|
|
68
69
|
"azure.core.rest", "AsyncHttpResponse", ImportType.AZURECORE, TypingSection.CONDITIONAL
|
|
69
70
|
)
|
|
70
71
|
else:
|
|
71
|
-
file_import.
|
|
72
|
+
file_import.add_submodule_import(
|
|
72
73
|
"azure.core.rest", "HttpResponse", ImportType.AZURECORE, TypingSection.CONDITIONAL
|
|
73
74
|
)
|
|
74
|
-
file_import.
|
|
75
|
+
file_import.add_submodule_import(
|
|
76
|
+
"azure.core.rest", "HttpRequest", ImportType.AZURECORE, TypingSection.CONDITIONAL
|
|
77
|
+
)
|
|
75
78
|
for og in self.code_model.operation_groups:
|
|
76
|
-
file_import.
|
|
79
|
+
file_import.add_submodule_import(
|
|
77
80
|
f".{self.code_model.operations_folder_name}", og.class_name, ImportType.LOCAL
|
|
78
81
|
)
|
|
79
82
|
|
|
80
83
|
if self.code_model.sorted_schemas:
|
|
81
84
|
path_to_models = ".." if async_mode else "."
|
|
82
|
-
file_import.
|
|
85
|
+
file_import.add_submodule_import(path_to_models, "models", ImportType.LOCAL)
|
|
83
86
|
else:
|
|
84
87
|
# in this case, we have client_models = {} in the service client, which needs a type annotation
|
|
85
88
|
# this import will always be commented, so will always add it to the typing section
|
|
86
|
-
file_import.
|
|
87
|
-
file_import.
|
|
89
|
+
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB, TypingSection.TYPING)
|
|
90
|
+
file_import.add_submodule_import("copy", "deepcopy", ImportType.STDLIB)
|
|
88
91
|
return file_import
|
|
89
92
|
|
|
90
93
|
def imports_for_multiapi(self, async_mode: bool) -> FileImport:
|
|
91
94
|
file_import = self._imports_shared(async_mode)
|
|
92
95
|
try:
|
|
93
96
|
mixin_operation = next(og for og in self.code_model.operation_groups if og.is_empty_operation_group)
|
|
94
|
-
file_import.
|
|
97
|
+
file_import.add_submodule_import("._operations_mixin", mixin_operation.class_name, ImportType.LOCAL)
|
|
95
98
|
except StopIteration:
|
|
96
99
|
pass
|
|
97
100
|
return file_import
|
|
98
101
|
|
|
99
|
-
def send_request_signature(self,
|
|
100
|
-
request_signature = ["request: HttpRequest," if
|
|
102
|
+
def send_request_signature(self, is_python3_file: bool) -> List[str]:
|
|
103
|
+
request_signature = ["request: HttpRequest," if is_python3_file else "request, # type: HttpRequest"]
|
|
101
104
|
return request_signature + self.parameters.method_signature_kwargs(is_python3_file)
|
|
@@ -44,7 +44,7 @@ class AzureKeyCredentialSchema(CredentialSchema):
|
|
|
44
44
|
|
|
45
45
|
def imports(self) -> FileImport:
|
|
46
46
|
file_import = FileImport()
|
|
47
|
-
file_import.
|
|
47
|
+
file_import.add_submodule_import(
|
|
48
48
|
"azure.core.credentials",
|
|
49
49
|
"AzureKeyCredential",
|
|
50
50
|
ImportType.AZURECORE,
|
|
@@ -76,13 +76,13 @@ class TokenCredentialSchema(CredentialSchema):
|
|
|
76
76
|
def imports(self) -> FileImport:
|
|
77
77
|
file_import = FileImport()
|
|
78
78
|
if self.async_mode:
|
|
79
|
-
file_import.
|
|
79
|
+
file_import.add_submodule_import(
|
|
80
80
|
"azure.core.credentials_async", "AsyncTokenCredential",
|
|
81
81
|
ImportType.AZURECORE,
|
|
82
82
|
typing_section=TypingSection.TYPING
|
|
83
83
|
)
|
|
84
84
|
else:
|
|
85
|
-
file_import.
|
|
85
|
+
file_import.add_submodule_import(
|
|
86
86
|
"azure.core.credentials", "TokenCredential",
|
|
87
87
|
ImportType.AZURECORE,
|
|
88
88
|
typing_section=TypingSection.TYPING
|
|
@@ -98,6 +98,6 @@ class DictionarySchema(BaseSchema):
|
|
|
98
98
|
|
|
99
99
|
def imports(self) -> FileImport:
|
|
100
100
|
file_import = FileImport()
|
|
101
|
-
file_import.
|
|
101
|
+
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
102
102
|
file_import.merge(self.element_type.imports())
|
|
103
103
|
return file_import
|
|
@@ -178,7 +178,7 @@ class EnumSchema(BaseSchema):
|
|
|
178
178
|
|
|
179
179
|
def imports(self) -> FileImport:
|
|
180
180
|
file_import = FileImport()
|
|
181
|
-
file_import.
|
|
181
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
182
182
|
file_import.merge(self.enum_type.imports())
|
|
183
183
|
return file_import
|
|
184
184
|
|
|
@@ -186,7 +186,7 @@ class EnumSchema(BaseSchema):
|
|
|
186
186
|
imports = self.imports()
|
|
187
187
|
# we import every enum since we can get extremely long imports
|
|
188
188
|
# if we import my name
|
|
189
|
-
imports.
|
|
189
|
+
imports.add_submodule_import("." + self.enum_file_name, "*", ImportType.LOCAL)
|
|
190
190
|
return imports
|
|
191
191
|
|
|
192
192
|
class HiddenModelEnumSchema(EnumSchema):
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
# license information.
|
|
5
5
|
# --------------------------------------------------------------------------
|
|
6
6
|
from enum import Enum
|
|
7
|
-
from typing import Dict,
|
|
8
|
-
|
|
7
|
+
from typing import Dict, List, Optional, Tuple, Union, Set
|
|
9
8
|
|
|
10
9
|
class ImportType(str, Enum):
|
|
11
10
|
STDLIB = "stdlib"
|
|
@@ -18,81 +17,122 @@ class TypingSection(str, Enum):
|
|
|
18
17
|
CONDITIONAL = "conditional" # is a typing import when we're dealing with files that py2 will use, else regular
|
|
19
18
|
TYPING = "typing" # never a typing import
|
|
20
19
|
|
|
20
|
+
class ImportModel:
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
typing_section: TypingSection,
|
|
24
|
+
import_type: ImportType,
|
|
25
|
+
module_name: str,
|
|
26
|
+
*,
|
|
27
|
+
submodule_name: Optional[str] = None,
|
|
28
|
+
alias: Optional[str] = None,
|
|
29
|
+
):
|
|
30
|
+
self.typing_section = typing_section
|
|
31
|
+
self.import_type = import_type
|
|
32
|
+
self.module_name = module_name
|
|
33
|
+
self.submodule_name = submodule_name
|
|
34
|
+
self.alias = alias
|
|
35
|
+
|
|
36
|
+
def __eq__(self, other):
|
|
37
|
+
try:
|
|
38
|
+
return (
|
|
39
|
+
self.typing_section == other.typing_section and
|
|
40
|
+
self.import_type == other.import_type and
|
|
41
|
+
self.module_name == other.module_name and
|
|
42
|
+
self.submodule_name == other.submodule_name and
|
|
43
|
+
self.alias == other.alias
|
|
44
|
+
)
|
|
45
|
+
except AttributeError:
|
|
46
|
+
return False
|
|
47
|
+
|
|
48
|
+
def __hash__(self):
|
|
49
|
+
retval: int = 0
|
|
50
|
+
for attr in dir(self):
|
|
51
|
+
if attr[0] != "_":
|
|
52
|
+
retval += hash(getattr(self, attr))
|
|
53
|
+
return retval
|
|
21
54
|
|
|
22
55
|
class FileImport:
|
|
23
56
|
def __init__(
|
|
24
57
|
self,
|
|
25
|
-
imports:
|
|
26
|
-
TypingSection,
|
|
27
|
-
Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
|
|
28
|
-
] = None
|
|
58
|
+
imports: List[ImportModel] = None
|
|
29
59
|
) -> None:
|
|
30
|
-
|
|
31
|
-
# First level dict: TypingSection
|
|
32
|
-
# Second level dict: ImportType
|
|
33
|
-
# Third level dict: the package name.
|
|
34
|
-
# Fourth level set: None if this import is a "import", the name to import if it's a "from"
|
|
35
|
-
self._imports: Dict[
|
|
36
|
-
TypingSection,
|
|
37
|
-
Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
|
|
38
|
-
] = imports or dict()
|
|
60
|
+
self.imports = imports or []
|
|
39
61
|
# has sync and async type definitions
|
|
40
62
|
self.type_definitions: Dict[str, Tuple[str, str]] = {}
|
|
41
63
|
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
).add(name_import)
|
|
64
|
+
def _append_import(self, import_model: ImportModel) -> None:
|
|
65
|
+
if not any(
|
|
66
|
+
i for i in self.imports
|
|
67
|
+
if all(
|
|
68
|
+
getattr(i, attr) == getattr(import_model, attr)
|
|
69
|
+
for attr in dir(i)
|
|
70
|
+
if attr[0] != "_"
|
|
71
|
+
)
|
|
72
|
+
):
|
|
73
|
+
self.imports.append(import_model)
|
|
74
|
+
|
|
75
|
+
def get_imports_from_section(self, typing_section: TypingSection) -> List[ImportModel]:
|
|
76
|
+
return [i for i in self.imports if i.typing_section == typing_section]
|
|
56
77
|
|
|
57
|
-
def
|
|
78
|
+
def add_submodule_import(
|
|
58
79
|
self,
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
module_name: str,
|
|
81
|
+
submodule_name: str,
|
|
61
82
|
import_type: ImportType,
|
|
62
83
|
typing_section: TypingSection = TypingSection.REGULAR,
|
|
63
84
|
alias: Optional[str] = None,
|
|
64
85
|
) -> None:
|
|
65
86
|
"""Add an import to this import block.
|
|
66
87
|
"""
|
|
67
|
-
self.
|
|
68
|
-
|
|
69
|
-
|
|
88
|
+
self._append_import(ImportModel(
|
|
89
|
+
typing_section=typing_section,
|
|
90
|
+
import_type=import_type,
|
|
91
|
+
module_name=module_name,
|
|
92
|
+
submodule_name=submodule_name,
|
|
93
|
+
alias=alias,
|
|
94
|
+
))
|
|
70
95
|
|
|
71
96
|
def add_import(
|
|
72
97
|
self,
|
|
73
|
-
|
|
98
|
+
module_name: str,
|
|
74
99
|
import_type: ImportType,
|
|
75
100
|
typing_section: TypingSection = TypingSection.REGULAR
|
|
76
101
|
) -> None:
|
|
77
102
|
# Implementation detail: a regular import is just a "from" with no from
|
|
78
|
-
self.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
|
|
84
|
-
]:
|
|
85
|
-
return self._imports
|
|
103
|
+
self._append_import(ImportModel(
|
|
104
|
+
typing_section=typing_section,
|
|
105
|
+
import_type=import_type,
|
|
106
|
+
module_name=module_name,
|
|
107
|
+
))
|
|
86
108
|
|
|
87
109
|
def define_mypy_type(self, type_name: str, type_value: str, async_type_value: Optional[str] = None):
|
|
88
|
-
self.
|
|
110
|
+
self.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
89
111
|
self.type_definitions[type_name] = (type_value, async_type_value or type_value)
|
|
90
112
|
|
|
91
113
|
def merge(self, file_import: "FileImport") -> None:
|
|
92
114
|
"""Merge the given file import format."""
|
|
93
|
-
for
|
|
94
|
-
|
|
95
|
-
for package_name, module_list in package_list.items():
|
|
96
|
-
for module_name in module_list:
|
|
97
|
-
self._add_import(package_name, import_type, module_name, typing_section)
|
|
115
|
+
for i in file_import.imports:
|
|
116
|
+
self._append_import(i)
|
|
98
117
|
self.type_definitions.update(file_import.type_definitions)
|
|
118
|
+
|
|
119
|
+
def to_dict(self) -> Dict[
|
|
120
|
+
TypingSection,
|
|
121
|
+
Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
|
|
122
|
+
]:
|
|
123
|
+
retval: Dict[
|
|
124
|
+
TypingSection,
|
|
125
|
+
Dict[ImportType, Dict[str, Set[Optional[Union[str, Tuple[str, str]]]]]]
|
|
126
|
+
] = dict()
|
|
127
|
+
for i in self.imports:
|
|
128
|
+
name_import: Optional[Union[str, Tuple[str, str]]] = None
|
|
129
|
+
if i.submodule_name:
|
|
130
|
+
name_import = (i.submodule_name, i.alias) if i.alias else i.submodule_name
|
|
131
|
+
retval.setdefault(
|
|
132
|
+
i.typing_section, dict()
|
|
133
|
+
).setdefault(
|
|
134
|
+
i.import_type, dict()
|
|
135
|
+
).setdefault(
|
|
136
|
+
i.module_name, set()
|
|
137
|
+
).add(name_import)
|
|
138
|
+
return retval
|
|
@@ -108,6 +108,6 @@ class ListSchema(BaseSchema):
|
|
|
108
108
|
|
|
109
109
|
def imports(self) -> FileImport:
|
|
110
110
|
file_import = FileImport()
|
|
111
|
-
file_import.
|
|
111
|
+
file_import.add_submodule_import("typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
112
112
|
file_import.merge(self.element_type.imports())
|
|
113
113
|
return file_import
|
|
@@ -140,28 +140,30 @@ class LROOperation(Operation):
|
|
|
140
140
|
file_import = super().imports_for_multiapi(async_mode)
|
|
141
141
|
poller_import_path = ".".join(self.get_poller_path(async_mode).split(".")[:-1])
|
|
142
142
|
poller = self.get_poller(async_mode)
|
|
143
|
-
file_import.
|
|
143
|
+
file_import.add_submodule_import(poller_import_path, poller, ImportType.AZURECORE, TypingSection.CONDITIONAL)
|
|
144
144
|
return file_import
|
|
145
145
|
|
|
146
146
|
def imports(self, async_mode: bool) -> FileImport:
|
|
147
147
|
file_import = super().imports(async_mode)
|
|
148
|
-
file_import.
|
|
148
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
149
149
|
|
|
150
150
|
poller_import_path = ".".join(self.get_poller_path(async_mode).split(".")[:-1])
|
|
151
151
|
poller = self.get_poller(async_mode)
|
|
152
|
-
file_import.
|
|
152
|
+
file_import.add_submodule_import(poller_import_path, poller, ImportType.AZURECORE)
|
|
153
153
|
|
|
154
154
|
default_polling_method_import_path = ".".join(
|
|
155
155
|
self.get_default_polling_method_path(async_mode, self.code_model.options['azure_arm']).split(".")[:-1]
|
|
156
156
|
)
|
|
157
157
|
default_polling_method = self.get_default_polling_method(async_mode, self.code_model.options['azure_arm'])
|
|
158
|
-
file_import.
|
|
158
|
+
file_import.add_submodule_import(
|
|
159
|
+
default_polling_method_import_path, default_polling_method, ImportType.AZURECORE
|
|
160
|
+
)
|
|
159
161
|
|
|
160
162
|
default_no_polling_method_import_path = ".".join(
|
|
161
163
|
self.get_default_no_polling_method_path(async_mode).split(".")[:-1]
|
|
162
164
|
)
|
|
163
165
|
default_no_polling_method = self.get_default_no_polling_method(async_mode)
|
|
164
|
-
file_import.
|
|
166
|
+
file_import.add_submodule_import(
|
|
165
167
|
default_no_polling_method_import_path, default_no_polling_method, ImportType.AZURECORE
|
|
166
168
|
)
|
|
167
169
|
|
|
@@ -169,10 +171,14 @@ class LROOperation(Operation):
|
|
|
169
171
|
self.get_base_polling_method_path(async_mode).split(".")[:-1]
|
|
170
172
|
)
|
|
171
173
|
base_polling_method = self.get_base_polling_method(async_mode)
|
|
172
|
-
file_import.
|
|
174
|
+
file_import.add_submodule_import(base_polling_method_import_path, base_polling_method, ImportType.AZURECORE)
|
|
173
175
|
|
|
174
176
|
if async_mode:
|
|
175
|
-
file_import.
|
|
176
|
-
if self.
|
|
177
|
-
file_import.
|
|
177
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
178
|
+
if self.code_model.options["tracing"] and self.want_tracing:
|
|
179
|
+
file_import.add_submodule_import(
|
|
180
|
+
f"azure.core.tracing.decorator{'_async' if async_mode else ''}",
|
|
181
|
+
f"distributed_trace{'_async' if async_mode else ''}",
|
|
182
|
+
ImportType.AZURECORE,
|
|
183
|
+
)
|
|
178
184
|
return file_import
|
|
@@ -213,7 +213,7 @@ class ObjectSchema(BaseSchema): # pylint: disable=too-many-instance-attributes
|
|
|
213
213
|
def imports(self) -> FileImport:
|
|
214
214
|
file_import = FileImport()
|
|
215
215
|
if self.is_exception:
|
|
216
|
-
file_import.
|
|
216
|
+
file_import.add_submodule_import("azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE)
|
|
217
217
|
return file_import
|
|
218
218
|
|
|
219
219
|
class HiddenModelObjectSchema(ObjectSchema):
|
|
@@ -240,7 +240,7 @@ class HiddenModelObjectSchema(ObjectSchema):
|
|
|
240
240
|
|
|
241
241
|
def imports(self) -> FileImport:
|
|
242
242
|
file_import = FileImport()
|
|
243
|
-
file_import.
|
|
243
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
244
244
|
return file_import
|
|
245
245
|
|
|
246
246
|
def get_object_schema(code_model) -> Type[ObjectSchema]:
|
|
@@ -147,7 +147,7 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
147
147
|
|
|
148
148
|
def _imports_shared(self, async_mode: bool) -> FileImport: # pylint: disable=unused-argument
|
|
149
149
|
file_import = FileImport()
|
|
150
|
-
file_import.
|
|
150
|
+
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
151
151
|
for param in self.parameters.method:
|
|
152
152
|
file_import.merge(param.imports())
|
|
153
153
|
|
|
@@ -159,11 +159,12 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
159
159
|
if response.has_body:
|
|
160
160
|
file_import.merge(cast(BaseSchema, response.schema).imports())
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
response_types = [r.operation_type_annotation for r in self.responses if r.has_body]
|
|
163
|
+
if len(set(response_types)) > 1:
|
|
164
|
+
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
164
165
|
|
|
165
166
|
if self.is_stream_response:
|
|
166
|
-
file_import.
|
|
167
|
+
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
167
168
|
return file_import
|
|
168
169
|
|
|
169
170
|
|
|
@@ -174,42 +175,37 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
174
175
|
file_import = self._imports_shared(async_mode)
|
|
175
176
|
|
|
176
177
|
# Exceptions
|
|
177
|
-
file_import.
|
|
178
|
+
file_import.add_submodule_import("azure.core.exceptions", "map_error", ImportType.AZURECORE)
|
|
178
179
|
if self.code_model.options["azure_arm"]:
|
|
179
|
-
file_import.
|
|
180
|
-
file_import.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
file_import.
|
|
184
|
-
file_import.
|
|
185
|
-
file_import.
|
|
186
|
-
file_import.
|
|
187
|
-
file_import.
|
|
188
|
-
file_import.add_from_import("typing", "Generic", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
189
|
-
file_import.add_from_import("azure.core.pipeline", "PipelineResponse", ImportType.AZURECORE)
|
|
190
|
-
file_import.add_from_import("azure.core.rest", "HttpRequest", ImportType.AZURECORE)
|
|
180
|
+
file_import.add_submodule_import("azure.mgmt.core.exceptions", "ARMErrorFormat", ImportType.AZURECORE)
|
|
181
|
+
file_import.add_submodule_import("azure.core.exceptions", "HttpResponseError", ImportType.AZURECORE)
|
|
182
|
+
|
|
183
|
+
file_import.add_submodule_import("typing", "Callable", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
184
|
+
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
185
|
+
file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
186
|
+
file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB, TypingSection.CONDITIONAL)
|
|
187
|
+
file_import.add_submodule_import("azure.core.pipeline", "PipelineResponse", ImportType.AZURECORE)
|
|
188
|
+
file_import.add_submodule_import("azure.core.rest", "HttpRequest", ImportType.AZURECORE)
|
|
191
189
|
if async_mode:
|
|
192
|
-
file_import.
|
|
190
|
+
file_import.add_submodule_import("azure.core.pipeline.transport", "AsyncHttpResponse", ImportType.AZURECORE)
|
|
193
191
|
else:
|
|
194
|
-
file_import.
|
|
192
|
+
file_import.add_submodule_import("azure.core.pipeline.transport", "HttpResponse", ImportType.AZURECORE)
|
|
195
193
|
|
|
196
|
-
|
|
197
|
-
# FIXME: Replace with "the YAML contains deprecated:true"
|
|
198
|
-
if True: # pylint: disable=using-constant-test
|
|
194
|
+
if self.deprecated:
|
|
199
195
|
file_import.add_import("warnings", ImportType.STDLIB)
|
|
200
196
|
|
|
201
197
|
if self.code_model.options["builders_visibility"] != "embedded":
|
|
202
198
|
builder_group_name = self.request_builder.builder_group_name
|
|
203
199
|
rest_import_path = "..." if async_mode else ".."
|
|
204
200
|
if builder_group_name:
|
|
205
|
-
file_import.
|
|
201
|
+
file_import.add_submodule_import(
|
|
206
202
|
f"{rest_import_path}{self.code_model.rest_layer_name}",
|
|
207
|
-
|
|
203
|
+
builder_group_name,
|
|
208
204
|
import_type=ImportType.LOCAL,
|
|
209
205
|
alias=f"rest_{builder_group_name}"
|
|
210
206
|
)
|
|
211
207
|
else:
|
|
212
|
-
file_import.
|
|
208
|
+
file_import.add_submodule_import(
|
|
213
209
|
rest_import_path,
|
|
214
210
|
self.code_model.rest_layer_name,
|
|
215
211
|
import_type=ImportType.LOCAL,
|
|
@@ -219,7 +215,7 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
219
215
|
file_import.merge(self.request_builder.imports())
|
|
220
216
|
if self.code_model.need_request_converter:
|
|
221
217
|
relative_path = "..." if async_mode else ".."
|
|
222
|
-
file_import.
|
|
218
|
+
file_import.add_submodule_import(
|
|
223
219
|
f"{relative_path}_vendor", "_convert_request", ImportType.LOCAL
|
|
224
220
|
)
|
|
225
221
|
if self.code_model.options["version_tolerant"] and (
|
|
@@ -227,6 +223,12 @@ class Operation(BaseBuilder): # pylint: disable=too-many-public-methods, too-ma
|
|
|
227
223
|
any(r for r in self.responses if r.has_body)
|
|
228
224
|
):
|
|
229
225
|
file_import.define_mypy_type("JSONType", "Any")
|
|
226
|
+
if self.code_model.options["tracing"] and self.want_tracing:
|
|
227
|
+
file_import.add_submodule_import(
|
|
228
|
+
f"azure.core.tracing.decorator{'_async' if async_mode else ''}",
|
|
229
|
+
f"distributed_trace{'_async' if async_mode else ''}",
|
|
230
|
+
ImportType.AZURECORE,
|
|
231
|
+
)
|
|
230
232
|
return file_import
|
|
231
233
|
|
|
232
234
|
def _get_body_param_from_body_kwarg(self, body_kwarg: Parameter) -> Parameter:
|
|
@@ -58,23 +58,14 @@ class OperationGroup(BaseModel):
|
|
|
58
58
|
|
|
59
59
|
def imports(self, async_mode: bool) -> FileImport:
|
|
60
60
|
file_import = FileImport()
|
|
61
|
-
file_import.
|
|
62
|
-
file_import.
|
|
63
|
-
file_import.
|
|
61
|
+
file_import.add_submodule_import("azure.core.exceptions", "ClientAuthenticationError", ImportType.AZURECORE)
|
|
62
|
+
file_import.add_submodule_import("azure.core.exceptions", "ResourceNotFoundError", ImportType.AZURECORE)
|
|
63
|
+
file_import.add_submodule_import("azure.core.exceptions", "ResourceExistsError", ImportType.AZURECORE)
|
|
64
64
|
for operation in self.operations:
|
|
65
65
|
file_import.merge(operation.imports(async_mode))
|
|
66
|
-
if self.code_model.options["tracing"]:
|
|
67
|
-
if async_mode:
|
|
68
|
-
file_import.add_from_import(
|
|
69
|
-
"azure.core.tracing.decorator_async", "distributed_trace_async", ImportType.AZURECORE,
|
|
70
|
-
)
|
|
71
|
-
else:
|
|
72
|
-
file_import.add_from_import(
|
|
73
|
-
"azure.core.tracing.decorator", "distributed_trace", ImportType.AZURECORE,
|
|
74
|
-
)
|
|
75
66
|
local_path = "..." if async_mode else ".."
|
|
76
67
|
if self.code_model.has_schemas and self.code_model.options["models_mode"]:
|
|
77
|
-
file_import.
|
|
68
|
+
file_import.add_submodule_import(local_path, "models", ImportType.LOCAL, alias="_models")
|
|
78
69
|
if self.code_model.options["builders_visibility"] == "embedded" and async_mode:
|
|
79
70
|
if not self.code_model.options["combine_operation_files"]:
|
|
80
71
|
operation_group_name = "" if self.is_empty_operation_group else self.name
|
|
@@ -88,7 +79,7 @@ class OperationGroup(BaseModel):
|
|
|
88
79
|
python3_only = self.code_model.options["python3_only"]
|
|
89
80
|
typed_sync_operation_file = self.code_model.options["add_python3_operation_files"]
|
|
90
81
|
suffix = "_py3" if typed_sync_operation_file and not python3_only else ""
|
|
91
|
-
file_import.
|
|
82
|
+
file_import.add_submodule_import(
|
|
92
83
|
f"...{self.code_model.operations_folder_name}.{self.filename}{suffix}",
|
|
93
84
|
request_builder.name,
|
|
94
85
|
import_type=ImportType.LOCAL
|