@autorest/python 5.15.0 → 5.18.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/ChangeLog.md +98 -4
- package/README.md +30 -4
- package/autorest/__init__.py +2 -3
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +122 -211
- package/autorest/codegen/models/__init__.py +122 -78
- package/autorest/codegen/models/base_builder.py +70 -72
- package/autorest/codegen/models/base_model.py +7 -5
- package/autorest/codegen/models/{base_schema.py → base_type.py} +68 -45
- package/autorest/codegen/models/client.py +193 -40
- package/autorest/codegen/models/code_model.py +145 -245
- package/autorest/codegen/models/combined_type.py +107 -0
- package/autorest/codegen/models/constant_type.py +122 -0
- package/autorest/codegen/models/credential_types.py +224 -0
- package/autorest/codegen/models/dictionary_type.py +131 -0
- package/autorest/codegen/models/enum_type.py +195 -0
- package/autorest/codegen/models/imports.py +93 -41
- package/autorest/codegen/models/list_type.py +149 -0
- package/autorest/codegen/models/lro_operation.py +90 -133
- package/autorest/codegen/models/lro_paging_operation.py +28 -12
- package/autorest/codegen/models/model_type.py +262 -0
- package/autorest/codegen/models/operation.py +412 -259
- package/autorest/codegen/models/operation_group.py +80 -91
- package/autorest/codegen/models/paging_operation.py +101 -117
- package/autorest/codegen/models/parameter.py +302 -341
- package/autorest/codegen/models/parameter_list.py +373 -357
- package/autorest/codegen/models/primitive_types.py +544 -0
- package/autorest/codegen/models/property.py +136 -134
- package/autorest/codegen/models/request_builder.py +138 -86
- package/autorest/codegen/models/request_builder_parameter.py +122 -86
- package/autorest/codegen/models/response.py +325 -0
- package/autorest/codegen/models/utils.py +13 -17
- package/autorest/codegen/serializers/__init__.py +212 -112
- package/autorest/codegen/serializers/builder_serializer.py +931 -1040
- package/autorest/codegen/serializers/client_serializer.py +140 -84
- package/autorest/codegen/serializers/general_serializer.py +26 -50
- package/autorest/codegen/serializers/import_serializer.py +96 -31
- package/autorest/codegen/serializers/metadata_serializer.py +39 -79
- package/autorest/codegen/serializers/model_base_serializer.py +62 -34
- package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
- package/autorest/codegen/serializers/model_init_serializer.py +4 -2
- package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
- package/autorest/codegen/serializers/operation_groups_serializer.py +21 -19
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/parameter_serializer.py +174 -0
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
- package/autorest/codegen/serializers/utils.py +0 -126
- package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
- package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
- package/autorest/codegen/templates/config.py.jinja2 +13 -13
- package/autorest/codegen/templates/enum.py.jinja2 +4 -4
- package/autorest/codegen/templates/enum_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/init.py.jinja2 +3 -3
- package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
- package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
- package/autorest/codegen/templates/model.py.jinja2 +23 -24
- package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
- package/autorest/codegen/templates/model_init.py.jinja2 +3 -5
- package/autorest/codegen/templates/operation.py.jinja2 +10 -14
- package/autorest/codegen/templates/operation_group.py.jinja2 +9 -15
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +19 -10
- package/autorest/codegen/templates/setup.py.jinja2 +9 -3
- package/autorest/codegen/templates/vendor.py.jinja2 +1 -1
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +28 -9
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- package/autorest/m4reformatter/__init__.py +1126 -0
- package/autorest/multiapi/__init__.py +24 -14
- package/autorest/multiapi/models/client.py +21 -11
- package/autorest/multiapi/models/code_model.py +23 -10
- package/autorest/multiapi/models/config.py +4 -1
- package/autorest/multiapi/models/constant_global_parameter.py +1 -0
- package/autorest/multiapi/models/global_parameter.py +2 -1
- package/autorest/multiapi/models/global_parameters.py +14 -8
- package/autorest/multiapi/models/imports.py +24 -17
- package/autorest/multiapi/models/mixin_operation.py +5 -5
- package/autorest/multiapi/models/operation_group.py +2 -1
- package/autorest/multiapi/models/operation_mixin_group.py +21 -10
- package/autorest/multiapi/serializers/__init__.py +20 -25
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
- package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/postprocess/__init__.py +202 -0
- package/autorest/postprocess/get_all.py +19 -0
- package/autorest/postprocess/venvtools.py +73 -0
- package/autorest/preprocess/__init__.py +210 -0
- package/autorest/preprocess/helpers.py +54 -0
- package/autorest/{namer → preprocess}/python_mappings.py +25 -32
- package/package.json +3 -3
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/constant_schema.py +0 -101
- package/autorest/codegen/models/credential_model.py +0 -47
- package/autorest/codegen/models/credential_schema.py +0 -91
- package/autorest/codegen/models/credential_schema_policy.py +0 -77
- package/autorest/codegen/models/dictionary_schema.py +0 -103
- package/autorest/codegen/models/enum_schema.py +0 -215
- package/autorest/codegen/models/list_schema.py +0 -123
- package/autorest/codegen/models/object_schema.py +0 -253
- package/autorest/codegen/models/primitive_schemas.py +0 -466
- package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
- package/autorest/codegen/models/rest.py +0 -42
- package/autorest/codegen/models/schema_request.py +0 -45
- package/autorest/codegen/models/schema_response.py +0 -136
- package/autorest/codegen/serializers/rest_serializer.py +0 -57
- package/autorest/namer/__init__.py +0 -25
- package/autorest/namer/name_converter.py +0 -412
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
import sys
|
|
7
|
+
import importlib
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main(namespace):
|
|
11
|
+
sdk = importlib.import_module(namespace)
|
|
12
|
+
return sdk._patch.__all__ # pylint: disable=protected-access
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
patched = ",".join(main(sys.argv[1]))
|
|
17
|
+
output_folder = sys.argv[2]
|
|
18
|
+
with open(f"{output_folder}/.temp_folder/patched.txt", "w") as f:
|
|
19
|
+
f.write(patched)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import Optional
|
|
7
|
+
import subprocess
|
|
8
|
+
import venv
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
_ROOT_DIR = Path(__file__).parent
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ExtendedEnvBuilder(venv.EnvBuilder):
|
|
17
|
+
"""An extended env builder which saves the context, to have access
|
|
18
|
+
easily to bin path and such.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, *args, **kwargs):
|
|
22
|
+
self.context = None
|
|
23
|
+
super(ExtendedEnvBuilder, self).__init__(*args, **kwargs)
|
|
24
|
+
|
|
25
|
+
def ensure_directories(self, env_dir):
|
|
26
|
+
self.context = super(ExtendedEnvBuilder, self).ensure_directories(env_dir)
|
|
27
|
+
return self.context
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def create(
|
|
31
|
+
env_dir,
|
|
32
|
+
system_site_packages=False,
|
|
33
|
+
clear=False,
|
|
34
|
+
symlinks=False,
|
|
35
|
+
with_pip=False,
|
|
36
|
+
prompt=None,
|
|
37
|
+
):
|
|
38
|
+
"""Create a virtual environment in a directory."""
|
|
39
|
+
builder = ExtendedEnvBuilder(
|
|
40
|
+
system_site_packages=system_site_packages,
|
|
41
|
+
clear=clear,
|
|
42
|
+
symlinks=symlinks,
|
|
43
|
+
with_pip=with_pip,
|
|
44
|
+
prompt=prompt,
|
|
45
|
+
)
|
|
46
|
+
builder.create(env_dir)
|
|
47
|
+
return builder.context
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def python_run( # pylint: disable=inconsistent-return-statements
|
|
51
|
+
venv_context, module, command, directory=_ROOT_DIR, *, error_ok=False
|
|
52
|
+
) -> Optional[str]:
|
|
53
|
+
try:
|
|
54
|
+
cmd_line = [
|
|
55
|
+
venv_context.env_exe,
|
|
56
|
+
"-m",
|
|
57
|
+
module,
|
|
58
|
+
] + command
|
|
59
|
+
print("Executing: {}".format(" ".join(cmd_line)))
|
|
60
|
+
subprocess.run(
|
|
61
|
+
cmd_line,
|
|
62
|
+
cwd=directory,
|
|
63
|
+
check=True,
|
|
64
|
+
stdout=False,
|
|
65
|
+
)
|
|
66
|
+
if module == "get_all":
|
|
67
|
+
with open(f"{command[1]}/.temp_folder/patched.txt", "r") as f:
|
|
68
|
+
return f.read()
|
|
69
|
+
except subprocess.CalledProcessError as err:
|
|
70
|
+
print(err)
|
|
71
|
+
if not error_ok:
|
|
72
|
+
sys.exit(1)
|
|
73
|
+
return None
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
"""The preprocessing autorest plugin.
|
|
7
|
+
"""
|
|
8
|
+
from typing import Callable, Dict, Any, List, Optional
|
|
9
|
+
from .helpers import to_snake_case, pad_reserved_words, add_redefined_builtin_info
|
|
10
|
+
from .python_mappings import PadType
|
|
11
|
+
|
|
12
|
+
from .. import YamlUpdatePlugin
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def update_description(
|
|
16
|
+
description: Optional[str], default_description: str = ""
|
|
17
|
+
) -> str:
|
|
18
|
+
if not description:
|
|
19
|
+
description = default_description
|
|
20
|
+
description.rstrip(" ")
|
|
21
|
+
if description and description[-1] != ".":
|
|
22
|
+
description += "."
|
|
23
|
+
return description
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def update_operation_group_class_name(
|
|
27
|
+
yaml_data: Dict[str, Any], class_name: str
|
|
28
|
+
) -> str:
|
|
29
|
+
if class_name == "":
|
|
30
|
+
return yaml_data["client"]["name"] + "OperationsMixin"
|
|
31
|
+
if class_name == "Operations":
|
|
32
|
+
return "Operations"
|
|
33
|
+
return class_name + "Operations"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def update_parameter(yaml_data: Dict[str, Any]) -> None:
|
|
37
|
+
yaml_data["description"] = update_description(yaml_data["description"])
|
|
38
|
+
if not (
|
|
39
|
+
yaml_data["location"] == "header"
|
|
40
|
+
and yaml_data["clientName"] in ("content_type", "accept")
|
|
41
|
+
):
|
|
42
|
+
yaml_data["clientName"] = pad_reserved_words(
|
|
43
|
+
yaml_data["clientName"].lower(), PadType.PARAMETER
|
|
44
|
+
)
|
|
45
|
+
if yaml_data.get("propertyToParameterName"):
|
|
46
|
+
# need to create a new one with padded keys and values
|
|
47
|
+
yaml_data["propertyToParameterName"] = {
|
|
48
|
+
pad_reserved_words(prop, PadType.PROPERTY)
|
|
49
|
+
.lower(): pad_reserved_words(param_name, PadType.PARAMETER)
|
|
50
|
+
.lower()
|
|
51
|
+
for prop, param_name in yaml_data["propertyToParameterName"].items()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def update_types(yaml_data: List[Dict[str, Any]]) -> None:
|
|
56
|
+
for type in yaml_data:
|
|
57
|
+
for property in type.get("properties", []):
|
|
58
|
+
property["description"] = update_description(property["description"])
|
|
59
|
+
property["clientName"] = pad_reserved_words(
|
|
60
|
+
property["clientName"].lower(), PadType.PROPERTY
|
|
61
|
+
)
|
|
62
|
+
add_redefined_builtin_info(property["clientName"], property)
|
|
63
|
+
if type.get("name"):
|
|
64
|
+
type["description"] = update_description(type["description"], type["name"])
|
|
65
|
+
type["snakeCaseName"] = to_snake_case(type["name"])
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def update_client(yaml_data: Dict[str, Any]) -> None:
|
|
69
|
+
yaml_data["description"] = update_description(
|
|
70
|
+
yaml_data["description"], default_description=yaml_data["name"]
|
|
71
|
+
)
|
|
72
|
+
yaml_data["moduleName"] = to_snake_case(yaml_data["name"].replace(" ", "_"))
|
|
73
|
+
for parameter in yaml_data["parameters"]:
|
|
74
|
+
update_parameter(parameter)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def update_paging_response(yaml_data: Dict[str, Any]) -> None:
|
|
78
|
+
yaml_data["discriminator"] = "paging"
|
|
79
|
+
yaml_data["pagerSync"] = yaml_data.get("pagerSync") or "azure.core.paging.ItemPaged"
|
|
80
|
+
yaml_data["pagerAsync"] = (
|
|
81
|
+
yaml_data.get("pagerAsync") or "azure.core.async_paging.AsyncItemPaged"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class PreProcessPlugin(YamlUpdatePlugin):
|
|
86
|
+
"""Add Python naming information."""
|
|
87
|
+
|
|
88
|
+
def get_operation_updater(
|
|
89
|
+
self, yaml_data: Dict[str, Any]
|
|
90
|
+
) -> Callable[[Dict[str, Any]], None]:
|
|
91
|
+
if yaml_data["discriminator"] == "lropaging":
|
|
92
|
+
return self.update_lro_paging_operation
|
|
93
|
+
if yaml_data["discriminator"] == "lro":
|
|
94
|
+
return self.update_lro_operation
|
|
95
|
+
if yaml_data["discriminator"] == "paging":
|
|
96
|
+
return self.update_paging_operation
|
|
97
|
+
return self.update_operation
|
|
98
|
+
|
|
99
|
+
def update_operation(self, yaml_data: Dict[str, Any]) -> None:
|
|
100
|
+
yaml_data["groupName"] = pad_reserved_words(
|
|
101
|
+
yaml_data["groupName"], PadType.OPERATION_GROUP
|
|
102
|
+
)
|
|
103
|
+
yaml_data["groupName"] = to_snake_case(yaml_data["groupName"])
|
|
104
|
+
yaml_data["name"] = yaml_data["name"].lower()
|
|
105
|
+
yaml_data["name"] = pad_reserved_words(yaml_data["name"], PadType.METHOD)
|
|
106
|
+
yaml_data["description"] = update_description(
|
|
107
|
+
yaml_data["description"], yaml_data["name"]
|
|
108
|
+
)
|
|
109
|
+
yaml_data["summary"] = update_description(yaml_data.get("summary", ""))
|
|
110
|
+
for parameter in yaml_data["parameters"]:
|
|
111
|
+
update_parameter(parameter)
|
|
112
|
+
if yaml_data.get("bodyParameter"):
|
|
113
|
+
update_parameter(yaml_data["bodyParameter"])
|
|
114
|
+
for entry in yaml_data["bodyParameter"].get("entries", []):
|
|
115
|
+
update_parameter(entry)
|
|
116
|
+
for overload in yaml_data.get("overloads", []):
|
|
117
|
+
self.update_operation(overload)
|
|
118
|
+
for response in yaml_data.get("responses", []):
|
|
119
|
+
response["discriminator"] = "operation"
|
|
120
|
+
|
|
121
|
+
def _update_lro_operation_helper(self, yaml_data: Dict[str, Any]) -> None:
|
|
122
|
+
azure_arm = self._autorestapi.get_boolean_value("azure-arm", False)
|
|
123
|
+
for response in yaml_data.get("responses", []):
|
|
124
|
+
response["discriminator"] = "lro"
|
|
125
|
+
response["pollerSync"] = (
|
|
126
|
+
response.get("pollerSync") or "azure.core.polling.LROPoller"
|
|
127
|
+
)
|
|
128
|
+
response["pollerAsync"] = (
|
|
129
|
+
response.get("pollerAsync") or "azure.core.polling.AsyncLROPoller"
|
|
130
|
+
)
|
|
131
|
+
if not response.get("pollingMethodSync"):
|
|
132
|
+
response["pollingMethodSync"] = (
|
|
133
|
+
"azure.mgmt.core.polling.arm_polling.ARMPolling"
|
|
134
|
+
if azure_arm
|
|
135
|
+
else "azure.core.polling.base_polling.LROBasePolling"
|
|
136
|
+
)
|
|
137
|
+
if not response.get("pollingMethodAsync"):
|
|
138
|
+
response["pollingMethodAsync"] = (
|
|
139
|
+
"azure.mgmt.core.polling.async_arm_polling.AsyncARMPolling"
|
|
140
|
+
if azure_arm
|
|
141
|
+
else "azure.core.polling.async_base_polling.AsyncLROBasePolling"
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def update_lro_paging_operation(self, yaml_data: Dict[str, Any]) -> None:
|
|
145
|
+
self.update_lro_operation(yaml_data)
|
|
146
|
+
self.update_paging_operation(yaml_data)
|
|
147
|
+
for response in yaml_data.get("responses", []):
|
|
148
|
+
response["discriminator"] = "lropaging"
|
|
149
|
+
|
|
150
|
+
def update_lro_operation(self, yaml_data: Dict[str, Any]) -> None:
|
|
151
|
+
self.update_operation(yaml_data)
|
|
152
|
+
self._update_lro_operation_helper(yaml_data)
|
|
153
|
+
for overload in yaml_data["overloads"]:
|
|
154
|
+
self._update_lro_operation_helper(overload)
|
|
155
|
+
|
|
156
|
+
def update_paging_operation(self, yaml_data: Dict[str, Any]) -> None:
|
|
157
|
+
self.update_operation(yaml_data)
|
|
158
|
+
if not yaml_data.get("pagerSync"):
|
|
159
|
+
yaml_data["pagerSync"] = "azure.core.paging.ItemPaged"
|
|
160
|
+
if not yaml_data.get("pagerAsync"):
|
|
161
|
+
yaml_data["pagerAsync"] = "azure.core.async_paging.AsyncItemPaged"
|
|
162
|
+
returned_response_object = (
|
|
163
|
+
yaml_data["nextOperation"]["responses"][0]
|
|
164
|
+
if yaml_data.get("nextOperation")
|
|
165
|
+
else yaml_data["responses"][0]
|
|
166
|
+
)
|
|
167
|
+
# if we're in version tolerant, hide the paging model
|
|
168
|
+
if self._autorestapi.get_boolean_value("version-tolerant"):
|
|
169
|
+
returned_response_object["type"]["isPublic"] = False
|
|
170
|
+
item_type = next(
|
|
171
|
+
p["type"]["elementType"]
|
|
172
|
+
for p in returned_response_object["type"]["properties"]
|
|
173
|
+
if p["restApiName"] == yaml_data["itemName"]
|
|
174
|
+
)
|
|
175
|
+
if yaml_data.get("nextOperation"):
|
|
176
|
+
yaml_data["nextOperation"]["groupName"] = pad_reserved_words(
|
|
177
|
+
yaml_data["nextOperation"]["groupName"], PadType.OPERATION_GROUP
|
|
178
|
+
)
|
|
179
|
+
yaml_data["nextOperation"]["groupName"] = to_snake_case(
|
|
180
|
+
yaml_data["nextOperation"]["groupName"]
|
|
181
|
+
)
|
|
182
|
+
for response in yaml_data["nextOperation"].get("responses", []):
|
|
183
|
+
update_paging_response(response)
|
|
184
|
+
response["itemType"] = item_type
|
|
185
|
+
for response in yaml_data.get("responses", []):
|
|
186
|
+
update_paging_response(response)
|
|
187
|
+
response["itemType"] = item_type
|
|
188
|
+
for overload in yaml_data.get("overloads", []):
|
|
189
|
+
self.update_paging_operation(overload)
|
|
190
|
+
|
|
191
|
+
def update_operation_groups(self, yaml_data: Dict[str, Any]) -> None:
|
|
192
|
+
operation_groups_yaml_data = yaml_data["operationGroups"]
|
|
193
|
+
for operation_group in operation_groups_yaml_data:
|
|
194
|
+
operation_group["propertyName"] = pad_reserved_words(
|
|
195
|
+
operation_group["propertyName"], PadType.OPERATION_GROUP
|
|
196
|
+
)
|
|
197
|
+
operation_group["propertyName"] = to_snake_case(
|
|
198
|
+
operation_group["propertyName"]
|
|
199
|
+
)
|
|
200
|
+
operation_group["className"] = update_operation_group_class_name(
|
|
201
|
+
yaml_data, operation_group["className"]
|
|
202
|
+
)
|
|
203
|
+
for operation in operation_group["operations"]:
|
|
204
|
+
self.get_operation_updater(operation)(operation)
|
|
205
|
+
|
|
206
|
+
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
|
|
207
|
+
"""Convert in place the YAML str."""
|
|
208
|
+
update_client(yaml_data["client"])
|
|
209
|
+
update_types(yaml_data["types"])
|
|
210
|
+
self.update_operation_groups(yaml_data)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
+
# license information.
|
|
5
|
+
# --------------------------------------------------------------------------
|
|
6
|
+
from typing import Any, Dict
|
|
7
|
+
import re
|
|
8
|
+
from .python_mappings import PadType, RESERVED_WORDS, REDEFINED_BUILTINS
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def to_snake_case(name: str) -> str:
|
|
12
|
+
def replace_upper_characters(m) -> str:
|
|
13
|
+
match_str = m.group().lower()
|
|
14
|
+
if m.start() > 0 and name[m.start() - 1] == "_":
|
|
15
|
+
# we are good if a '_' already exists
|
|
16
|
+
return match_str
|
|
17
|
+
# the first letter should not have _
|
|
18
|
+
prefix = "_" if m.start() > 0 else ""
|
|
19
|
+
|
|
20
|
+
# we will add an extra _ if there are multiple upper case chars together
|
|
21
|
+
next_non_upper_case_char_location = m.start() + len(match_str)
|
|
22
|
+
if (
|
|
23
|
+
len(match_str) > 2
|
|
24
|
+
and len(name) - next_non_upper_case_char_location > 1
|
|
25
|
+
and name[next_non_upper_case_char_location].isalpha()
|
|
26
|
+
):
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
prefix
|
|
30
|
+
+ match_str[: len(match_str) - 1]
|
|
31
|
+
+ "_"
|
|
32
|
+
+ match_str[len(match_str) - 1]
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return prefix + match_str
|
|
36
|
+
|
|
37
|
+
return re.sub("[A-Z]+", replace_upper_characters, name)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def pad_reserved_words(name: str, pad_type: PadType):
|
|
41
|
+
# we want to pad hidden variables as well
|
|
42
|
+
if not name:
|
|
43
|
+
# we'll pass in empty operation groups sometime etc.
|
|
44
|
+
return name
|
|
45
|
+
name_prefix = "_" if name[0] == "_" else ""
|
|
46
|
+
name = name[1:] if name[0] == "_" else name
|
|
47
|
+
if name.lower() in RESERVED_WORDS[pad_type]:
|
|
48
|
+
return name_prefix + name + pad_type
|
|
49
|
+
return name_prefix + name
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def add_redefined_builtin_info(name: str, yaml_data: Dict[str, Any]) -> None:
|
|
53
|
+
if name in REDEFINED_BUILTINS:
|
|
54
|
+
yaml_data["pylintDisable"] = "redefined-builtin"
|
|
@@ -50,14 +50,15 @@ basic_latin_chars = {
|
|
|
50
50
|
"~": "Tilde",
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
|
|
54
|
+
class PadType(str, Enum):
|
|
55
|
+
MODEL = "Model"
|
|
56
|
+
METHOD = "_method"
|
|
57
|
+
PARAMETER = "_parameter"
|
|
58
|
+
ENUM = "_enum"
|
|
59
|
+
PROPERTY = "_property"
|
|
60
|
+
OPERATION_GROUP = "Operations"
|
|
61
|
+
|
|
61
62
|
|
|
62
63
|
_always_reserved = [
|
|
63
64
|
"and",
|
|
@@ -91,14 +92,12 @@ _always_reserved = [
|
|
|
91
92
|
"with",
|
|
92
93
|
"yield",
|
|
93
94
|
"async",
|
|
94
|
-
"await"
|
|
95
|
+
"await",
|
|
95
96
|
]
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
PadType.
|
|
99
|
-
|
|
100
|
-
],
|
|
101
|
-
PadType.Parameter: [
|
|
98
|
+
RESERVED_WORDS = {
|
|
99
|
+
PadType.METHOD: [*_always_reserved],
|
|
100
|
+
PadType.PARAMETER: [
|
|
102
101
|
"self",
|
|
103
102
|
# these are kwargs we've reserved for our autorest generated operations
|
|
104
103
|
"content_type",
|
|
@@ -161,23 +160,17 @@ reserved_words = {
|
|
|
161
160
|
"retry_backoff_max",
|
|
162
161
|
"retry_mode",
|
|
163
162
|
"retry_on_status_codes",
|
|
164
|
-
*_always_reserved
|
|
165
|
-
],
|
|
166
|
-
PadType.Model: [
|
|
167
|
-
*_always_reserved
|
|
168
|
-
],
|
|
169
|
-
PadType.Property: [
|
|
170
|
-
"self",
|
|
171
|
-
*_always_reserved
|
|
172
|
-
],
|
|
173
|
-
PadType.Enum: [
|
|
174
|
-
"mro",
|
|
175
|
-
*_always_reserved
|
|
176
|
-
],
|
|
177
|
-
PadType.OperationGroup: [
|
|
178
|
-
*_always_reserved
|
|
163
|
+
*_always_reserved,
|
|
179
164
|
],
|
|
180
|
-
PadType.
|
|
181
|
-
|
|
182
|
-
]
|
|
165
|
+
PadType.MODEL: [*_always_reserved],
|
|
166
|
+
PadType.PROPERTY: ["self", *_always_reserved],
|
|
167
|
+
PadType.ENUM: ["mro", *_always_reserved],
|
|
168
|
+
PadType.OPERATION_GROUP: [*_always_reserved],
|
|
183
169
|
}
|
|
170
|
+
|
|
171
|
+
REDEFINED_BUILTINS = [ # we don't pad, but we need to do lint ignores
|
|
172
|
+
"id",
|
|
173
|
+
"min",
|
|
174
|
+
"max",
|
|
175
|
+
"filter",
|
|
176
|
+
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.0",
|
|
4
4
|
"description": "The Python extension for generators in AutoRest.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "node run-python3.js prepare.py",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/Azure/autorest.python/blob/autorestv3/README.md",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@
|
|
27
|
+
"@autorest/system-requirements": "~1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@microsoft.azure/autorest.testserver": "3.3.
|
|
30
|
+
"@microsoft.azure/autorest.testserver": "^3.3.28"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"autorest/**/*.py",
|
package/run-python3.js
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
// Invoke it like so: "node run-python3.js script.py"
|
|
8
8
|
|
|
9
9
|
const cp = require("child_process");
|
|
10
|
-
const extension = require("@
|
|
10
|
+
const extension = require("@autorest/system-requirements");
|
|
11
11
|
|
|
12
12
|
async function runPython3(scriptName, debug = "") {
|
|
13
|
-
const command = ["python", scriptName, debug];
|
|
14
|
-
await extension.updatePythonPath(command);
|
|
13
|
+
const command = await extension.patchPythonPath(["python", scriptName, debug], { version: ">=3.6", environmentVariable: "AUTOREST_PYTHON_EXE" });
|
|
15
14
|
cp.execSync(command.join(" "), {
|
|
16
15
|
stdio: [0, 1, 2]
|
|
17
16
|
});
|
package/venvtools.py
CHANGED
|
@@ -21,7 +21,7 @@ class ExtendedEnvBuilder(venv.EnvBuilder):
|
|
|
21
21
|
|
|
22
22
|
def __init__(self, *args, **kwargs):
|
|
23
23
|
self.context = None
|
|
24
|
-
super(
|
|
24
|
+
super().__init__(*args, **kwargs)
|
|
25
25
|
|
|
26
26
|
def ensure_directories(self, env_dir):
|
|
27
27
|
self.context = super(ExtendedEnvBuilder, self).ensure_directories(env_dir)
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
# license information.
|
|
5
|
-
# --------------------------------------------------------------------------
|
|
6
|
-
import logging
|
|
7
|
-
from typing import Dict, Any, Optional
|
|
8
|
-
from .base_schema import BaseSchema
|
|
9
|
-
from .primitive_schemas import get_primitive_schema, PrimitiveSchema
|
|
10
|
-
from .imports import FileImport
|
|
11
|
-
|
|
12
|
-
_LOGGER = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ConstantSchema(BaseSchema):
|
|
16
|
-
"""Schema for constants that will be serialized.
|
|
17
|
-
|
|
18
|
-
:param yaml_data: the yaml data for this schema
|
|
19
|
-
:type yaml_data: dict[str, Any]
|
|
20
|
-
:param str value: The actual value of this constant.
|
|
21
|
-
:param schema: The schema for the value of this constant.
|
|
22
|
-
:type schema: ~autorest.models.PrimitiveSchema
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
def __init__(
|
|
26
|
-
self, namespace: str, yaml_data: Dict[str, Any], schema: PrimitiveSchema, value: Optional[str],
|
|
27
|
-
) -> None:
|
|
28
|
-
super(ConstantSchema, self).__init__(namespace=namespace, yaml_data=yaml_data)
|
|
29
|
-
self.value = value
|
|
30
|
-
self.schema = schema
|
|
31
|
-
|
|
32
|
-
def get_declaration(self, value: Any):
|
|
33
|
-
if value != self.value:
|
|
34
|
-
_LOGGER.warning(
|
|
35
|
-
"Passed in value of %s differs from constant value of %s. Choosing constant value",
|
|
36
|
-
str(value), str(self.value)
|
|
37
|
-
)
|
|
38
|
-
if self.value is None:
|
|
39
|
-
return "None"
|
|
40
|
-
return self.schema.get_declaration(self.value)
|
|
41
|
-
|
|
42
|
-
@property
|
|
43
|
-
def serialization_type(self) -> str:
|
|
44
|
-
"""Returns the serialization value for msrest.
|
|
45
|
-
|
|
46
|
-
:return: The serialization value for msrest
|
|
47
|
-
:rtype: str
|
|
48
|
-
"""
|
|
49
|
-
return self.schema.serialization_type
|
|
50
|
-
|
|
51
|
-
@property
|
|
52
|
-
def docstring_text(self) -> str:
|
|
53
|
-
return "constant"
|
|
54
|
-
|
|
55
|
-
@property
|
|
56
|
-
def docstring_type(self) -> str:
|
|
57
|
-
"""The python type used for RST syntax input and type annotation.
|
|
58
|
-
|
|
59
|
-
:param str namespace: Optional. The namespace for the models.
|
|
60
|
-
"""
|
|
61
|
-
return self.schema.docstring_type
|
|
62
|
-
|
|
63
|
-
def type_annotation(self, *, is_operation_file: bool = False) -> str:
|
|
64
|
-
return self.schema.type_annotation(is_operation_file=is_operation_file)
|
|
65
|
-
|
|
66
|
-
@classmethod
|
|
67
|
-
def from_yaml(cls, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> "ConstantSchema":
|
|
68
|
-
"""Constructs a ConstantSchema from yaml data.
|
|
69
|
-
|
|
70
|
-
:param yaml_data: the yaml data from which we will construct this schema
|
|
71
|
-
:type yaml_data: dict[str, Any]
|
|
72
|
-
|
|
73
|
-
:return: A created ConstantSchema
|
|
74
|
-
:rtype: ~autorest.models.ConstantSchema
|
|
75
|
-
"""
|
|
76
|
-
name = yaml_data["language"]["python"]["name"] if yaml_data["language"]["python"].get("name") else ""
|
|
77
|
-
_LOGGER.debug("Parsing %s constant", name)
|
|
78
|
-
return cls(
|
|
79
|
-
namespace=namespace,
|
|
80
|
-
yaml_data=yaml_data,
|
|
81
|
-
schema=get_primitive_schema(namespace=namespace, yaml_data=yaml_data["valueType"]),
|
|
82
|
-
value=yaml_data.get("value", {}).get("value", None),
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
def get_json_template_representation(self, **kwargs: Any) -> Any:
|
|
86
|
-
kwargs['default_value_declaration'] = self.schema.get_declaration(self.value)
|
|
87
|
-
return self.schema.get_json_template_representation(**kwargs)
|
|
88
|
-
|
|
89
|
-
def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
|
|
90
|
-
kwargs['default_value_declaration'] = self.schema.get_declaration(self.value)
|
|
91
|
-
return self.schema.get_files_and_data_template_representation(**kwargs)
|
|
92
|
-
|
|
93
|
-
def imports(self) -> FileImport:
|
|
94
|
-
file_import = FileImport()
|
|
95
|
-
file_import.merge(self.schema.imports())
|
|
96
|
-
return file_import
|
|
97
|
-
|
|
98
|
-
def model_file_imports(self) -> FileImport:
|
|
99
|
-
file_import = self.imports()
|
|
100
|
-
file_import.merge(self.schema.model_file_imports())
|
|
101
|
-
return file_import
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# -------------------------------------------------------------------------
|
|
2
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
# Licensed under the MIT License. See License.txt in the project root for
|
|
4
|
-
# license information.
|
|
5
|
-
# --------------------------------------------------------------------------
|
|
6
|
-
from typing import Set, Optional, Type
|
|
7
|
-
from .credential_schema_policy import CredentialSchemaPolicy, BearerTokenCredentialPolicy
|
|
8
|
-
from .credential_schema_policy import ARMChallengeAuthenticationPolicy
|
|
9
|
-
from .credential_schema import TokenCredentialSchema, AzureKeyCredentialSchema
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class CredentialModel:
|
|
13
|
-
"""Store info about credential.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
def __init__(
|
|
17
|
-
self,
|
|
18
|
-
azure_arm: bool
|
|
19
|
-
) -> None:
|
|
20
|
-
self.azure_arm: bool = azure_arm
|
|
21
|
-
self.credential_scopes: Set[str] = set()
|
|
22
|
-
self.key_header_name: str = ""
|
|
23
|
-
self.policy_type: Optional[Type[CredentialSchemaPolicy]] = None
|
|
24
|
-
self._credential_schema_policy: Optional[CredentialSchemaPolicy] = None
|
|
25
|
-
|
|
26
|
-
@property
|
|
27
|
-
def default_authentication_policy(self) -> Type[CredentialSchemaPolicy]:
|
|
28
|
-
return ARMChallengeAuthenticationPolicy if self.azure_arm else BearerTokenCredentialPolicy
|
|
29
|
-
|
|
30
|
-
@property
|
|
31
|
-
def credential_schema_policy(self) -> CredentialSchemaPolicy:
|
|
32
|
-
if not self._credential_schema_policy:
|
|
33
|
-
raise ValueError(
|
|
34
|
-
"You want to find the Credential Schema Policy, but have not given a value")
|
|
35
|
-
return self._credential_schema_policy
|
|
36
|
-
|
|
37
|
-
def build_authentication_policy(self):
|
|
38
|
-
if hasattr(self.policy_type, "credential_scopes"):
|
|
39
|
-
self._credential_schema_policy = self.policy_type( # pylint: disable=not-callable
|
|
40
|
-
credential=TokenCredentialSchema(async_mode=False),
|
|
41
|
-
credential_scopes=list(self.credential_scopes),
|
|
42
|
-
)
|
|
43
|
-
elif hasattr(self.policy_type, "credential_key_header_name"):
|
|
44
|
-
self._credential_schema_policy = self.policy_type( # pylint: disable=not-callable
|
|
45
|
-
credential=AzureKeyCredentialSchema(),
|
|
46
|
-
credential_key_header_name=self.key_header_name
|
|
47
|
-
)
|