@autorest/python 6.28.1 → 6.28.3

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 (34) hide show
  1. package/autorest/codegen.py +2 -2
  2. package/autorest/jsonrpc/__init__.py +2 -2
  3. package/autorest/m4reformatter/__init__.py +13 -13
  4. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +1 -1
  5. package/generator/build/lib/pygen/codegen/models/code_model.py +1 -1
  6. package/generator/build/lib/pygen/codegen/models/operation.py +1 -1
  7. package/generator/build/lib/pygen/codegen/serializers/__init__.py +10 -5
  8. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +9 -2
  9. package/generator/build/lib/pygen/codegen/templates/macros.jinja2 +3 -2
  10. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +61 -0
  11. package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +2 -4
  12. package/generator/build/lib/pygen/codegen/templates/model_msrest.py.jinja2 +2 -6
  13. package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +37 -39
  14. package/generator/build/lib/pygen/preprocess/__init__.py +1 -1
  15. package/generator/component-detection-pip-report.json +6 -3
  16. package/generator/dev_requirements.txt +1 -11
  17. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  18. package/generator/pygen/codegen/models/code_model.py +1 -1
  19. package/generator/pygen/codegen/models/operation.py +1 -1
  20. package/generator/pygen/codegen/serializers/__init__.py +10 -5
  21. package/generator/pygen/codegen/serializers/builder_serializer.py +9 -2
  22. package/generator/pygen/codegen/templates/macros.jinja2 +3 -2
  23. package/generator/pygen/codegen/templates/model_base.py.jinja2 +61 -0
  24. package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +2 -4
  25. package/generator/pygen/codegen/templates/model_msrest.py.jinja2 +2 -6
  26. package/generator/pygen/codegen/templates/serialization.py.jinja2 +37 -39
  27. package/generator/pygen/preprocess/__init__.py +1 -1
  28. package/package.json +2 -2
  29. package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
  30. package/scripts/eng/mypy.ini +1 -1
  31. package/scripts/mypy.ini +1 -1
  32. package/scripts/prepare.py +2 -2
  33. package/scripts/start.py +2 -2
  34. package/scripts/venvtools.py +2 -2
@@ -40,7 +40,7 @@ class JinjaSerializerAutorest(JinjaSerializer, ReaderAndWriterAutorest):
40
40
  class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
41
41
  def get_options(self) -> Dict[str, Any]:
42
42
  if self._autorestapi.get_boolean_value("python3-only") is False:
43
- _LOGGER.warning("You have passed in --python3-only=False. We have force overriden this to True.")
43
+ _LOGGER.warning("You have passed in --python3-only=False. We have force overridden this to True.")
44
44
  if self._autorestapi.get_boolean_value("add-python3-operation-files"):
45
45
  _LOGGER.warning(
46
46
  "You have passed in --add-python3-operation-files. "
@@ -48,7 +48,7 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
48
48
  )
49
49
  if self._autorestapi.get_boolean_value("reformat-next-link"):
50
50
  _LOGGER.warning(
51
- "You have passed in --reformat-next-link. We have force overriden "
51
+ "You have passed in --reformat-next-link. We have force overridden "
52
52
  "this to False because we no longer reformat initial query parameters into next "
53
53
  "calls unless explicitly defined in the service definition."
54
54
  )
@@ -12,7 +12,7 @@ from pathlib import Path
12
12
 
13
13
 
14
14
  class Channel(Enum):
15
- # Information is considered the mildest of responses; not necesarily actionable.
15
+ # Information is considered the mildest of responses; not necessarily actionable.
16
16
  Information = "information"
17
17
 
18
18
  # Warnings are considered important for best practices, but not catastrophic in nature.
@@ -27,7 +27,7 @@ class Channel(Enum):
27
27
  # Verbose messages give the user additional clarity on the process.
28
28
  Verbose = "verbose"
29
29
 
30
- # Catastrophic failure, likely abending the process.
30
+ # Catastrophic failure, likely ending the process.
31
31
  Fatal = "fatal"
32
32
 
33
33
 
@@ -492,7 +492,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
492
492
  *,
493
493
  is_overload: bool = False,
494
494
  ) -> Dict[str, Any]:
495
- in_overriden = body_parameter["type"]["type"] == "combined" if body_parameter else False
495
+ in_overridden = body_parameter["type"]["type"] == "combined" if body_parameter else False
496
496
  abstract = False
497
497
  if body_parameter and (body_parameter.get("entries") or len(body_parameter["type"].get("types", [])) > 2):
498
498
  # this means it's formdata or urlencoded, or there are more than 2 types of body
@@ -507,7 +507,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
507
507
  yaml_data,
508
508
  body_parameter,
509
509
  in_overload=is_overload,
510
- in_overriden=in_overriden,
510
+ in_overridden=in_overridden,
511
511
  ),
512
512
  "bodyParameter": body_parameter,
513
513
  "responses": [update_response(r) for r in yaml_data.get("responses", [])],
@@ -723,7 +723,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
723
723
  request_media_types: List[str],
724
724
  *,
725
725
  in_overload: bool = False,
726
- in_overriden: bool = False,
726
+ in_overridden: bool = False,
727
727
  ) -> Dict[str, Any]:
728
728
  # override content type type to string
729
729
  if not body_parameter:
@@ -737,14 +737,14 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
737
737
  description = param["language"]["default"]["description"]
738
738
  if description and description[-1] != ".":
739
739
  description += "."
740
- if not (in_overriden or in_overload):
740
+ if not (in_overridden or in_overload):
741
741
  param["inDocstring"] = False
742
742
  elif in_overload:
743
743
  description += " Content type parameter for " f"{get_body_type_for_description(body_parameter)} body."
744
744
  if not in_overload or (body_parameter["type"]["type"] == "binary" and len(request_media_types) > 1):
745
745
  content_types = "'" + "', '".join(request_media_types) + "'"
746
746
  description += f" Known values are: {content_types}."
747
- if not in_overload and not in_overriden:
747
+ if not in_overload and not in_overridden:
748
748
  param["clientDefaultValue"] = body_parameter["defaultContentType"]
749
749
  param["language"]["default"]["description"] = description
750
750
  return param
@@ -758,7 +758,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
758
758
  request_media_types: List[str],
759
759
  *,
760
760
  in_overload: bool = False,
761
- in_overriden: bool = False,
761
+ in_overridden: bool = False,
762
762
  ) -> List[Dict[str, Any]]:
763
763
  retval: List[Dict[str, Any]] = []
764
764
  has_flattened_body = body_parameter and body_parameter.get("flattened")
@@ -785,9 +785,9 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
785
785
  body_parameter,
786
786
  request_media_types,
787
787
  in_overload=in_overload,
788
- in_overriden=in_overriden,
788
+ in_overridden=in_overridden,
789
789
  )
790
- updated_param = self.update_parameter(param, in_overload=in_overload, in_overriden=in_overriden)
790
+ updated_param = self.update_parameter(param, in_overload=in_overload, in_overridden=in_overridden)
791
791
  retval.append(updated_param)
792
792
  return retval
793
793
 
@@ -797,7 +797,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
797
797
  body_parameter: Optional[Dict[str, Any]],
798
798
  *,
799
799
  in_overload: bool = False,
800
- in_overriden: bool = False,
800
+ in_overridden: bool = False,
801
801
  ) -> List[Dict[str, Any]]:
802
802
  retval: List[Dict[str, Any]] = []
803
803
  seen_client_names: Set[str] = set()
@@ -812,7 +812,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
812
812
  groupers,
813
813
  request_media_types,
814
814
  in_overload=in_overload,
815
- in_overriden=in_overriden,
815
+ in_overridden=in_overridden,
816
816
  )
817
817
  )
818
818
  # now we handle content type and accept headers.
@@ -831,7 +831,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
831
831
  groupers,
832
832
  request_media_types,
833
833
  in_overload=in_overload,
834
- in_overriden=in_overriden,
834
+ in_overridden=in_overridden,
835
835
  )
836
836
  )
837
837
  all_params = (retval + [body_parameter]) if body_parameter else retval
@@ -853,7 +853,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
853
853
  *,
854
854
  override_client_name: Optional[str] = None,
855
855
  in_overload: bool = False,
856
- in_overriden: bool = False,
856
+ in_overridden: bool = False,
857
857
  ) -> Dict[str, Any]:
858
858
  param_base = self.update_parameter_base(yaml_data, override_client_name=override_client_name)
859
859
  type = get_type(yaml_data["schema"])
@@ -869,7 +869,7 @@ class M4Reformatter(YamlUpdatePluginAutorest): # pylint: disable=too-many-publi
869
869
  "inOverload": in_overload,
870
870
  "skipUrlEncoding": yaml_data.get("extensions", {}).get("x-ms-skip-url-encoding", False),
871
871
  "inDocstring": yaml_data.get("inDocstring", True),
872
- "inOverriden": in_overriden,
872
+ "inOverridden": in_overridden,
873
873
  "delimiter": update_parameter_delimiter(protocol_http.get("style")),
874
874
  }
875
875
  )
@@ -33,7 +33,7 @@ def __init__(
33
33
 
34
34
  class _SDKClient(object):
35
35
  def __init__(self, *args, **kwargs):
36
- """This is a fake class to support current implemetation of MultiApiClientMixin."
36
+ """This is a fake class to support current implementation of MultiApiClientMixin."
37
37
  Will be removed in final version of multiapi azure-core based client
38
38
  """
39
39
  pass
@@ -313,7 +313,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
313
313
  :param int schema_id: The yaml id of the schema
314
314
  :return: If created, we return the created schema, otherwise, we throw.
315
315
  :rtype: ~autorest.models.BaseType
316
- :raises: KeyError if schema is not found
316
+ :raises KeyError: if schema is not found
317
317
  """
318
318
  try:
319
319
  return next(type for id, type in self.types_map.items() if id == schema_id)
@@ -456,7 +456,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
456
456
  ImportType.LOCAL,
457
457
  )
458
458
  file_import.add_import("json", ImportType.STDLIB)
459
- if any(xml_serializable(str(r.default_content_type)) for r in self.responses):
459
+ if any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions):
460
460
  file_import.add_submodule_import(relative_path, "_deserialize_xml", ImportType.LOCAL)
461
461
  elif self.need_deserialize:
462
462
  file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
@@ -130,10 +130,10 @@ class JinjaSerializer(ReaderAndWriter):
130
130
  if self.code_model.options["package_mode"]:
131
131
  self._serialize_and_write_package_files(client_namespace)
132
132
 
133
- # write apiview_mapping_python.json
133
+ # write apiview-properties.json
134
134
  if self.code_model.options.get("emit_cross_language_definition_file"):
135
135
  self.write_file(
136
- exec_path / Path("apiview_mapping_python.json"),
136
+ exec_path / Path("apiview-properties.json"),
137
137
  general_serializer.serialize_cross_language_definition_file(),
138
138
  )
139
139
 
@@ -238,7 +238,7 @@ class JinjaSerializer(ReaderAndWriter):
238
238
  self, env: Environment, namespace: str, models: List[ModelType], enums: List[EnumType]
239
239
  ) -> None:
240
240
  # Write the models folder
241
- models_path = self.exec_path(namespace + ".models")
241
+ models_path = self.exec_path(namespace) / "models"
242
242
  serializer = DpgModelSerializer if self.code_model.options["models_mode"] == "dpg" else MsrestModelSerializer
243
243
  if self.code_model.has_non_json_models(models):
244
244
  self.write_file(
@@ -479,7 +479,12 @@ class JinjaSerializer(ReaderAndWriter):
479
479
  else Path(".")
480
480
  )
481
481
 
482
+ def exec_path_for_test_sample(self, namespace: str) -> Path:
483
+ return self.exec_path_compensation / Path(*namespace.split("."))
484
+
482
485
  def exec_path(self, namespace: str) -> Path:
486
+ if self.code_model.options["no_namespace_folders"] and not self.code_model.options["multiapi"]:
487
+ return Path(".")
483
488
  return self.exec_path_compensation / Path(*namespace.split("."))
484
489
 
485
490
  @property
@@ -492,7 +497,7 @@ class JinjaSerializer(ReaderAndWriter):
492
497
  return Path("")
493
498
 
494
499
  def _serialize_and_write_sample(self, env: Environment, namespace: str):
495
- out_path = self.exec_path(namespace) / Path("generated_samples")
500
+ out_path = self.exec_path_for_test_sample(namespace) / Path("generated_samples")
496
501
  for client in self.code_model.clients:
497
502
  for op_group in client.operation_groups:
498
503
  for operation in op_group.operations:
@@ -526,7 +531,7 @@ class JinjaSerializer(ReaderAndWriter):
526
531
 
527
532
  def _serialize_and_write_test(self, env: Environment, namespace: str):
528
533
  self.code_model.for_test = True
529
- out_path = self.exec_path(namespace) / Path("generated_tests")
534
+ out_path = self.exec_path_for_test_sample(namespace) / Path("generated_tests")
530
535
  general_serializer = TestGeneralSerializer(code_model=self.code_model, env=env)
531
536
  self.write_file(out_path / "conftest.py", general_serializer.serialize_conftest())
532
537
  if not self.code_model.options["azure_arm"]:
@@ -1005,7 +1005,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1005
1005
  retval.extend(deserialize_code)
1006
1006
  return retval
1007
1007
 
1008
- def handle_error_response(self, builder: OperationType) -> List[str]:
1008
+ def handle_error_response(self, builder: OperationType) -> List[str]: # pylint: disable=too-many-statements, too-many-branches
1009
1009
  async_await = "await " if self.async_mode else ""
1010
1010
  retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
1011
1011
  response_read = [
@@ -1079,7 +1079,14 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1079
1079
  is_operation_file=True, skip_quote=True, serialize_namespace=self.serialize_namespace
1080
1080
  )
1081
1081
  if self.code_model.options["models_mode"] == "dpg":
1082
- retval.append(f" error = _failsafe_deserialize({type_annotation}, response.json())")
1082
+ if xml_serializable(str(e.default_content_type)):
1083
+ retval.append(
1084
+ f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
1085
+ )
1086
+ else:
1087
+ retval.append(
1088
+ f" error = _failsafe_deserialize({type_annotation}, response.json())"
1089
+ )
1083
1090
  else:
1084
1091
  retval.append(
1085
1092
  f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
@@ -2,11 +2,12 @@
2
2
  {% set original_result = doc_string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrap_string) %}
3
3
  {% set list_result = original_result.split('\n') %}
4
4
  {% for line in list_result %}
5
+ {% set prefix = "" if loop.index == 1 else " " %}
5
6
  {% set suffix = suffix_string if list_result | length == loop.index %}
6
7
  {% if line | length > 120 %}
7
- {{ line + " # pylint: disable=line-too-long" }}{{ suffix }}
8
+ {{ prefix }}{{ line + " # pylint: disable=line-too-long" }}{{ suffix }}
8
9
  {% else %}
9
- {{ line }}{{ suffix }}
10
+ {{ prefix }}{{ line }}{{ suffix }}
10
11
  {% endif %}
11
12
  {% endfor %}
12
13
  {% endmacro %}
@@ -372,15 +372,34 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
372
372
  return not self.__eq__(other)
373
373
 
374
374
  def keys(self) -> typing.KeysView[str]:
375
+ """
376
+ :returns: a set-like object providing a view on D's keys
377
+ :rtype: ~typing.KeysView
378
+ """
375
379
  return self._data.keys()
376
380
 
377
381
  def values(self) -> typing.ValuesView[typing.Any]:
382
+ """
383
+ :returns: an object providing a view on D's values
384
+ :rtype: ~typing.ValuesView
385
+ """
378
386
  return self._data.values()
379
387
 
380
388
  def items(self) -> typing.ItemsView[str, typing.Any]:
389
+ """
390
+ :returns: set-like object providing a view on D's items
391
+ :rtype: ~typing.ItemsView
392
+ """
381
393
  return self._data.items()
382
394
 
383
395
  def get(self, key: str, default: typing.Any = None) -> typing.Any:
396
+ """
397
+ Get the value for key if key is in the dictionary, else default.
398
+ :param str key: The key to look up.
399
+ :param any default: The value to return if key is not in the dictionary. Defaults to None
400
+ :returns: D[k] if k in D, else d.
401
+ :rtype: any
402
+ """
384
403
  try:
385
404
  return self[key]
386
405
  except KeyError:
@@ -396,17 +415,38 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
396
415
  def pop(self, key: str, default: typing.Any) -> typing.Any: ...
397
416
 
398
417
  def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
418
+ """
419
+ Removes specified key and return the corresponding value.
420
+ :param str key: The key to pop.
421
+ :param any default: The value to return if key is not in the dictionary
422
+ :returns: The value corresponding to the key.
423
+ :rtype: any
424
+ :raises KeyError: If key is not found and default is not given.
425
+ """
399
426
  if default is _UNSET:
400
427
  return self._data.pop(key)
401
428
  return self._data.pop(key, default)
402
429
 
403
430
  def popitem(self) -> typing.Tuple[str, typing.Any]:
431
+ """
432
+ Removes and returns some (key, value) pair
433
+ :returns: The (key, value) pair.
434
+ :rtype: tuple
435
+ :raises KeyError: if D is empty.
436
+ """
404
437
  return self._data.popitem()
405
438
 
406
439
  def clear(self) -> None:
440
+ """
441
+ Remove all items from D.
442
+ """
407
443
  self._data.clear()
408
444
 
409
445
  def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
446
+ """
447
+ Updates D from mapping/iterable E and F.
448
+ :param any args: Either a mapping object or an iterable of key-value pairs.
449
+ """
410
450
  self._data.update(*args, **kwargs)
411
451
 
412
452
  @typing.overload
@@ -416,6 +456,13 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
416
456
  def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...
417
457
 
418
458
  def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
459
+ """
460
+ Same as calling D.get(k, d), and setting D[k]=d if k not found
461
+ :param str key: The key to look up.
462
+ :param any default: The value to set if key is not in the dictionary
463
+ :returns: D[k] if k in D, else d.
464
+ :rtype: any
465
+ """
419
466
  if default is _UNSET:
420
467
  return self._data.setdefault(key)
421
468
  return self._data.setdefault(key, default)
@@ -909,6 +956,20 @@ def _failsafe_deserialize(
909
956
  return None
910
957
 
911
958
 
959
+ def _failsafe_deserialize_xml(
960
+ deserializer: typing.Any,
961
+ value: typing.Any,
962
+ ) -> typing.Any:
963
+ try:
964
+ return _deserialize_xml(deserializer, value)
965
+ except DeserializationError:
966
+ _LOGGER.warning(
967
+ "Ran into a deserialization error. Ignoring since this is failsafe deserialization",
968
+ exc_info=True
969
+ )
970
+ return None
971
+
972
+
912
973
  class _RestField:
913
974
  def __init__(
914
975
  self,
@@ -22,9 +22,7 @@
22
22
  {% if model.properties != None %}
23
23
  {% for p in model.properties %}
24
24
  {% for line in serializer.variable_documentation_string(p) %}
25
- {% for doc_string in line.replace('\n', '\n ').split('\n') %}
26
- {{ macros.wrap_model_string(doc_string, '\n ') -}}
27
- {% endfor %}
25
+ {{ macros.wrap_model_string(line, '\n ') -}}
28
26
  {% endfor %}
29
27
  {% endfor %}
30
28
  {% endif %}
@@ -37,7 +35,7 @@
37
35
  {{ serializer.declare_property(p) }}
38
36
  {% set prop_description = p.description(is_operation_file=False).replace('"', '\\"') %}
39
37
  {% if prop_description %}
40
- """{{ macros.wrap_model_string(prop_description, '\n ', '\"\"\"') -}}
38
+ """{{ macros.wrap_model_string(prop_description, '\n ', '\"\"\"') -}}
41
39
  {% endif %}
42
40
  {% endfor %}
43
41
 
@@ -21,9 +21,7 @@
21
21
  {% if model.properties != None %}
22
22
  {% for p in model.properties %}
23
23
  {% for line in serializer.variable_documentation_string(p) %}
24
- {% for doc_string in line.replace('\n', '\n ').split('\n') %}
25
- {{ macros.wrap_model_string(doc_string, '\n ') -}}
26
- {% endfor %}
24
+ {{ macros.wrap_model_string(line, '\n ') -}}
27
25
  {% endfor %}
28
26
  {% endfor %}
29
27
  {% endif %}
@@ -75,9 +73,7 @@
75
73
  {% for p in model.properties %}
76
74
  {% if p.is_input %}
77
75
  {% for line in serializer.input_documentation_string(p) %}
78
- {% for doc_string in line.replace('\n', '\n ').split('\n') %}
79
- {{ macros.wrap_model_string(doc_string, '\n ') -}}
80
- {% endfor %}
76
+ {{ macros.wrap_model_string(line, '\n ') -}}
81
77
  {% endfor %}
82
78
  {% endif %}
83
79
  {% endfor %}