@autorest/python 6.1.7 → 6.1.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.
@@ -3,7 +3,7 @@
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 Any, Dict
6
+ from typing import Any, Dict, Tuple
7
7
  import re
8
8
  import argparse
9
9
 
@@ -37,7 +37,9 @@ def to_snake_case(name: str) -> str:
37
37
  return re.sub("[A-Z]+", replace_upper_characters, name)
38
38
 
39
39
 
40
- def parse_args(need_cadl_file: bool = True):
40
+ def parse_args(
41
+ need_cadl_file: bool = True,
42
+ ) -> Tuple[argparse.Namespace, Dict[str, Any]]:
41
43
  parser = argparse.ArgumentParser(
42
44
  description="Run mypy against target folder. Add a local custom plugin to the path prior to execution. "
43
45
  )
@@ -60,7 +62,24 @@ def parse_args(need_cadl_file: bool = True):
60
62
  required=False,
61
63
  action="store_true",
62
64
  )
63
- return parser.parse_args()
65
+ args, unknown_args = parser.parse_known_args()
66
+
67
+ def _get_value(value: Any) -> Any:
68
+ if value == "true":
69
+ return True
70
+ if value == "false":
71
+ return False
72
+ try:
73
+ return int(value)
74
+ except ValueError:
75
+ pass
76
+ return value
77
+
78
+ unknown_args_ret = {
79
+ ua.strip("--").split("=")[0]: _get_value(ua.strip("--").split("=")[1])
80
+ for ua in unknown_args
81
+ }
82
+ return args, unknown_args_ret
64
83
 
65
84
 
66
85
  def get_body_type_for_description(body_parameter: Dict[str, Any]) -> str:
@@ -54,5 +54,5 @@ class BlackScriptPluginAutorest(BlackScriptPlugin, PluginAutorest):
54
54
 
55
55
  if __name__ == "__main__":
56
56
  # CADL pipeline will call this
57
- args = parse_args(need_cadl_file=False)
58
- BlackScriptPlugin(output_folder=args.output_folder).process()
57
+ args, unknown_args = parse_args(need_cadl_file=False)
58
+ BlackScriptPlugin(output_folder=args.output_folder, **unknown_args).process()
@@ -124,5 +124,7 @@ class CadlFlags(YamlUpdatePlugin): # pylint: disable=abstract-method
124
124
 
125
125
  if __name__ == "__main__":
126
126
  # CADL pipeline will call this
127
- args = parse_args()
128
- CadlFlags(output_folder=args.output_folder, cadl_file=args.cadl_file).process()
127
+ args, unknown_args = parse_args()
128
+ CadlFlags(
129
+ output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args
130
+ ).process()
@@ -361,5 +361,7 @@ class CodeGeneratorAutorest(CodeGenerator, PluginAutorest):
361
361
 
362
362
  if __name__ == "__main__":
363
363
  # CADL pipeline will call this
364
- args = parse_args()
365
- CodeGenerator(output_folder=args.output_folder, cadl_file=args.cadl_file).process()
364
+ args, unknown_args = parse_args()
365
+ CodeGenerator(
366
+ output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args
367
+ ).process()
@@ -75,7 +75,8 @@ class ModelType(
75
75
  @property
76
76
  def serialization_type(self) -> str:
77
77
  if self.code_model.options["models_mode"] == "msrest":
78
- return f"{'' if self.is_public else (self.code_model.models_filename + '.')}{self.name}"
78
+ private_model_path = f"_models.{self.code_model.models_filename}."
79
+ return f"{'' if self.is_public else private_model_path}{self.name}"
79
80
  if self.code_model.options["models_mode"] == "dpg":
80
81
  return f"{'' if self.is_public else '_models.'}_models.{self.name}"
81
82
  return "object"
@@ -1258,9 +1258,12 @@ class _PagingOperationSerializer(
1258
1258
  response = builder.responses[0]
1259
1259
  deserialized = "pipeline_response.http_response.json()"
1260
1260
  if self.code_model.options["models_mode"] == "msrest":
1261
- deserialized = (
1262
- f'self._deserialize("{response.serialization_type}", pipeline_response)'
1263
- )
1261
+ deserialize_type = response.serialization_type
1262
+ pylint_disable = " # pylint: disable=protected-access"
1263
+ if isinstance(response.type, ModelType) and response.type.is_public:
1264
+ deserialize_type = f'"{response.serialization_type}"'
1265
+ pylint_disable = ""
1266
+ deserialized = f"self._deserialize(\n {deserialize_type}, pipeline_response{pylint_disable}\n)"
1264
1267
  elif self.code_model.options["models_mode"] == "dpg":
1265
1268
  deserialized = (
1266
1269
  f"_deserialize({response.serialization_type}, pipeline_response)"
@@ -1440,6 +1443,7 @@ class _LROOperationSerializer(_OperationSerializer[LROOperationType]):
1440
1443
  retval.append(" response_headers = {}")
1441
1444
  if (
1442
1445
  not self.code_model.options["models_mode"]
1446
+ or self.code_model.options["models_mode"] == "dpg"
1443
1447
  or builder.lro_response.headers
1444
1448
  ):
1445
1449
  retval.append(" response = pipeline_response.http_response")
@@ -68,5 +68,7 @@ class M2RAutorest(YamlUpdatePluginAutorest, M2R):
68
68
 
69
69
  if __name__ == "__main__":
70
70
  # CADL pipeline will call this
71
- args = parse_args()
72
- M2R(output_folder=args.output_folder, cadl_file=args.cadl_file).process()
71
+ args, unknown_args = parse_args()
72
+ M2R(
73
+ output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args
74
+ ).process()
@@ -29,10 +29,11 @@ class {{ code_model.client.name }}OperationsMixin(object):
29
29
  mixin_instance = OperationClass()
30
30
  mixin_instance._client = self._client
31
31
  mixin_instance._config = self._config
32
+ mixin_instance._config.api_version = api_version
32
33
  mixin_instance._serialize = Serializer(self._models_dict(api_version))
33
34
  {% if not code_model.client.client_side_validation %}
34
35
  mixin_instance._serialize.client_side_validation = False
35
36
  {% endif %}
36
37
  mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
37
38
  return {{ "await " if mixin_operation.coroutine(async_mode) }}mixin_instance.{{ mixin_operation.name }}({{ mixin_operation.call(async_mode) }})
38
- {% endfor %}
39
+ {% endfor %}
@@ -135,6 +135,7 @@ class {{ code_model.client.name }}({% if code_model.operation_mixin_group.mixin_
135
135
  {% endfor %}
136
136
  else:
137
137
  raise ValueError("API version {} does not have operation group '{{ operation_group.name }}'".format(api_version))
138
+ self._config.api_version = api_version
138
139
  return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))
139
140
  {% endfor %}
140
141
 
@@ -363,7 +363,7 @@ class PreProcessPluginAutorest(YamlUpdatePluginAutorest, PreProcessPlugin):
363
363
 
364
364
  if __name__ == "__main__":
365
365
  # CADL pipeline will call this
366
- args = parse_args()
366
+ args, unknown_args = parse_args()
367
367
  PreProcessPlugin(
368
- output_folder=args.output_folder, cadl_file=args.cadl_file
368
+ output_folder=args.output_folder, cadl_file=args.cadl_file, **unknown_args
369
369
  ).process()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.1.7",
3
+ "version": "6.1.9",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,7 @@
21
21
  "@autorest/system-requirements": "~1.0.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@microsoft.azure/autorest.testserver": "^3.3.38",
24
+ "@microsoft.azure/autorest.testserver": "^3.3.41",
25
25
  "typescript": "^4.8.3"
26
26
  },
27
27
  "files": [