@autorest/python 6.4.7 → 6.4.9

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.
@@ -16,6 +16,10 @@ from .serializers import JinjaSerializer, JinjaSerializerAutorest
16
16
  from ._utils import DEFAULT_HEADER_TEXT
17
17
 
18
18
 
19
+ def _default_pprint(package_name: str) -> str:
20
+ return " ".join([i.capitalize() for i in package_name.split("-")])
21
+
22
+
19
23
  def _validate_code_model_options(options: Dict[str, Any]) -> None:
20
24
  if options["builders_visibility"] not in ["public", "hidden", "embedded"]:
21
25
  raise ValueError(
@@ -126,6 +130,7 @@ class CodeGenerator(Plugin):
126
130
  if self.options.get("cadl_file") is not None:
127
131
  models_mode_default = "dpg"
128
132
 
133
+ package_name = self.options.get("package-name")
129
134
  options: Dict[str, Any] = {
130
135
  "azure_arm": azure_arm,
131
136
  "head_as_boolean": self.options.get("head-as-boolean", True),
@@ -134,7 +139,7 @@ class CodeGenerator(Plugin):
134
139
  "no_async": self.options.get("no-async", False),
135
140
  "no_namespace_folders": self.options.get("no-namespace-folders", False),
136
141
  "basic_setup_py": self.options.get("basic-setup-py", False),
137
- "package_name": self.options.get("package-name"),
142
+ "package_name": package_name,
138
143
  "package_version": self.options.get("package-version"),
139
144
  "client_side_validation": self.options.get("client-side-validation", False),
140
145
  "tracing": self.options.get("tracing", show_operations),
@@ -156,7 +161,8 @@ class CodeGenerator(Plugin):
156
161
  "combine-operation-files", version_tolerant
157
162
  ),
158
163
  "package_mode": self.options.get("package-mode"),
159
- "package_pprint_name": self.options.get("package-pprint-name"),
164
+ "package_pprint_name": self.options.get("package-pprint-name")
165
+ or _default_pprint(str(package_name)),
160
166
  "package_configuration": self.options.get("package-configuration"),
161
167
  "default_optional_constants_to_none": self.options.get(
162
168
  "default-optional-constants-to-none",
@@ -146,6 +146,8 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
146
146
  retval = add_to_pylint_disable("", "client-accepts-api-version-keyword")
147
147
  if len(self.operation_groups) > 6:
148
148
  retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
149
+ if len(self.name) > 40:
150
+ retval = add_to_pylint_disable(retval, "name-too-long")
149
151
  return retval
150
152
 
151
153
  @property
@@ -203,7 +205,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
203
205
  if gp.method_location == ParameterMethodLocation.KWARG:
204
206
  continue
205
207
  file_import.merge(
206
- gp.imports(async_mode, relative_path=".." if async_mode else ".")
208
+ gp.imports(
209
+ async_mode,
210
+ relative_path=".." if async_mode else ".",
211
+ operation=True,
212
+ )
207
213
  )
208
214
  file_import.add_submodule_import(
209
215
  "._configuration",
@@ -420,7 +426,9 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
420
426
  continue
421
427
  file_import.merge(
422
428
  gp.imports(
423
- async_mode=async_mode, relative_path=".." if async_mode else "."
429
+ async_mode=async_mode,
430
+ relative_path=".." if async_mode else ".",
431
+ operation=True,
424
432
  )
425
433
  )
426
434
  return file_import
@@ -436,7 +444,9 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
436
444
  continue
437
445
  file_import.merge(
438
446
  gp.imports_for_multiapi(
439
- async_mode=async_mode, relative_path=".." if async_mode else "."
447
+ async_mode=async_mode,
448
+ relative_path=".." if async_mode else ".",
449
+ operation=True,
440
450
  )
441
451
  )
442
452
  return file_import
@@ -173,13 +173,13 @@ class EnumType(BaseType):
173
173
  )
174
174
 
175
175
  def imports(self, **kwargs: Any) -> FileImport:
176
- is_operation_file = kwargs.pop("is_operation_file", False)
176
+ operation = kwargs.pop("operation", False)
177
177
  file_import = FileImport()
178
178
  if self.code_model.options["models_mode"]:
179
179
  file_import.add_submodule_import(
180
180
  "typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
181
181
  )
182
- if not is_operation_file:
182
+ if not operation:
183
183
  file_import.add_submodule_import(
184
184
  "..",
185
185
  "models",
@@ -187,9 +187,7 @@ class EnumType(BaseType):
187
187
  TypingSection.TYPING,
188
188
  alias="_models",
189
189
  )
190
- file_import.merge(
191
- self.value_type.imports(is_operation_file=is_operation_file, **kwargs)
192
- )
190
+ file_import.merge(self.value_type.imports(operation=operation, **kwargs))
193
191
  relative_path = kwargs.pop("relative_path", None)
194
192
  if self.code_model.options["models_mode"] and relative_path:
195
193
  # add import for enums in operations file
@@ -130,6 +130,8 @@ class OperationBase( # pylint: disable=too-many-public-methods
130
130
  if self.response_type_annotation(async_mode=False) == "None":
131
131
  # doesn't matter if it's async or not
132
132
  retval = add_to_pylint_disable(retval, "inconsistent-return-statements")
133
+ if len(self.name) > 40:
134
+ retval = add_to_pylint_disable(retval, "name-too-long")
133
135
  return retval
134
136
 
135
137
  def cls_type_annotation(self, *, async_mode: bool) -> str:
@@ -221,7 +223,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
221
223
  )
222
224
 
223
225
  response_types = [
224
- r.type_annotation(async_mode=async_mode) for r in self.responses if r.type
226
+ r.type_annotation(async_mode=async_mode, operation=self)
227
+ for r in self.responses
228
+ if r.type
225
229
  ]
226
230
  if len(set(response_types)) > 1:
227
231
  file_import.add_submodule_import(
@@ -243,17 +247,22 @@ class OperationBase( # pylint: disable=too-many-public-methods
243
247
  file_import.merge(
244
248
  param.imports_for_multiapi(
245
249
  async_mode,
250
+ operation=self,
246
251
  **kwargs,
247
252
  )
248
253
  )
249
254
  for response in self.responses:
250
255
  file_import.merge(
251
- response.imports_for_multiapi(async_mode=async_mode, **kwargs)
256
+ response.imports_for_multiapi(
257
+ async_mode=async_mode, operation=self, **kwargs
258
+ )
252
259
  )
253
260
  if self.code_model.options["models_mode"]:
254
261
  for exception in self.exceptions:
255
262
  file_import.merge(
256
- exception.imports_for_multiapi(async_mode=async_mode, **kwargs)
263
+ exception.imports_for_multiapi(
264
+ async_mode=async_mode, operation=self, **kwargs
265
+ )
257
266
  )
258
267
  return file_import
259
268
 
@@ -321,17 +330,22 @@ class OperationBase( # pylint: disable=too-many-public-methods
321
330
  file_import.merge(
322
331
  param.imports(
323
332
  async_mode,
333
+ operation=self,
324
334
  **kwargs,
325
335
  )
326
336
  )
327
337
  for response in self.responses:
328
- file_import.merge(response.imports(async_mode=async_mode, **kwargs))
338
+ file_import.merge(
339
+ response.imports(async_mode=async_mode, operation=self, **kwargs)
340
+ )
329
341
  if self.code_model.options["models_mode"]:
330
342
  for exception in self.exceptions:
331
343
  file_import.merge(exception.imports(async_mode=async_mode, **kwargs))
332
344
 
333
345
  if self.parameters.has_body and self.parameters.body_parameter.flattened:
334
- file_import.merge(self.parameters.body_parameter.type.imports(**kwargs))
346
+ file_import.merge(
347
+ self.parameters.body_parameter.type.imports(operation=self, **kwargs)
348
+ )
335
349
 
336
350
  # Exceptions
337
351
  errors = [
@@ -182,11 +182,7 @@ class _ParameterBase(
182
182
  file_import = self._imports_shared(async_mode, **kwargs)
183
183
  # special logic for api-version parameter
184
184
  if not self.is_api_version:
185
- file_import.merge(
186
- self.type.imports(
187
- is_operation_file=True, async_mode=async_mode, **kwargs
188
- )
189
- )
185
+ file_import.merge(self.type.imports(async_mode=async_mode, **kwargs))
190
186
  if self.default_to_unset_sentinel:
191
187
  file_import.add_submodule_import("typing", "Any", ImportType.STDLIB)
192
188
  file_import.define_mypy_type(
@@ -198,9 +194,7 @@ class _ParameterBase(
198
194
  def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
199
195
  file_import = self._imports_shared(async_mode, **kwargs)
200
196
  file_import.merge(
201
- self.type.imports_for_multiapi(
202
- is_operation_file=True, async_mode=async_mode, **kwargs
203
- )
197
+ self.type.imports_for_multiapi(async_mode=async_mode, **kwargs)
204
198
  )
205
199
  return file_import
206
200
 
@@ -105,13 +105,23 @@ class BinaryType(PrimitiveType):
105
105
  return self.get_declaration(b"bytes")
106
106
 
107
107
  def imports(self, **kwargs: Any) -> FileImport:
108
+ from .combined_type import CombinedType
109
+ from .operation import OperationBase
110
+
108
111
  file_import = FileImport()
109
112
  file_import.add_submodule_import("typing", "IO", ImportType.STDLIB)
113
+ operation = kwargs.get("operation")
114
+ if (
115
+ isinstance(operation, OperationBase)
116
+ and operation.parameters.has_body
117
+ and isinstance(operation.parameters.body_parameter.type, CombinedType)
118
+ ):
119
+ file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB)
110
120
  return file_import
111
121
 
112
122
  @property
113
123
  def instance_check_template(self) -> str:
114
- return "isinstance({}, (IO, bytes))"
124
+ return "isinstance({}, (IOBase, bytes))"
115
125
 
116
126
 
117
127
  class BinaryIteratorType(PrimitiveType):
@@ -130,9 +130,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
130
130
  return retval or None
131
131
 
132
132
  def imports(self, **kwargs) -> FileImport:
133
- file_import = self.type.imports(
134
- **kwargs, is_operation_file=False, relative_path="..", model_typing=True
135
- )
133
+ file_import = self.type.imports(**kwargs, relative_path="..", model_typing=True)
136
134
  if self.optional and self.client_default_value is None:
137
135
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
138
136
  if self.code_model.options["models_mode"] == "dpg":
@@ -16,6 +16,7 @@ from typing import (
16
16
  from abc import abstractmethod
17
17
 
18
18
  from .base_builder import BaseBuilder
19
+ from .utils import add_to_pylint_disable
19
20
  from .parameter_list import (
20
21
  RequestBuilderParameterList,
21
22
  OverloadedRequestBuilderParameterList,
@@ -56,6 +57,12 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
56
57
  self.method: str = yaml_data["method"]
57
58
  self.want_tracing = False
58
59
 
60
+ @property
61
+ def pylint_disable(self) -> str:
62
+ if len(self.name) > 40:
63
+ return add_to_pylint_disable("", "name-too-long")
64
+ return ""
65
+
59
66
  def response_type_annotation(self, **kwargs) -> str:
60
67
  return "HttpRequest"
61
68
 
@@ -81,7 +88,9 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
81
88
  return file_import
82
89
  for parameter in self.parameters.method:
83
90
  file_import.merge(
84
- parameter.imports(async_mode=False, relative_path=relative_path)
91
+ parameter.imports(
92
+ async_mode=False, relative_path=relative_path, operation=self
93
+ )
85
94
  )
86
95
 
87
96
  file_import.add_submodule_import(
@@ -103,7 +103,7 @@ class Response(BaseModel):
103
103
  def _imports_shared(self, **kwargs: Any) -> FileImport:
104
104
  file_import = FileImport()
105
105
  if self.type:
106
- file_import.merge(self.type.imports(is_operation_file=True, **kwargs))
106
+ file_import.merge(self.type.imports(**kwargs))
107
107
  if self.nullable:
108
108
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
109
109
  if isinstance(self.type, CombinedType) and self.type.name:
@@ -58,6 +58,14 @@ OperationType = TypeVar(
58
58
  )
59
59
 
60
60
 
61
+ def _xml_config(send_xml: bool, content_types: List[str]) -> str:
62
+ if not (send_xml and "xml" in str(content_types)):
63
+ return ""
64
+ if len(content_types) == 1:
65
+ return ", is_xml=True"
66
+ return ", is_xml='xml' in str(content_type)"
67
+
68
+
61
69
  def _escape_str(input_str: str) -> str:
62
70
  replace = input_str.replace("'", "\\'")
63
71
  return f'"{replace}"'
@@ -741,7 +749,9 @@ class _OperationSerializer(
741
749
  if xml_serialization_ctxt and self.code_model.options["models_mode"]:
742
750
  retval.append(f'{ser_ctxt_name} = {{"xml": {{{xml_serialization_ctxt}}}}}')
743
751
  if self.code_model.options["models_mode"] == "msrest":
744
- is_xml_cmd = ", is_xml=True" if send_xml else ""
752
+ is_xml_cmd = _xml_config(
753
+ send_xml, builder.parameters.body_parameter.content_types
754
+ )
745
755
  serialization_ctxt_cmd = (
746
756
  f", {ser_ctxt_name}={ser_ctxt_name}" if xml_serialization_ctxt else ""
747
757
  )
@@ -24,12 +24,12 @@ with open(os.path.join(package_folder_path, "_version.py"), "r") as fd:
24
24
 
25
25
  if not version:
26
26
  raise RuntimeError("Cannot find version information")
27
- {% set description = "Microsoft %s Client Library for Python"|format(package_pprint_name) %}
27
+ {% set description = "\"Microsoft {} Client Library for Python\".format(PACKAGE_PPRINT_NAME)" %}
28
28
  {% set author_email = "azpysdkhelp@microsoft.com" %}
29
29
  {% set url = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk" %}
30
30
  {% else %}
31
31
  version = "{{ package_version }}"
32
- {% set description = "%s"|format(package_name) %}
32
+ {% set description = "\"%s\""|format(package_name) %}
33
33
  {% set long_description = code_model.description %}
34
34
  {% set author_email = "" %}
35
35
  {% set url = "" %}
@@ -38,7 +38,7 @@ version = "{{ package_version }}"
38
38
  setup(
39
39
  name=PACKAGE_NAME,
40
40
  version=version,
41
- description="{{ description }}",
41
+ description={{ description }},
42
42
  {% if package_mode %}
43
43
  long_description=open("README.md", "r").read(),
44
44
  long_description_content_type="text/markdown",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.4.7",
3
+ "version": "6.4.9",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {