@autorest/python 5.16.0 → 5.17.0

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.
Files changed (92) hide show
  1. package/ChangeLog.md +43 -3
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +1 -1
  4. package/autorest/codegen/__init__.py +48 -209
  5. package/autorest/codegen/models/__init__.py +116 -83
  6. package/autorest/codegen/models/base_builder.py +49 -88
  7. package/autorest/codegen/models/base_model.py +1 -1
  8. package/autorest/codegen/models/{base_schema.py → base_type.py} +56 -40
  9. package/autorest/codegen/models/client.py +157 -48
  10. package/autorest/codegen/models/code_model.py +108 -254
  11. package/autorest/codegen/models/combined_type.py +107 -0
  12. package/autorest/codegen/models/{constant_schema.py → constant_type.py} +49 -40
  13. package/autorest/codegen/models/credential_types.py +224 -0
  14. package/autorest/codegen/models/{dictionary_schema.py → dictionary_type.py} +41 -31
  15. package/autorest/codegen/models/enum_type.py +195 -0
  16. package/autorest/codegen/models/imports.py +23 -0
  17. package/autorest/codegen/models/list_type.py +134 -0
  18. package/autorest/codegen/models/lro_operation.py +77 -156
  19. package/autorest/codegen/models/lro_paging_operation.py +28 -11
  20. package/autorest/codegen/models/model_type.py +239 -0
  21. package/autorest/codegen/models/operation.py +303 -269
  22. package/autorest/codegen/models/operation_group.py +48 -89
  23. package/autorest/codegen/models/paging_operation.py +80 -123
  24. package/autorest/codegen/models/parameter.py +289 -396
  25. package/autorest/codegen/models/parameter_list.py +348 -360
  26. package/autorest/codegen/models/primitive_types.py +544 -0
  27. package/autorest/codegen/models/property.py +109 -139
  28. package/autorest/codegen/models/request_builder.py +105 -88
  29. package/autorest/codegen/models/request_builder_parameter.py +112 -100
  30. package/autorest/codegen/models/response.py +325 -0
  31. package/autorest/codegen/models/utils.py +12 -19
  32. package/autorest/codegen/serializers/__init__.py +46 -37
  33. package/autorest/codegen/serializers/builder_serializer.py +604 -1146
  34. package/autorest/codegen/serializers/client_serializer.py +83 -88
  35. package/autorest/codegen/serializers/general_serializer.py +5 -64
  36. package/autorest/codegen/serializers/import_serializer.py +7 -4
  37. package/autorest/codegen/serializers/metadata_serializer.py +15 -104
  38. package/autorest/codegen/serializers/model_base_serializer.py +40 -32
  39. package/autorest/codegen/serializers/model_generic_serializer.py +8 -6
  40. package/autorest/codegen/serializers/model_init_serializer.py +2 -4
  41. package/autorest/codegen/serializers/model_python3_serializer.py +22 -16
  42. package/autorest/codegen/serializers/operation_groups_serializer.py +4 -13
  43. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  44. package/autorest/codegen/serializers/request_builders_serializer.py +12 -29
  45. package/autorest/codegen/serializers/utils.py +0 -142
  46. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  47. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  48. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  49. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  50. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
  51. package/autorest/codegen/templates/init.py.jinja2 +2 -2
  52. package/autorest/codegen/templates/lro_operation.py.jinja2 +4 -1
  53. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +4 -1
  54. package/autorest/codegen/templates/metadata.json.jinja2 +33 -33
  55. package/autorest/codegen/templates/model.py.jinja2 +23 -24
  56. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  57. package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
  58. package/autorest/codegen/templates/operation.py.jinja2 +6 -8
  59. package/autorest/codegen/templates/operation_group.py.jinja2 +7 -7
  60. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
  61. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  62. package/autorest/codegen/templates/paging_operation.py.jinja2 +2 -2
  63. package/autorest/codegen/templates/request_builder.py.jinja2 +13 -11
  64. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  65. package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
  66. package/autorest/jsonrpc/server.py +15 -3
  67. package/autorest/m4reformatter/__init__.py +1108 -0
  68. package/autorest/multiapi/models/code_model.py +1 -1
  69. package/autorest/multiapi/serializers/__init__.py +4 -4
  70. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  71. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  72. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +3 -3
  73. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  74. package/autorest/postprocess/__init__.py +202 -0
  75. package/autorest/postprocess/get_all.py +19 -0
  76. package/autorest/postprocess/venvtools.py +73 -0
  77. package/autorest/preprocess/__init__.py +209 -0
  78. package/autorest/preprocess/helpers.py +54 -0
  79. package/autorest/{namer → preprocess}/python_mappings.py +21 -16
  80. package/package.json +2 -2
  81. package/autorest/codegen/models/credential_model.py +0 -55
  82. package/autorest/codegen/models/credential_schema.py +0 -95
  83. package/autorest/codegen/models/credential_schema_policy.py +0 -73
  84. package/autorest/codegen/models/enum_schema.py +0 -225
  85. package/autorest/codegen/models/list_schema.py +0 -135
  86. package/autorest/codegen/models/object_schema.py +0 -303
  87. package/autorest/codegen/models/primitive_schemas.py +0 -495
  88. package/autorest/codegen/models/request_builder_parameter_list.py +0 -249
  89. package/autorest/codegen/models/schema_request.py +0 -55
  90. package/autorest/codegen/models/schema_response.py +0 -141
  91. package/autorest/namer/__init__.py +0 -23
  92. package/autorest/namer/name_converter.py +0 -509
@@ -3,26 +3,48 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import List, Optional, TYPE_CHECKING
7
- from .parameter_list import GlobalParameterList
6
+ from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union
7
+
8
+ from .base_model import BaseModel
9
+ from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList
8
10
  from .imports import FileImport, ImportType, TypingSection
11
+ from .utils import add_to_pylint_disable
12
+
13
+ ParameterListType = TypeVar(
14
+ "ParameterListType",
15
+ bound=Union[ClientGlobalParameterList, ConfigGlobalParameterList],
16
+ )
9
17
 
10
18
  if TYPE_CHECKING:
11
19
  from .code_model import CodeModel
12
20
 
13
21
 
14
- class Client:
15
- """A service client."""
22
+ class _ClientConfigBase(Generic[ParameterListType], BaseModel):
23
+ """The service client base. Shared across our Client and Config type"""
16
24
 
17
- def __init__(self, code_model: "CodeModel", parameters: GlobalParameterList):
18
- self.code_model = code_model
25
+ def __init__(
26
+ self,
27
+ yaml_data: Dict[str, Any],
28
+ code_model: "CodeModel",
29
+ parameters: ParameterListType,
30
+ ):
31
+ super().__init__(yaml_data, code_model)
19
32
  self.parameters = parameters
20
- self.parameterized_host_template: Optional[str] = None
21
- self._config_parameters = parameters
33
+ self.url: str = self.yaml_data[
34
+ "url"
35
+ ] # the base endpoint of the client. Can be parameterized or not
22
36
 
23
37
  @property
24
- def has_parameterized_host(self) -> bool:
25
- return bool(self.parameterized_host_template)
38
+ def description(self) -> str:
39
+ return self.yaml_data["description"]
40
+
41
+ @property
42
+ def name(self) -> str:
43
+ return self.yaml_data["name"]
44
+
45
+
46
+ class Client(_ClientConfigBase[ClientGlobalParameterList]):
47
+ """Model representing our service client"""
26
48
 
27
49
  def pipeline_class(self, async_mode: bool) -> str:
28
50
  if self.code_model.options["azure_arm"]:
@@ -33,6 +55,37 @@ class Client:
33
55
  return "AsyncPipelineClient"
34
56
  return "PipelineClient"
35
57
 
58
+ @property
59
+ def send_request_name(self) -> str:
60
+ """Name of the send request function"""
61
+ return (
62
+ "send_request"
63
+ if self.code_model.options["show_send_request"]
64
+ else "_send_request"
65
+ )
66
+
67
+ @property
68
+ def has_parameterized_host(self) -> bool:
69
+ """Whether the base url is parameterized or not"""
70
+ return not any(p for p in self.parameters if p.is_host)
71
+
72
+ @property
73
+ def pylint_disable(self) -> str:
74
+ retval = add_to_pylint_disable("", "client-accepts-api-version-keyword")
75
+ if len(self.code_model.operation_groups) > 6:
76
+ retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
77
+ return retval
78
+
79
+ @property
80
+ def filename(self) -> str:
81
+ """Name of the file for the client"""
82
+ if (
83
+ self.code_model.options["version_tolerant"]
84
+ or self.code_model.options["low_level_client"]
85
+ ):
86
+ return "_client"
87
+ return f"_{self.code_model.module_name}"
88
+
36
89
  def _imports_shared(self, async_mode: bool) -> FileImport:
37
90
  file_import = FileImport()
38
91
 
@@ -43,21 +96,6 @@ class Client:
43
96
  file_import.add_submodule_import(
44
97
  "typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
45
98
  )
46
-
47
- any_optional_gp = any(not gp.required for gp in self.parameters)
48
-
49
- legacy = not any(
50
- g
51
- for g in ["low_level_client", "version_tolerant"]
52
- if g in self.code_model.options
53
- )
54
- if any_optional_gp or (
55
- legacy and self.code_model.service_client.parameters.host
56
- ):
57
- file_import.add_submodule_import(
58
- "typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL
59
- )
60
-
61
99
  if self.code_model.options["azure_arm"]:
62
100
  file_import.add_submodule_import(
63
101
  "azure.mgmt.core", self.pipeline_class(async_mode), ImportType.AZURECORE
@@ -67,11 +105,11 @@ class Client:
67
105
  "azure.core", self.pipeline_class(async_mode), ImportType.AZURECORE
68
106
  )
69
107
 
70
- for gp in self.code_model.global_parameters:
71
- file_import.merge(gp.imports())
108
+ for gp in self.parameters:
109
+ file_import.merge(gp.imports(async_mode))
72
110
  file_import.add_submodule_import(
73
111
  "._configuration",
74
- f"{self.code_model.class_name}Configuration",
112
+ f"{self.code_model.client.name}Configuration",
75
113
  ImportType.LOCAL,
76
114
  )
77
115
 
@@ -107,9 +145,25 @@ class Client:
107
145
  ImportType.LOCAL,
108
146
  )
109
147
 
110
- if self.code_model.sorted_schemas:
148
+ if self.code_model.model_types and self.code_model.options["models_mode"]:
111
149
  path_to_models = ".." if async_mode else "."
112
- file_import.add_submodule_import(path_to_models, "models", ImportType.LOCAL)
150
+ if len(self.code_model.model_types) != len(
151
+ self.code_model.public_model_types
152
+ ):
153
+ # this means we have hidden models. In that case, we import directly from the models
154
+ # file, not the module, bc we don't expose the hidden models in the models module
155
+
156
+ # Also in this case, we're in version tolerant, so python3 only is true
157
+ file_import.add_submodule_import(
158
+ f"{path_to_models}models",
159
+ f"{self.code_model.get_models_filename(is_python3_file=True)}",
160
+ ImportType.LOCAL,
161
+ alias="models",
162
+ )
163
+ else:
164
+ file_import.add_submodule_import(
165
+ path_to_models, "models", ImportType.LOCAL
166
+ )
113
167
  else:
114
168
  # in this case, we have client_models = {} in the service client, which needs a type annotation
115
169
  # this import will always be commented, so will always add it to the typing section
@@ -121,34 +175,89 @@ class Client:
121
175
 
122
176
  def imports_for_multiapi(self, async_mode: bool) -> FileImport:
123
177
  file_import = self._imports_shared(async_mode)
178
+ file_import.add_submodule_import(
179
+ "typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL
180
+ )
124
181
  try:
125
182
  mixin_operation = next(
126
- og
127
- for og in self.code_model.operation_groups
128
- if og.is_empty_operation_group
183
+ og for og in self.code_model.operation_groups if og.is_mixin
129
184
  )
130
185
  file_import.add_submodule_import(
131
186
  "._operations_mixin", mixin_operation.class_name, ImportType.LOCAL
132
187
  )
133
188
  except StopIteration:
134
189
  pass
190
+ file_import.add_submodule_import(
191
+ "azure.profiles", "KnownProfiles", import_type=ImportType.AZURECORE
192
+ )
193
+ file_import.add_submodule_import(
194
+ "azure.profiles", "ProfileDefinition", import_type=ImportType.AZURECORE
195
+ )
196
+ file_import.add_submodule_import(
197
+ "azure.profiles.multiapiclient",
198
+ "MultiApiClientMixin",
199
+ import_type=ImportType.AZURECORE,
200
+ )
135
201
  return file_import
136
202
 
137
- def send_request_signature(self, is_python3_file: bool) -> List[str]:
138
- request_signature = [
139
- "request: HttpRequest,"
140
- if is_python3_file
141
- else "request, # type: HttpRequest"
142
- ]
143
- return request_signature + self.parameters.method_signature_kwargs(
144
- is_python3_file
203
+ @classmethod
204
+ def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Client":
205
+ return cls(
206
+ yaml_data=yaml_data,
207
+ code_model=code_model,
208
+ parameters=ClientGlobalParameterList.from_yaml(yaml_data, code_model),
145
209
  )
146
210
 
211
+
212
+ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
213
+ """Model representing our Config type."""
214
+
147
215
  @property
148
- def filename(self) -> str:
149
- if (
150
- self.code_model.options["version_tolerant"]
151
- or self.code_model.options["low_level_client"]
152
- ):
153
- return "_client"
154
- return f"_{self.code_model.module_name}"
216
+ def description(self) -> str:
217
+ return (
218
+ f"Configuration for {self.yaml_data['name']}.\n\n."
219
+ "Note that all parameters used to create this instance are saved as instance attributes."
220
+ )
221
+
222
+ @property
223
+ def name(self) -> str:
224
+ return f"{super().name}Configuration"
225
+
226
+ def imports(self, async_mode: bool) -> FileImport:
227
+ file_import = FileImport()
228
+ file_import.add_submodule_import(
229
+ "azure.core.configuration", "Configuration", ImportType.AZURECORE
230
+ )
231
+ file_import.add_submodule_import(
232
+ "azure.core.pipeline", "policies", ImportType.AZURECORE
233
+ )
234
+ file_import.add_submodule_import(
235
+ "typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL
236
+ )
237
+ if self.code_model.options["package_version"]:
238
+ file_import.add_submodule_import(
239
+ ".._version" if async_mode else "._version", "VERSION", ImportType.LOCAL
240
+ )
241
+ for gp in self.parameters:
242
+ file_import.merge(gp.imports(async_mode=async_mode))
243
+ if self.code_model.options["azure_arm"]:
244
+ policy = (
245
+ "AsyncARMChallengeAuthenticationPolicy"
246
+ if async_mode
247
+ else "ARMChallengeAuthenticationPolicy"
248
+ )
249
+ file_import.add_submodule_import(
250
+ "azure.mgmt.core.policies", "ARMHttpLoggingPolicy", ImportType.AZURECORE
251
+ )
252
+ file_import.add_submodule_import(
253
+ "azure.mgmt.core.policies", policy, ImportType.AZURECORE
254
+ )
255
+ return file_import
256
+
257
+ @classmethod
258
+ def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel") -> "Config":
259
+ return cls(
260
+ yaml_data=yaml_data,
261
+ code_model=code_model,
262
+ parameters=ConfigGlobalParameterList.from_yaml(yaml_data, code_model),
263
+ )