@autorest/python 5.14.0 → 5.17.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.
Files changed (120) hide show
  1. package/ChangeLog.md +91 -2
  2. package/README.md +30 -4
  3. package/autorest/__init__.py +2 -3
  4. package/autorest/black/__init__.py +12 -5
  5. package/autorest/codegen/__init__.py +130 -179
  6. package/autorest/codegen/models/__init__.py +122 -78
  7. package/autorest/codegen/models/base_builder.py +70 -72
  8. package/autorest/codegen/models/base_model.py +7 -5
  9. package/autorest/codegen/models/{base_schema.py → base_type.py} +62 -49
  10. package/autorest/codegen/models/client.py +195 -36
  11. package/autorest/codegen/models/code_model.py +165 -299
  12. package/autorest/codegen/models/combined_type.py +107 -0
  13. package/autorest/codegen/models/constant_type.py +122 -0
  14. package/autorest/codegen/models/credential_types.py +224 -0
  15. package/autorest/codegen/models/dictionary_type.py +116 -0
  16. package/autorest/codegen/models/enum_type.py +195 -0
  17. package/autorest/codegen/models/imports.py +95 -41
  18. package/autorest/codegen/models/list_type.py +134 -0
  19. package/autorest/codegen/models/lro_operation.py +90 -133
  20. package/autorest/codegen/models/lro_paging_operation.py +28 -12
  21. package/autorest/codegen/models/model_type.py +239 -0
  22. package/autorest/codegen/models/operation.py +415 -241
  23. package/autorest/codegen/models/operation_group.py +82 -88
  24. package/autorest/codegen/models/paging_operation.py +101 -117
  25. package/autorest/codegen/models/parameter.py +307 -322
  26. package/autorest/codegen/models/parameter_list.py +366 -357
  27. package/autorest/codegen/models/primitive_types.py +544 -0
  28. package/autorest/codegen/models/property.py +122 -134
  29. package/autorest/codegen/models/request_builder.py +138 -86
  30. package/autorest/codegen/models/request_builder_parameter.py +122 -79
  31. package/autorest/codegen/models/response.py +325 -0
  32. package/autorest/codegen/models/utils.py +17 -1
  33. package/autorest/codegen/serializers/__init__.py +242 -118
  34. package/autorest/codegen/serializers/builder_serializer.py +863 -1027
  35. package/autorest/codegen/serializers/client_serializer.py +148 -82
  36. package/autorest/codegen/serializers/general_serializer.py +44 -47
  37. package/autorest/codegen/serializers/import_serializer.py +96 -31
  38. package/autorest/codegen/serializers/metadata_serializer.py +39 -79
  39. package/autorest/codegen/serializers/model_base_serializer.py +65 -29
  40. package/autorest/codegen/serializers/model_generic_serializer.py +9 -10
  41. package/autorest/codegen/serializers/model_init_serializer.py +4 -2
  42. package/autorest/codegen/serializers/model_python3_serializer.py +29 -22
  43. package/autorest/codegen/serializers/operation_groups_serializer.py +21 -18
  44. package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
  45. package/autorest/codegen/serializers/parameter_serializer.py +174 -0
  46. package/autorest/codegen/serializers/patch_serializer.py +14 -2
  47. package/autorest/codegen/serializers/request_builders_serializer.py +57 -0
  48. package/autorest/codegen/serializers/utils.py +0 -103
  49. package/autorest/codegen/templates/MANIFEST.in.jinja2 +1 -0
  50. package/autorest/codegen/templates/{service_client.py.jinja2 → client.py.jinja2} +7 -7
  51. package/autorest/codegen/templates/config.py.jinja2 +13 -13
  52. package/autorest/codegen/templates/enum.py.jinja2 +4 -4
  53. package/autorest/codegen/templates/enum_container.py.jinja2 +1 -2
  54. package/autorest/codegen/templates/init.py.jinja2 +9 -6
  55. package/autorest/codegen/templates/keywords.jinja2 +14 -1
  56. package/autorest/codegen/templates/lro_operation.py.jinja2 +6 -5
  57. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +6 -5
  58. package/autorest/codegen/templates/metadata.json.jinja2 +36 -35
  59. package/autorest/codegen/templates/model.py.jinja2 +23 -29
  60. package/autorest/codegen/templates/model_container.py.jinja2 +2 -1
  61. package/autorest/codegen/templates/model_init.py.jinja2 +9 -8
  62. package/autorest/codegen/templates/operation.py.jinja2 +10 -15
  63. package/autorest/codegen/templates/operation_group.py.jinja2 +14 -13
  64. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -2
  65. package/autorest/codegen/templates/operation_tools.jinja2 +8 -2
  66. package/autorest/codegen/templates/operations_folder_init.py.jinja2 +4 -0
  67. package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
  68. package/autorest/codegen/templates/patch.py.jinja2 +18 -29
  69. package/autorest/codegen/templates/request_builder.py.jinja2 +20 -13
  70. package/autorest/codegen/templates/setup.py.jinja2 +9 -3
  71. package/autorest/codegen/templates/vendor.py.jinja2 +12 -2
  72. package/autorest/jsonrpc/__init__.py +7 -12
  73. package/autorest/jsonrpc/localapi.py +4 -3
  74. package/autorest/jsonrpc/server.py +28 -9
  75. package/autorest/jsonrpc/stdstream.py +13 -6
  76. package/autorest/m2r/__init__.py +5 -8
  77. package/autorest/m4reformatter/__init__.py +1108 -0
  78. package/autorest/multiapi/__init__.py +24 -14
  79. package/autorest/multiapi/models/client.py +21 -11
  80. package/autorest/multiapi/models/code_model.py +23 -10
  81. package/autorest/multiapi/models/config.py +4 -1
  82. package/autorest/multiapi/models/constant_global_parameter.py +1 -0
  83. package/autorest/multiapi/models/global_parameter.py +2 -1
  84. package/autorest/multiapi/models/global_parameters.py +14 -8
  85. package/autorest/multiapi/models/imports.py +35 -18
  86. package/autorest/multiapi/models/mixin_operation.py +5 -5
  87. package/autorest/multiapi/models/operation_group.py +2 -1
  88. package/autorest/multiapi/models/operation_mixin_group.py +21 -10
  89. package/autorest/multiapi/serializers/__init__.py +20 -25
  90. package/autorest/multiapi/serializers/import_serializer.py +47 -15
  91. package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
  92. package/autorest/multiapi/templates/multiapi_config.py.jinja2 +3 -3
  93. package/autorest/multiapi/templates/multiapi_init.py.jinja2 +2 -2
  94. package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +4 -4
  95. package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +9 -9
  96. package/autorest/multiapi/utils.py +3 -3
  97. package/autorest/postprocess/__init__.py +202 -0
  98. package/autorest/postprocess/get_all.py +19 -0
  99. package/autorest/postprocess/venvtools.py +73 -0
  100. package/autorest/preprocess/__init__.py +209 -0
  101. package/autorest/preprocess/helpers.py +54 -0
  102. package/autorest/{namer → preprocess}/python_mappings.py +25 -32
  103. package/package.json +3 -3
  104. package/run-python3.js +2 -3
  105. package/venvtools.py +1 -1
  106. package/autorest/codegen/models/constant_schema.py +0 -97
  107. package/autorest/codegen/models/credential_schema.py +0 -90
  108. package/autorest/codegen/models/credential_schema_policy.py +0 -77
  109. package/autorest/codegen/models/dictionary_schema.py +0 -103
  110. package/autorest/codegen/models/enum_schema.py +0 -246
  111. package/autorest/codegen/models/list_schema.py +0 -113
  112. package/autorest/codegen/models/object_schema.py +0 -249
  113. package/autorest/codegen/models/primitive_schemas.py +0 -476
  114. package/autorest/codegen/models/request_builder_parameter_list.py +0 -280
  115. package/autorest/codegen/models/rest.py +0 -42
  116. package/autorest/codegen/models/schema_request.py +0 -45
  117. package/autorest/codegen/models/schema_response.py +0 -123
  118. package/autorest/codegen/serializers/rest_serializer.py +0 -57
  119. package/autorest/namer/__init__.py +0 -25
  120. 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,209 @@
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
+
66
+
67
+ def update_client(yaml_data: Dict[str, Any]) -> None:
68
+ yaml_data["description"] = update_description(
69
+ yaml_data["description"], default_description=yaml_data["name"]
70
+ )
71
+ yaml_data["moduleName"] = to_snake_case(yaml_data["name"].replace(" ", "_"))
72
+ for parameter in yaml_data["parameters"]:
73
+ update_parameter(parameter)
74
+
75
+
76
+ def update_paging_response(yaml_data: Dict[str, Any]) -> None:
77
+ yaml_data["discriminator"] = "paging"
78
+ yaml_data["pagerSync"] = yaml_data.get("pagerSync") or "azure.core.paging.ItemPaged"
79
+ yaml_data["pagerAsync"] = (
80
+ yaml_data.get("pagerAsync") or "azure.core.async_paging.AsyncItemPaged"
81
+ )
82
+
83
+
84
+ class PreProcessPlugin(YamlUpdatePlugin):
85
+ """Add Python naming information."""
86
+
87
+ def get_operation_updater(
88
+ self, yaml_data: Dict[str, Any]
89
+ ) -> Callable[[Dict[str, Any]], None]:
90
+ if yaml_data["discriminator"] == "lropaging":
91
+ return self.update_lro_paging_operation
92
+ if yaml_data["discriminator"] == "lro":
93
+ return self.update_lro_operation
94
+ if yaml_data["discriminator"] == "paging":
95
+ return self.update_paging_operation
96
+ return self.update_operation
97
+
98
+ def update_operation(self, yaml_data: Dict[str, Any]) -> None:
99
+ yaml_data["groupName"] = pad_reserved_words(
100
+ yaml_data["groupName"], PadType.OPERATION_GROUP
101
+ )
102
+ yaml_data["groupName"] = to_snake_case(yaml_data["groupName"])
103
+ yaml_data["name"] = yaml_data["name"].lower()
104
+ yaml_data["name"] = pad_reserved_words(yaml_data["name"], PadType.METHOD)
105
+ yaml_data["description"] = update_description(
106
+ yaml_data["description"], yaml_data["name"]
107
+ )
108
+ yaml_data["summary"] = update_description(yaml_data.get("summary", ""))
109
+ for parameter in yaml_data["parameters"]:
110
+ update_parameter(parameter)
111
+ if yaml_data.get("bodyParameter"):
112
+ update_parameter(yaml_data["bodyParameter"])
113
+ for entry in yaml_data["bodyParameter"].get("entries", []):
114
+ update_parameter(entry)
115
+ for overload in yaml_data.get("overloads", []):
116
+ self.update_operation(overload)
117
+ for response in yaml_data.get("responses", []):
118
+ response["discriminator"] = "operation"
119
+
120
+ def _update_lro_operation_helper(self, yaml_data: Dict[str, Any]) -> None:
121
+ azure_arm = self._autorestapi.get_boolean_value("azure-arm", False)
122
+ for response in yaml_data.get("responses", []):
123
+ response["discriminator"] = "lro"
124
+ response["pollerSync"] = (
125
+ response.get("pollerSync") or "azure.core.polling.LROPoller"
126
+ )
127
+ response["pollerAsync"] = (
128
+ response.get("pollerAsync") or "azure.core.polling.AsyncLROPoller"
129
+ )
130
+ if not response.get("pollingMethodSync"):
131
+ response["pollingMethodSync"] = (
132
+ "azure.mgmt.core.polling.arm_polling.ARMPolling"
133
+ if azure_arm
134
+ else "azure.core.polling.base_polling.LROBasePolling"
135
+ )
136
+ if not response.get("pollingMethodAsync"):
137
+ response["pollingMethodAsync"] = (
138
+ "azure.mgmt.core.polling.async_arm_polling.AsyncARMPolling"
139
+ if azure_arm
140
+ else "azure.core.polling.async_base_polling.AsyncLROBasePolling"
141
+ )
142
+
143
+ def update_lro_paging_operation(self, yaml_data: Dict[str, Any]) -> None:
144
+ self.update_lro_operation(yaml_data)
145
+ self.update_paging_operation(yaml_data)
146
+ for response in yaml_data.get("responses", []):
147
+ response["discriminator"] = "lropaging"
148
+
149
+ def update_lro_operation(self, yaml_data: Dict[str, Any]) -> None:
150
+ self.update_operation(yaml_data)
151
+ self._update_lro_operation_helper(yaml_data)
152
+ for overload in yaml_data["overloads"]:
153
+ self._update_lro_operation_helper(overload)
154
+
155
+ def update_paging_operation(self, yaml_data: Dict[str, Any]) -> None:
156
+ self.update_operation(yaml_data)
157
+ if not yaml_data.get("pagerSync"):
158
+ yaml_data["pagerSync"] = "azure.core.paging.ItemPaged"
159
+ if not yaml_data.get("pagerAsync"):
160
+ yaml_data["pagerAsync"] = "azure.core.async_paging.AsyncItemPaged"
161
+ returned_response_object = (
162
+ yaml_data["nextOperation"]["responses"][0]
163
+ if yaml_data.get("nextOperation")
164
+ else yaml_data["responses"][0]
165
+ )
166
+ # if we're in version tolerant, hide the paging model
167
+ if self._autorestapi.get_boolean_value("version-tolerant"):
168
+ returned_response_object["type"]["isPublic"] = False
169
+ item_type = next(
170
+ p["type"]["elementType"]
171
+ for p in returned_response_object["type"]["properties"]
172
+ if p["restApiName"] == yaml_data["itemName"]
173
+ )
174
+ if yaml_data.get("nextOperation"):
175
+ yaml_data["nextOperation"]["groupName"] = pad_reserved_words(
176
+ yaml_data["nextOperation"]["groupName"], PadType.OPERATION_GROUP
177
+ )
178
+ yaml_data["nextOperation"]["groupName"] = to_snake_case(
179
+ yaml_data["nextOperation"]["groupName"]
180
+ )
181
+ for response in yaml_data["nextOperation"].get("responses", []):
182
+ update_paging_response(response)
183
+ response["itemType"] = item_type
184
+ for response in yaml_data.get("responses", []):
185
+ update_paging_response(response)
186
+ response["itemType"] = item_type
187
+ for overload in yaml_data.get("overloads", []):
188
+ self.update_paging_operation(overload)
189
+
190
+ def update_operation_groups(self, yaml_data: Dict[str, Any]) -> None:
191
+ operation_groups_yaml_data = yaml_data["operationGroups"]
192
+ for operation_group in operation_groups_yaml_data:
193
+ operation_group["propertyName"] = pad_reserved_words(
194
+ operation_group["propertyName"], PadType.OPERATION_GROUP
195
+ )
196
+ operation_group["propertyName"] = to_snake_case(
197
+ operation_group["propertyName"]
198
+ )
199
+ operation_group["className"] = update_operation_group_class_name(
200
+ yaml_data, operation_group["className"]
201
+ )
202
+ for operation in operation_group["operations"]:
203
+ self.get_operation_updater(operation)(operation)
204
+
205
+ def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
206
+ """Convert in place the YAML str."""
207
+ update_client(yaml_data["client"])
208
+ update_types(yaml_data["types"])
209
+ 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
- class PadType(Enum):
54
- Model = "Model"
55
- Method = "Method"
56
- Parameter = "Parameter"
57
- Enum = "Enum"
58
- Property = "Property"
59
- OperationGroup = "Operations"
60
- BuilderGroup = "Builders"
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
- reserved_words = {
98
- PadType.Method: [
99
- *_always_reserved
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.BuilderGroup: [
181
- *_always_reserved
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.14.0",
3
+ "version": "5.17.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
- "@azure-tools/extension": "~3.2.1"
27
+ "@autorest/system-requirements": "~1.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@microsoft.azure/autorest.testserver": "^3.3.20"
30
+ "@microsoft.azure/autorest.testserver": "^3.3.26"
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("@azure-tools/extension");
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(ExtendedEnvBuilder, self).__init__(*args, **kwargs)
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,97 +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
- @property
64
- def type_annotation(self) -> str:
65
- return self.schema.type_annotation
66
-
67
- @classmethod
68
- def from_yaml(cls, namespace: str, yaml_data: Dict[str, Any], **kwargs) -> "ConstantSchema":
69
- """Constructs a ConstantSchema from yaml data.
70
-
71
- :param yaml_data: the yaml data from which we will construct this schema
72
- :type yaml_data: dict[str, Any]
73
-
74
- :return: A created ConstantSchema
75
- :rtype: ~autorest.models.ConstantSchema
76
- """
77
- name = yaml_data["language"]["python"]["name"] if yaml_data["language"]["python"].get("name") else ""
78
- _LOGGER.debug("Parsing %s constant", name)
79
- return cls(
80
- namespace=namespace,
81
- yaml_data=yaml_data,
82
- schema=get_primitive_schema(namespace=namespace, yaml_data=yaml_data["valueType"]),
83
- value=yaml_data.get("value", {}).get("value", None),
84
- )
85
-
86
- def get_json_template_representation(self, **kwargs: Any) -> Any:
87
- kwargs['default_value_declaration'] = self.schema.get_declaration(self.value)
88
- return self.schema.get_json_template_representation(**kwargs)
89
-
90
- def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
91
- kwargs['default_value_declaration'] = self.schema.get_declaration(self.value)
92
- return self.schema.get_files_and_data_template_representation(**kwargs)
93
-
94
- def imports(self) -> FileImport:
95
- file_import = FileImport()
96
- file_import.merge(self.schema.imports())
97
- return file_import
@@ -1,90 +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 Any
7
- from .base_schema import BaseSchema
8
- from .imports import FileImport, ImportType, TypingSection
9
-
10
- class CredentialSchema(BaseSchema):
11
- def __init__(self) -> None: # pylint: disable=super-init-not-called
12
- self.default_value = None
13
-
14
- @property
15
- def docstring_type(self) -> str:
16
- return self.serialization_type
17
-
18
- @property
19
- def docstring_text(self) -> str:
20
- return "credential"
21
-
22
- @property
23
- def serialization_type(self) -> str:
24
- # this property is added, because otherwise pylint says that
25
- # abstract serialization_type in BaseSchema is not overridden
26
- pass
27
-
28
- def get_json_template_representation(self, **kwargs: Any) -> Any:
29
- raise TypeError("You should not try to get a JSON template representation of a CredentialSchema")
30
-
31
- def get_files_and_data_template_representation(self, **kwargs: Any) -> Any:
32
- raise TypeError("You should not try to get a files template representation of a CredentialSchema")
33
-
34
-
35
- class AzureKeyCredentialSchema(CredentialSchema):
36
-
37
- @property
38
- def serialization_type(self) -> str:
39
- return "~azure.core.credentials.AzureKeyCredential"
40
-
41
- @property
42
- def type_annotation(self) -> str:
43
- return "AzureKeyCredential"
44
-
45
- def imports(self) -> FileImport:
46
- file_import = FileImport()
47
- file_import.add_submodule_import(
48
- "azure.core.credentials",
49
- "AzureKeyCredential",
50
- ImportType.AZURECORE,
51
- typing_section=TypingSection.CONDITIONAL
52
- )
53
- return file_import
54
-
55
-
56
- class TokenCredentialSchema(CredentialSchema):
57
- def __init__(self, async_mode) -> None:
58
- super(TokenCredentialSchema, self).__init__()
59
- self.async_mode = async_mode
60
- self.async_type = "~azure.core.credentials_async.AsyncTokenCredential"
61
- self.sync_type = "~azure.core.credentials.TokenCredential"
62
-
63
- @property
64
- def serialization_type(self) -> str:
65
- if self.async_mode:
66
- return self.async_type
67
- return self.sync_type
68
-
69
- @property
70
- def type_annotation(self) -> str:
71
- if self.async_mode:
72
- return '"AsyncTokenCredential"'
73
- return '"TokenCredential"'
74
-
75
-
76
- def imports(self) -> FileImport:
77
- file_import = FileImport()
78
- if self.async_mode:
79
- file_import.add_submodule_import(
80
- "azure.core.credentials_async", "AsyncTokenCredential",
81
- ImportType.AZURECORE,
82
- typing_section=TypingSection.TYPING
83
- )
84
- else:
85
- file_import.add_submodule_import(
86
- "azure.core.credentials", "TokenCredential",
87
- ImportType.AZURECORE,
88
- typing_section=TypingSection.TYPING
89
- )
90
- return file_import