@autorest/python 6.1.3 → 6.1.4

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # Release History
2
2
 
3
+ ### 2022-08-31 - 6.1.4
4
+
5
+ | Library | Min Version |
6
+ | ----------------------------------------------------------------------- | ----------- |
7
+ | `@autorest/core` | `3.8.4` |
8
+ | `@autorest/modelerfour` | `4.23.5` |
9
+ | `azure-core` dep of generated code | `1.24.0` |
10
+ | `isodate` dep of generated code | `0.6.1` |
11
+ | `msrest` dep of generated code (If generating legacy code) | `0.7.1` |
12
+ | `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.2` |
13
+
14
+ **Bug Fixes**
15
+
16
+ - Fix generation failure for `format: password` #1404
17
+ - Fix `content_type` error when paging with body #1407
18
+ - Fix excessive warning level logging in vendored `failsafe_deserialize` #1419
19
+
20
+ **Other Changes**
21
+
22
+ - Upgrade min dependency for `azure-mgmt-core` to `1.3.2` #1404
23
+
3
24
  ### 2022-08-22 - 6.1.3
4
25
 
5
26
  | Library | Min Version |
@@ -53,7 +53,13 @@ def parse_args(need_cadl_file: bool = True):
53
53
  help="Serialized cadl file",
54
54
  required=need_cadl_file,
55
55
  )
56
-
56
+ parser.add_argument(
57
+ "--debug",
58
+ dest="debug",
59
+ help="Debug mode",
60
+ required=False,
61
+ action="store_true",
62
+ )
57
63
  return parser.parse_args()
58
64
 
59
65
 
@@ -122,7 +122,7 @@ class CodeGenerator(Plugin):
122
122
  @staticmethod
123
123
  def _build_package_dependency() -> Dict[str, str]:
124
124
  return {
125
- "dependency_azure_mgmt_core": "azure-mgmt-core<2.0.0,>=1.3.0",
125
+ "dependency_azure_mgmt_core": "azure-mgmt-core<2.0.0,>=1.3.2",
126
126
  "dependency_azure_core": "azure-core<2.0.0,>=1.24.0",
127
127
  "dependency_msrest": "msrest>=0.7.1",
128
128
  }
@@ -140,6 +140,7 @@ TYPE_TO_OBJECT = {
140
140
  "AzureKeyCredentialPolicy": AzureKeyCredentialPolicyType,
141
141
  "any-object": AnyObjectType,
142
142
  "unixtime": UnixTimeType,
143
+ "credential": StringType,
143
144
  }
144
145
  _LOGGER = logging.getLogger(__name__)
145
146
 
@@ -72,16 +72,20 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes
72
72
  @property
73
73
  def serialization_type(self) -> str:
74
74
  if self.code_model.options["models_mode"]:
75
- return self.name
75
+ return (
76
+ self.name
77
+ if self.is_public
78
+ else f"{self.code_model.models_filename}.{self.name}"
79
+ )
76
80
  return "object"
77
81
 
78
82
  def type_annotation(self, **kwargs: Any) -> str:
79
83
  if self.code_model.options["models_mode"]:
80
84
  is_operation_file = kwargs.pop("is_operation_file", False)
81
- if self.is_public:
82
- retval = f"_models.{self.name}"
83
- return retval if is_operation_file else f'"{retval}"'
84
- return self.name if is_operation_file else f'"{self.name}"'
85
+ retval = f"_models.{self.name}"
86
+ if not self.is_public:
87
+ retval = f"{self.code_model.models_filename}.{retval}"
88
+ return retval if is_operation_file else f'"{retval}"'
85
89
  return "ET.Element" if self.is_xml else "JSON"
86
90
 
87
91
  def docstring_type(self, **kwargs: Any) -> str:
@@ -250,16 +254,9 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes
250
254
  relative_path = kwargs.pop("relative_path", None)
251
255
  if self.code_model.options["models_mode"] and relative_path:
252
256
  # add import for models in operations file
253
- if self.is_public:
254
- file_import.add_submodule_import(
255
- relative_path, "models", ImportType.LOCAL, alias="_models"
256
- )
257
- else:
258
- file_import.add_submodule_import(
259
- f"{relative_path}models.{self.code_model.models_filename}",
260
- self.name,
261
- ImportType.LOCAL,
262
- )
257
+ file_import.add_submodule_import(
258
+ relative_path, "models", ImportType.LOCAL, alias="_models"
259
+ )
263
260
  if self.code_model.options["models_mode"]:
264
261
  return file_import
265
262
  file_import.add_submodule_import(
@@ -708,8 +708,13 @@ class _OperationSerializer(
708
708
  retval.extend(self._serialize_body_parameter(builder))
709
709
  return retval
710
710
 
711
- def _initialize_overloads(self, builder: OperationType) -> List[str]:
711
+ def _initialize_overloads(
712
+ self, builder: OperationType, is_paging: bool = False
713
+ ) -> List[str]:
712
714
  retval: List[str] = []
715
+ # For paging, we put body parameter in local place outside `prepare_request`
716
+ if is_paging:
717
+ return retval
713
718
  same_content_type = (
714
719
  len(
715
720
  set(
@@ -883,6 +888,7 @@ class _OperationSerializer(
883
888
  request_builder: RequestBuilderType,
884
889
  template_url: Optional[str] = None,
885
890
  is_next_request: bool = False,
891
+ is_paging: bool = False,
886
892
  ) -> List[str]:
887
893
  retval = []
888
894
  if builder.parameters.grouped:
@@ -893,7 +899,7 @@ class _OperationSerializer(
893
899
  retval.extend(_serialize_flattened_body(builder.parameters.body_parameter))
894
900
  if builder.overloads:
895
901
  # we are only dealing with two overloads. If there are three, we generate an abstract operation
896
- retval.extend(self._initialize_overloads(builder))
902
+ retval.extend(self._initialize_overloads(builder, is_paging=is_paging))
897
903
  elif builder.parameters.has_body:
898
904
  # non-overloaded body
899
905
  retval.extend(self._create_body_parameter(builder))
@@ -906,8 +912,12 @@ class _OperationSerializer(
906
912
  retval.extend(self._postprocess_http_request(builder, template_url))
907
913
  return retval
908
914
 
909
- def call_request_builder(self, builder: OperationType) -> List[str]:
910
- return self._call_request_builder_helper(builder, builder.request_builder)
915
+ def call_request_builder(
916
+ self, builder: OperationType, is_paging: bool = False
917
+ ) -> List[str]:
918
+ return self._call_request_builder_helper(
919
+ builder, builder.request_builder, is_paging=is_paging
920
+ )
911
921
 
912
922
  def response_headers_and_deserialization(
913
923
  self,
@@ -1116,6 +1126,8 @@ class _PagingOperationSerializer(
1116
1126
  def decorators(self, builder: PagingOperationType) -> List[str]:
1117
1127
  """Decorators for the method"""
1118
1128
  retval: List[str] = []
1129
+ if builder.is_overload:
1130
+ return ["@overload"]
1119
1131
  if self.code_model.options["tracing"] and builder.want_tracing:
1120
1132
  retval.append("@distributed_trace")
1121
1133
  return retval
@@ -1168,10 +1180,14 @@ class _PagingOperationSerializer(
1168
1180
  return retval
1169
1181
 
1170
1182
  def _prepare_request_callback(self, builder: PagingOperationType) -> List[str]:
1171
- retval = ["def prepare_request(next_link=None):"]
1183
+ retval = self._initialize_overloads(builder)
1184
+ retval.append("def prepare_request(next_link=None):")
1172
1185
  retval.append(" if not next_link:")
1173
1186
  retval.extend(
1174
- [f" {line}" for line in self.call_request_builder(builder)]
1187
+ [
1188
+ f" {line}"
1189
+ for line in self.call_request_builder(builder, is_paging=True)
1190
+ ]
1175
1191
  )
1176
1192
  retval.append("")
1177
1193
  retval.append(" else:")
@@ -1,5 +1,8 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools with context %}
2
2
  {# actual template starts here #}
3
+ {% if operation.overloads and operation.public %}
4
+ {{ op_tools.generate_overloads(operation_serializer, operation) }}
5
+ {% endif %}
3
6
  {{ operation_serializer.method_signature_and_response_type_annotation(operation) }}
4
7
  {% if operation.public %}
5
8
  {{ op_tools.description(operation, operation_serializer) | indent }}{% endif %}
@@ -18,4 +21,4 @@
18
21
  {% endif %}
19
22
  {% if not code_model.options["version_tolerant"] %}
20
23
  {{ operation_serializer.get_metadata_url(operation) -}}
21
- {% endif %}
24
+ {% endif %}
@@ -1524,7 +1524,7 @@ class Deserializer(object):
1524
1524
  try:
1525
1525
  return self(target_obj, data, content_type=content_type)
1526
1526
  except:
1527
- _LOGGER.warning(
1527
+ _LOGGER.debug(
1528
1528
  "Ran into a deserialization error. Ignoring since this is failsafe deserialization",
1529
1529
  exc_info=True
1530
1530
  )
@@ -2003,4 +2003,4 @@ class Deserializer(object):
2003
2003
  msg = "Cannot deserialize to unix datetime object."
2004
2004
  raise_with_traceback(DeserializationError, msg, err)
2005
2005
  else:
2006
- return date_obj
2006
+ return date_obj
package/package.json CHANGED
@@ -1,44 +1,45 @@
1
1
  {
2
- "name": "@autorest/python",
3
- "version": "6.1.3",
4
- "description": "The Python extension for generators in AutoRest.",
5
- "scripts": {
6
- "prepare": "node run-python3.js prepare.py",
7
- "start": "node run-python3.js start.py",
8
- "install": "node run-python3.js install.py",
9
- "debug": "node run-python3.js start.py --debug"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/Azure/autorest.python/tree/autorestv3"
14
- },
15
- "readme": "https://github.com/Azure/autorest.python/blob/autorestv3/README.md",
16
- "keywords": [
17
- "autorest",
18
- "python"
19
- ],
20
- "author": "Microsoft Corporation",
21
- "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/Azure/autorest.python/issues"
24
- },
25
- "homepage": "https://github.com/Azure/autorest.python/blob/autorestv3/README.md",
26
- "dependencies": {
27
- "@autorest/system-requirements": "~1.0.0"
28
- },
29
- "devDependencies": {
30
- "@microsoft.azure/autorest.testserver": "^3.3.31"
31
- },
32
- "files": [
33
- "autorest/**/*.py",
34
- "autorest/**/*.jinja2",
35
- "setup.py",
36
- "install.py",
37
- "prepare.py",
38
- "start.py",
39
- "venvtools.py",
40
- "run-python3.js",
41
- "requirements.txt",
42
- "run_cadl.py"
43
- ]
2
+ "name": "@autorest/python",
3
+ "version": "6.1.4",
4
+ "description": "The Python extension for generators in AutoRest.",
5
+ "scripts": {
6
+ "prepare": "node run-python3.js prepare.py",
7
+ "start": "node run-python3.js start.py",
8
+ "install": "node run-python3.js install.py",
9
+ "debug": "node run-python3.js start.py --debug"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Azure/autorest.python/tree/autorestv3"
14
+ },
15
+ "readme": "https://github.com/Azure/autorest.python/blob/autorestv3/README.md",
16
+ "keywords": [
17
+ "autorest",
18
+ "python"
19
+ ],
20
+ "author": "Microsoft Corporation",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/Azure/autorest.python/issues"
24
+ },
25
+ "homepage": "https://github.com/Azure/autorest.python/blob/autorestv3/README.md",
26
+ "dependencies": {
27
+ "@autorest/system-requirements": "~1.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@microsoft.azure/autorest.testserver": "^3.3.38",
31
+ "typescript": "^4.7.4"
32
+ },
33
+ "files": [
34
+ "autorest/**/*.py",
35
+ "autorest/**/*.jinja2",
36
+ "setup.py",
37
+ "install.py",
38
+ "prepare.py",
39
+ "start.py",
40
+ "venvtools.py",
41
+ "run-python3.js",
42
+ "requirements.txt",
43
+ "run_cadl.py"
44
+ ]
44
45
  }
package/run_cadl.py CHANGED
@@ -5,11 +5,14 @@
5
5
  # --------------------------------------------------------------------------
6
6
  import sys
7
7
  import venv
8
+ import logging
8
9
  from pathlib import Path
9
10
  from venvtools import python_run
10
11
 
11
12
  _ROOT_DIR = Path(__file__).parent
12
13
 
14
+ _LOGGER = logging.getLogger(__name__)
15
+
13
16
  if __name__ == "__main__":
14
17
  venv_path = _ROOT_DIR / "venv"
15
18
  venv_prexists = venv_path.exists()
@@ -19,6 +22,19 @@ if __name__ == "__main__":
19
22
  env_builder = venv.EnvBuilder(with_pip=True)
20
23
  venv_context = env_builder.ensure_directories(venv_path)
21
24
 
25
+ if "--debug" in sys.argv:
26
+ try:
27
+ import debugpy # pylint: disable=import-outside-toplevel
28
+ except ImportError:
29
+ raise SystemExit(
30
+ "Please pip install ptvsd in order to use VSCode debugging"
31
+ )
32
+
33
+ # 5678 is the default attach port in the VS Code debug configurations
34
+ debugpy.listen(("localhost", 5678))
35
+ debugpy.wait_for_client()
36
+ breakpoint() # pylint: disable=undefined-variable
37
+
22
38
  # run m2r
23
39
  python_run(venv_context, "autorest.m2r.__init__", command=sys.argv[1:])
24
40
  python_run(venv_context, "autorest.preprocess.__init__", command=sys.argv[1:])