@autorest/python 6.7.8 → 6.8.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.
- package/autorest/codegen/__init__.py +12 -5
- package/autorest/codegen/_utils.py +4 -0
- package/autorest/codegen/models/parameter.py +13 -0
- package/autorest/codegen/models/parameter_list.py +5 -14
- package/autorest/codegen/models/request_builder_parameter.py +4 -0
- package/autorest/codegen/serializers/__init__.py +2 -1
- package/autorest/codegen/serializers/builder_serializer.py +4 -1
- package/autorest/preprocess/__init__.py +0 -15
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ from .. import Plugin, PluginAutorest
|
|
|
13
13
|
from .._utils import parse_args
|
|
14
14
|
from .models.code_model import CodeModel
|
|
15
15
|
from .serializers import JinjaSerializer, JinjaSerializerAutorest
|
|
16
|
-
from ._utils import DEFAULT_HEADER_TEXT
|
|
16
|
+
from ._utils import DEFAULT_HEADER_TEXT, VALID_PACKAGE_MODE, TYPESPEC_PACKAGE_MODE
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def _default_pprint(package_name: str) -> str:
|
|
@@ -55,11 +55,17 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None:
|
|
|
55
55
|
|
|
56
56
|
if options["package_mode"]:
|
|
57
57
|
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
(
|
|
59
|
+
options["package_mode"] not in TYPESPEC_PACKAGE_MODE
|
|
60
|
+
and options["from_typespec"]
|
|
61
|
+
)
|
|
62
|
+
or (
|
|
63
|
+
options["package_mode"] not in VALID_PACKAGE_MODE
|
|
64
|
+
and not options["from_typespec"]
|
|
65
|
+
)
|
|
66
|
+
) and not Path(options["package_mode"]).exists():
|
|
61
67
|
raise ValueError(
|
|
62
|
-
"--package-mode can only be '
|
|
68
|
+
f"--package-mode can only be {' or '.join(TYPESPEC_PACKAGE_MODE)} or directory which contains template files" # pylint: disable=line-too-long
|
|
63
69
|
)
|
|
64
70
|
|
|
65
71
|
if options["multiapi"] and options["version_tolerant"]:
|
|
@@ -170,6 +176,7 @@ class CodeGenerator(Plugin):
|
|
|
170
176
|
),
|
|
171
177
|
"generate_sample": self.options.get("generate-sample", False),
|
|
172
178
|
"default_api_version": self.options.get("default-api-version"),
|
|
179
|
+
"from_typespec": self.options.get("from-typespec", False),
|
|
173
180
|
}
|
|
174
181
|
|
|
175
182
|
if options["builders_visibility"] is None:
|
|
@@ -10,3 +10,7 @@ DEFAULT_HEADER_TEXT = (
|
|
|
10
10
|
"Code generated by Microsoft (R) Python Code Generator.\n"
|
|
11
11
|
"Changes may cause incorrect behavior and will be lost if the code is regenerated."
|
|
12
12
|
)
|
|
13
|
+
|
|
14
|
+
SWAGGER_PACKAGE_MODE = ["mgmtplane", "dataplane"] # for backward compatibility
|
|
15
|
+
TYPESPEC_PACKAGE_MODE = ["azure-mgmt", "azure-dataplane", "generic"]
|
|
16
|
+
VALID_PACKAGE_MODE = SWAGGER_PACKAGE_MODE + TYPESPEC_PACKAGE_MODE
|
|
@@ -92,6 +92,10 @@ class _ParameterBase(
|
|
|
92
92
|
)
|
|
93
93
|
self.hide_in_method: bool = self.yaml_data.get("hideInMethod", False)
|
|
94
94
|
|
|
95
|
+
@property
|
|
96
|
+
def hide_in_operation_signature(self) -> bool:
|
|
97
|
+
return False
|
|
98
|
+
|
|
95
99
|
@property
|
|
96
100
|
def constant(self) -> bool:
|
|
97
101
|
"""Returns whether a parameter is a constant or not.
|
|
@@ -341,6 +345,15 @@ class Parameter(_ParameterBase):
|
|
|
341
345
|
self.delimiter: Optional[ParameterDelimeter] = self.yaml_data.get("delimiter")
|
|
342
346
|
self._default_to_unset_sentinel: bool = False
|
|
343
347
|
|
|
348
|
+
@property
|
|
349
|
+
def hide_in_operation_signature(self) -> bool:
|
|
350
|
+
if (
|
|
351
|
+
self.code_model.options["version_tolerant"]
|
|
352
|
+
and self.client_name == "maxpagesize"
|
|
353
|
+
):
|
|
354
|
+
return True
|
|
355
|
+
return False
|
|
356
|
+
|
|
344
357
|
@property
|
|
345
358
|
def in_method_signature(self) -> bool:
|
|
346
359
|
return not (self.wire_name == "Accept" or self.grouped_by or self.flattened)
|
|
@@ -248,11 +248,12 @@ class _ParameterListBase(
|
|
|
248
248
|
|
|
249
249
|
def method_signature_keyword_only(self, async_mode: bool) -> List[str]:
|
|
250
250
|
"""Signature for keyword only parameters"""
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
251
|
+
result = [
|
|
252
|
+
parameter.method_signature(async_mode)
|
|
253
|
+
for parameter in self.keyword_only
|
|
254
|
+
if not parameter.hide_in_operation_signature
|
|
255
255
|
]
|
|
256
|
+
return ["*,"] + result if result else []
|
|
256
257
|
|
|
257
258
|
@property
|
|
258
259
|
def method_signature_kwargs(self) -> List[str]:
|
|
@@ -409,16 +410,6 @@ class RequestBuilderParameterList(_RequestBuilderParameterList):
|
|
|
409
410
|
class OverloadedRequestBuilderParameterList(_RequestBuilderParameterList):
|
|
410
411
|
"""Parameter list for OverloadedRequestBuilder"""
|
|
411
412
|
|
|
412
|
-
def method_signature_keyword_only(self, async_mode: bool) -> List[str]:
|
|
413
|
-
"""Signature for keyword only parameters"""
|
|
414
|
-
if not self.keyword_only:
|
|
415
|
-
return []
|
|
416
|
-
return ["*,"] + [
|
|
417
|
-
parameter.method_signature(async_mode)
|
|
418
|
-
for parameter in self.keyword_only
|
|
419
|
-
if parameter.location != ParameterLocation.BODY
|
|
420
|
-
]
|
|
421
|
-
|
|
422
413
|
|
|
423
414
|
class _ClientGlobalParameterList( # pylint: disable=abstract-method
|
|
424
415
|
_ParameterListBase[ParameterType, BodyParameter]
|
|
@@ -110,6 +110,10 @@ class RequestBuilderParameter(Parameter):
|
|
|
110
110
|
# we don't want hidden parameters for grouped by in request builders
|
|
111
111
|
self.client_name = self.client_name[1:]
|
|
112
112
|
|
|
113
|
+
@property
|
|
114
|
+
def hide_in_operation_signature(self) -> bool:
|
|
115
|
+
return False
|
|
116
|
+
|
|
113
117
|
@property
|
|
114
118
|
def in_method_signature(self) -> bool:
|
|
115
119
|
if self.grouped_by and not self.in_flattened_body:
|
|
@@ -29,6 +29,7 @@ from .patch_serializer import PatchSerializer
|
|
|
29
29
|
from .sample_serializer import SampleSerializer
|
|
30
30
|
from .types_serializer import TypesSerializer
|
|
31
31
|
from ..._utils import to_snake_case
|
|
32
|
+
from .._utils import VALID_PACKAGE_MODE
|
|
32
33
|
from .utils import (
|
|
33
34
|
extract_sample_name,
|
|
34
35
|
get_namespace_from_package_name,
|
|
@@ -216,7 +217,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
|
|
|
216
217
|
|
|
217
218
|
def _serialize_and_write_package_files(self, namespace_path: Path) -> None:
|
|
218
219
|
root_of_sdk = self._package_root_folder(namespace_path)
|
|
219
|
-
if self.code_model.options["package_mode"] in
|
|
220
|
+
if self.code_model.options["package_mode"] in VALID_PACKAGE_MODE:
|
|
220
221
|
env = Environment(
|
|
221
222
|
loader=PackageLoader(
|
|
222
223
|
"autorest.codegen", "templates/packaging_templates"
|
|
@@ -333,7 +333,7 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
333
333
|
def param_description(self, builder: BuilderType) -> List[str]:
|
|
334
334
|
description_list: List[str] = []
|
|
335
335
|
for param in builder.parameters.method:
|
|
336
|
-
if not param.in_docstring:
|
|
336
|
+
if not param.in_docstring or param.hide_in_operation_signature:
|
|
337
337
|
continue
|
|
338
338
|
description_list.extend(
|
|
339
339
|
f":{param.description_keyword} {param.client_name}: {param.description}".replace(
|
|
@@ -701,6 +701,9 @@ class _OperationSerializer(
|
|
|
701
701
|
check_client_input=not self.code_model.options["multiapi"],
|
|
702
702
|
operation_name=f"('{builder.name}')" if builder.group_name == "" else "",
|
|
703
703
|
)
|
|
704
|
+
for p in builder.parameters.parameters:
|
|
705
|
+
if p.hide_in_operation_signature:
|
|
706
|
+
kwargs.append(f'{p.client_name} = kwargs.pop("{p.client_name}", None)')
|
|
704
707
|
cls_annotation = builder.cls_type_annotation(async_mode=self.async_mode)
|
|
705
708
|
pylint_disable = ""
|
|
706
709
|
if any(x.startswith("_") for x in cls_annotation.split(".")):
|
|
@@ -137,16 +137,6 @@ def add_overloads_for_body_param(yaml_data: Dict[str, Any]) -> None:
|
|
|
137
137
|
content_type_param["optional"] = True
|
|
138
138
|
|
|
139
139
|
|
|
140
|
-
def _remove_paging_maxpagesize(yaml_data: Dict[str, Any]) -> None:
|
|
141
|
-
# we don't expose maxpagesize for version tolerant generation
|
|
142
|
-
# users should be passing this into `by_page`
|
|
143
|
-
yaml_data["parameters"] = [
|
|
144
|
-
p
|
|
145
|
-
for p in yaml_data.get("parameters", [])
|
|
146
|
-
if p["wireName"].lower() not in ["maxpagesize", "$maxpagesize"]
|
|
147
|
-
]
|
|
148
|
-
|
|
149
|
-
|
|
150
140
|
def update_description(
|
|
151
141
|
description: Optional[str], default_description: str = ""
|
|
152
142
|
) -> str:
|
|
@@ -494,13 +484,8 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
494
484
|
yaml_data["pagerSync"] = "azure.core.paging.ItemPaged"
|
|
495
485
|
if not yaml_data.get("pagerAsync"):
|
|
496
486
|
yaml_data["pagerAsync"] = "azure.core.async_paging.AsyncItemPaged"
|
|
497
|
-
if self.version_tolerant:
|
|
498
|
-
# if we're in version tolerant, hide the paging model
|
|
499
|
-
_remove_paging_maxpagesize(yaml_data)
|
|
500
487
|
item_type = item_type or yaml_data["itemType"]["elementType"]
|
|
501
488
|
if yaml_data.get("nextOperation"):
|
|
502
|
-
if self.version_tolerant:
|
|
503
|
-
_remove_paging_maxpagesize(yaml_data["nextOperation"])
|
|
504
489
|
yaml_data["nextOperation"]["groupName"] = self.pad_reserved_words(
|
|
505
490
|
yaml_data["nextOperation"]["groupName"], PadType.OPERATION_GROUP
|
|
506
491
|
)
|