@autorest/python 6.2.4 → 6.2.7
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/black/__init__.py +3 -2
- package/autorest/codegen/__init__.py +1 -1
- package/autorest/codegen/models/base.py +14 -2
- package/autorest/codegen/models/client.py +20 -22
- package/autorest/codegen/models/combined_type.py +1 -1
- package/autorest/codegen/models/imports.py +2 -2
- package/autorest/codegen/models/model_type.py +4 -0
- package/autorest/codegen/models/operation.py +6 -6
- package/autorest/codegen/models/operation_group.py +12 -11
- package/autorest/codegen/models/primitive_types.py +50 -0
- package/autorest/codegen/models/property.py +4 -0
- package/autorest/codegen/models/request_builder.py +9 -7
- package/autorest/codegen/serializers/__init__.py +7 -6
- package/autorest/codegen/serializers/builder_serializer.py +67 -30
- package/autorest/codegen/serializers/client_serializer.py +22 -8
- package/autorest/codegen/serializers/metadata_serializer.py +7 -1
- package/autorest/codegen/serializers/model_serializer.py +12 -13
- package/autorest/codegen/serializers/operation_groups_serializer.py +1 -0
- package/autorest/codegen/serializers/parameter_serializer.py +3 -3
- package/autorest/codegen/serializers/patch_serializer.py +2 -4
- package/autorest/codegen/serializers/sample_serializer.py +23 -14
- package/autorest/codegen/serializers/utils.py +6 -0
- package/autorest/codegen/templates/client.py.jinja2 +3 -12
- package/autorest/codegen/templates/config.py.jinja2 +2 -5
- package/autorest/codegen/templates/keywords.jinja2 +2 -2
- package/autorest/codegen/templates/metadata.json.jinja2 +2 -2
- package/autorest/codegen/templates/model_base.py.jinja2 +171 -130
- package/autorest/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +1 -0
- package/autorest/codegen/templates/request_builder.py.jinja2 +1 -1
- package/autorest/codegen/templates/serialization.py.jinja2 +286 -325
- package/autorest/jsonrpc/__init__.py +3 -1
- package/autorest/jsonrpc/localapi.py +3 -1
- package/autorest/jsonrpc/stdstream.py +1 -1
- package/autorest/m2r/__init__.py +2 -2
- package/autorest/multiapi/models/imports.py +34 -22
- package/autorest/multiapi/serializers/import_serializer.py +1 -1
- package/autorest/multiapi/templates/multiapi_config.py.jinja2 +2 -8
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +1 -1
- package/autorest/postprocess/__init__.py +5 -4
- package/autorest/preprocess/__init__.py +7 -1
- package/autorest/preprocess/helpers.py +14 -2
- package/autorest/preprocess/python_mappings.py +27 -0
- package/package.json +2 -2
- package/setup.py +3 -0
|
@@ -114,7 +114,9 @@ class AutorestAPI(ABC):
|
|
|
114
114
|
def message(self, channel: Channel, text: str) -> None:
|
|
115
115
|
"""Send a log message to autorest."""
|
|
116
116
|
|
|
117
|
-
def get_boolean_value(
|
|
117
|
+
def get_boolean_value(
|
|
118
|
+
self, key: str, default: Optional[bool] = None
|
|
119
|
+
) -> Optional[bool]:
|
|
118
120
|
"""Check if value is present on the line, and interpret it as bool if it was.
|
|
119
121
|
|
|
120
122
|
If value is not not on the line, return the "default".
|
|
@@ -17,7 +17,9 @@ class LocalAutorestAPI(AutorestAPI):
|
|
|
17
17
|
"""A local API that will write on local disk."""
|
|
18
18
|
|
|
19
19
|
def __init__(
|
|
20
|
-
self,
|
|
20
|
+
self,
|
|
21
|
+
reachable_files: Optional[List[str]] = None,
|
|
22
|
+
output_folder: str = "generated",
|
|
21
23
|
) -> None:
|
|
22
24
|
super().__init__()
|
|
23
25
|
if reachable_files is None:
|
|
@@ -28,7 +28,7 @@ def read_message(stream: BinaryIO = sys.stdin.buffer) -> str:
|
|
|
28
28
|
try:
|
|
29
29
|
bytes_size = int(order.split(b":")[1].strip())
|
|
30
30
|
except Exception as err:
|
|
31
|
-
raise ValueError(f"Was unable to read length from {order}") from err
|
|
31
|
+
raise ValueError(f"Was unable to read length from {order!r}") from err
|
|
32
32
|
# Double new line, so read another emptyline and ignore it
|
|
33
33
|
stream.readline()
|
|
34
34
|
|
package/autorest/m2r/__init__.py
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"""An autorest MD to RST plugin.
|
|
7
7
|
"""
|
|
8
8
|
import logging
|
|
9
|
-
from typing import Any, Dict, Set
|
|
9
|
+
from typing import Any, Dict, Set, Union
|
|
10
10
|
|
|
11
11
|
import m2r2
|
|
12
12
|
|
|
@@ -35,7 +35,7 @@ class M2R(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
35
35
|
self._convert_docstring_no_cycles(yaml_data, set())
|
|
36
36
|
|
|
37
37
|
def _convert_docstring_no_cycles(
|
|
38
|
-
self, yaml_data: Dict[str, Any], node_list: Set[int]
|
|
38
|
+
self, yaml_data: Union[Dict[str, Any], str], node_list: Set[int]
|
|
39
39
|
) -> None:
|
|
40
40
|
"""Walk the YAML tree to convert MD to RST."""
|
|
41
41
|
if id(yaml_data) in node_list:
|
|
@@ -25,30 +25,34 @@ class TypingSection(str, Enum):
|
|
|
25
25
|
class FileImport:
|
|
26
26
|
def __init__(
|
|
27
27
|
self,
|
|
28
|
-
imports:
|
|
29
|
-
TypingSection,
|
|
28
|
+
imports: Optional[
|
|
30
29
|
Dict[
|
|
31
|
-
|
|
30
|
+
TypingSection,
|
|
32
31
|
Dict[
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
str,
|
|
40
|
-
str,
|
|
41
|
-
],
|
|
42
|
-
Tuple[
|
|
43
|
-
str,
|
|
32
|
+
ImportType,
|
|
33
|
+
Dict[
|
|
34
|
+
str,
|
|
35
|
+
Set[
|
|
36
|
+
Optional[
|
|
37
|
+
Union[
|
|
44
38
|
str,
|
|
45
|
-
Tuple[
|
|
46
|
-
|
|
39
|
+
Tuple[
|
|
40
|
+
str,
|
|
41
|
+
str,
|
|
42
|
+
],
|
|
43
|
+
Tuple[
|
|
44
|
+
str,
|
|
45
|
+
Optional[str],
|
|
46
|
+
Tuple[
|
|
47
|
+
Tuple[Tuple[int, int], str, Optional[str]]
|
|
48
|
+
],
|
|
49
|
+
],
|
|
50
|
+
]
|
|
47
51
|
]
|
|
48
|
-
]
|
|
52
|
+
],
|
|
49
53
|
],
|
|
50
54
|
],
|
|
51
|
-
]
|
|
55
|
+
]
|
|
52
56
|
] = None,
|
|
53
57
|
) -> None:
|
|
54
58
|
# Basic implementation
|
|
@@ -72,7 +76,7 @@ class FileImport:
|
|
|
72
76
|
],
|
|
73
77
|
Tuple[
|
|
74
78
|
str,
|
|
75
|
-
str,
|
|
79
|
+
Optional[str],
|
|
76
80
|
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
77
81
|
],
|
|
78
82
|
]
|
|
@@ -95,7 +99,11 @@ class FileImport:
|
|
|
95
99
|
str,
|
|
96
100
|
str,
|
|
97
101
|
],
|
|
98
|
-
Tuple[
|
|
102
|
+
Tuple[
|
|
103
|
+
str,
|
|
104
|
+
Optional[str],
|
|
105
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
106
|
+
],
|
|
99
107
|
]
|
|
100
108
|
] = None,
|
|
101
109
|
typing_section: TypingSection = TypingSection.REGULAR,
|
|
@@ -107,7 +115,11 @@ class FileImport:
|
|
|
107
115
|
str,
|
|
108
116
|
str,
|
|
109
117
|
],
|
|
110
|
-
Tuple[
|
|
118
|
+
Tuple[
|
|
119
|
+
str,
|
|
120
|
+
Optional[str],
|
|
121
|
+
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
122
|
+
],
|
|
111
123
|
]
|
|
112
124
|
] = None
|
|
113
125
|
name_input = convert_list_to_tuple(name_import)
|
|
@@ -144,7 +156,7 @@ class FileImport:
|
|
|
144
156
|
],
|
|
145
157
|
Tuple[
|
|
146
158
|
str,
|
|
147
|
-
str,
|
|
159
|
+
Optional[str],
|
|
148
160
|
Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
|
|
149
161
|
],
|
|
150
162
|
]
|
|
@@ -55,7 +55,7 @@ def _serialize_package(
|
|
|
55
55
|
),
|
|
56
56
|
)
|
|
57
57
|
)
|
|
58
|
-
for submodule_name, alias, version_modules in versioned_modules:
|
|
58
|
+
for submodule_name, alias, version_modules in versioned_modules:
|
|
59
59
|
for n, (version, module_name, comment) in enumerate(version_modules):
|
|
60
60
|
buffer.append(
|
|
61
61
|
"{} sys.version_info >= {}:".format("if" if n == 0 else "elif", version)
|
|
@@ -11,7 +11,7 @@ def __init__(
|
|
|
11
11
|
{{ parameter.signature(async_mode) }}
|
|
12
12
|
{% endif %}
|
|
13
13
|
{% endfor %}
|
|
14
|
-
**kwargs
|
|
14
|
+
**kwargs: Any
|
|
15
15
|
){{" -> None" if async_mode else "" }}:{% endmacro %}
|
|
16
16
|
{% set version_import = ".._version" if async_mode else "._version" %}
|
|
17
17
|
{% set async_prefix = "Async" if async_mode else "" %}
|
|
@@ -43,9 +43,6 @@ class {{ code_model.client.name }}Configuration(Configuration):
|
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
45
|
{{ method_signature()|indent }}
|
|
46
|
-
{% if not async_mode %}
|
|
47
|
-
# type: (...) -> None
|
|
48
|
-
{% endif %}
|
|
49
46
|
{% for parameter in code_model.global_parameters.parameters %}
|
|
50
47
|
{% if parameter.required %}
|
|
51
48
|
if {{ parameter.name }} is None:
|
|
@@ -70,11 +67,8 @@ class {{ code_model.client.name }}Configuration(Configuration):
|
|
|
70
67
|
|
|
71
68
|
def _configure(
|
|
72
69
|
self,
|
|
73
|
-
**kwargs
|
|
70
|
+
**kwargs: Any
|
|
74
71
|
){{ " -> None" if async_mode else "" }}:
|
|
75
|
-
{% if not async_mode %}
|
|
76
|
-
# type: (...) -> None
|
|
77
|
-
{% endif %}
|
|
78
72
|
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
|
|
79
73
|
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
|
|
80
74
|
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
|
|
@@ -14,7 +14,7 @@ def __init__(
|
|
|
14
14
|
{% for parameter in code_model.global_parameters.service_client_specific_global_parameters %}
|
|
15
15
|
{{ parameter.signature(async_mode) }}
|
|
16
16
|
{% endfor %}
|
|
17
|
-
**kwargs
|
|
17
|
+
**kwargs: Any
|
|
18
18
|
){{" -> None" if async_mode else "" }}:{% endmacro %}
|
|
19
19
|
{# actual template starts here #}
|
|
20
20
|
{% set pipeline_client = "ARMPipelineClient" if azure_arm else "PipelineClient" %}
|
|
@@ -9,11 +9,12 @@ import os
|
|
|
9
9
|
import shutil
|
|
10
10
|
from venv import EnvBuilder
|
|
11
11
|
import black
|
|
12
|
+
from black.report import NothingChanged
|
|
12
13
|
from .venvtools import ExtendedEnvBuilder, python_run
|
|
13
14
|
|
|
14
15
|
from .. import Plugin, PluginAutorest
|
|
15
16
|
|
|
16
|
-
_BLACK_MODE = black.Mode()
|
|
17
|
+
_BLACK_MODE = black.Mode() # pyright: ignore [reportPrivateImportUsage]
|
|
17
18
|
_BLACK_MODE.line_length = 120
|
|
18
19
|
|
|
19
20
|
|
|
@@ -24,7 +25,7 @@ def format_file(file: Path, file_content: str) -> str:
|
|
|
24
25
|
file_content = black.format_file_contents(
|
|
25
26
|
file_content, fast=True, mode=_BLACK_MODE
|
|
26
27
|
)
|
|
27
|
-
except
|
|
28
|
+
except NothingChanged:
|
|
28
29
|
pass
|
|
29
30
|
return file_content
|
|
30
31
|
|
|
@@ -170,7 +171,7 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
170
171
|
added_objs.append(obj)
|
|
171
172
|
file_content = file_content.replace(
|
|
172
173
|
"try:\n from ._patch import __all__ as _patch_all\n "
|
|
173
|
-
"from ._patch import * #
|
|
174
|
+
"from ._patch import * # pylint: disable=unused-wildcard-import"
|
|
174
175
|
"\nexcept ImportError:\n _patch_all = []",
|
|
175
176
|
"",
|
|
176
177
|
)
|
|
@@ -178,7 +179,7 @@ class PostProcessPlugin(Plugin): # pylint: disable=abstract-method
|
|
|
178
179
|
"from ._patch import __all__ as _patch_all", ""
|
|
179
180
|
)
|
|
180
181
|
file_content = file_content.replace(
|
|
181
|
-
"from ._patch import * #
|
|
182
|
+
"from ._patch import * # pylint: disable=unused-wildcard-import\n",
|
|
182
183
|
"",
|
|
183
184
|
)
|
|
184
185
|
file_content = file_content.replace(
|
|
@@ -9,7 +9,11 @@ import copy
|
|
|
9
9
|
from typing import Callable, Dict, Any, List, Optional
|
|
10
10
|
|
|
11
11
|
from .._utils import to_snake_case
|
|
12
|
-
from .helpers import
|
|
12
|
+
from .helpers import (
|
|
13
|
+
pad_reserved_words,
|
|
14
|
+
add_redefined_builtin_info,
|
|
15
|
+
pad_builtin_namespaces,
|
|
16
|
+
)
|
|
13
17
|
from .python_mappings import PadType
|
|
14
18
|
|
|
15
19
|
from .. import YamlUpdatePlugin, YamlUpdatePluginAutorest
|
|
@@ -362,6 +366,8 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
|
|
|
362
366
|
for client in clients:
|
|
363
367
|
update_client(client)
|
|
364
368
|
self.update_operation_groups(yaml_data, client)
|
|
369
|
+
if yaml_data.get("namespace"):
|
|
370
|
+
yaml_data["namespace"] = pad_builtin_namespaces(yaml_data["namespace"])
|
|
365
371
|
|
|
366
372
|
|
|
367
373
|
class PreProcessPluginAutorest(YamlUpdatePluginAutorest, PreProcessPlugin):
|
|
@@ -3,9 +3,14 @@
|
|
|
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
|
|
7
6
|
import re
|
|
8
|
-
from
|
|
7
|
+
from typing import Any, Dict
|
|
8
|
+
from .python_mappings import (
|
|
9
|
+
PadType,
|
|
10
|
+
RESERVED_WORDS,
|
|
11
|
+
REDEFINED_BUILTINS,
|
|
12
|
+
BUILTIN_PACKAGES,
|
|
13
|
+
)
|
|
9
14
|
|
|
10
15
|
|
|
11
16
|
def pad_reserved_words(name: str, pad_type: PadType):
|
|
@@ -26,5 +31,12 @@ def add_redefined_builtin_info(name: str, yaml_data: Dict[str, Any]) -> None:
|
|
|
26
31
|
yaml_data["pylintDisable"] = "redefined-builtin"
|
|
27
32
|
|
|
28
33
|
|
|
34
|
+
def pad_builtin_namespaces(namespace: str) -> str:
|
|
35
|
+
items = namespace.split(".")
|
|
36
|
+
if items[0] in BUILTIN_PACKAGES:
|
|
37
|
+
items[0] = items[0] + "_"
|
|
38
|
+
return ".".join(items)
|
|
39
|
+
|
|
40
|
+
|
|
29
41
|
def pad_special_chars(name: str) -> str:
|
|
30
42
|
return re.sub(r"[^A-z0-9_]", "_", name)
|
|
@@ -174,3 +174,30 @@ REDEFINED_BUILTINS = [ # we don't pad, but we need to do lint ignores
|
|
|
174
174
|
"max",
|
|
175
175
|
"filter",
|
|
176
176
|
]
|
|
177
|
+
|
|
178
|
+
BUILTIN_PACKAGES = [
|
|
179
|
+
"array",
|
|
180
|
+
"atexit",
|
|
181
|
+
"binascii",
|
|
182
|
+
"builtins",
|
|
183
|
+
"cmath",
|
|
184
|
+
"errno",
|
|
185
|
+
"faulthandler",
|
|
186
|
+
"fcntl",
|
|
187
|
+
"gc",
|
|
188
|
+
"grp",
|
|
189
|
+
"itertools",
|
|
190
|
+
"marshal",
|
|
191
|
+
"math",
|
|
192
|
+
"posix",
|
|
193
|
+
"pwd",
|
|
194
|
+
"pyexpat",
|
|
195
|
+
"select",
|
|
196
|
+
"spwd",
|
|
197
|
+
"sys",
|
|
198
|
+
"syslog",
|
|
199
|
+
"time",
|
|
200
|
+
"unicodedata",
|
|
201
|
+
"xxsubtype",
|
|
202
|
+
"zlib",
|
|
203
|
+
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autorest/python",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.7",
|
|
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.
|
|
24
|
+
"@microsoft.azure/autorest.testserver": "^3.3.45",
|
|
25
25
|
"typescript": "^4.8.3"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
package/setup.py
CHANGED
|
@@ -38,6 +38,9 @@ setup(
|
|
|
38
38
|
'Programming Language :: Python :: 3',
|
|
39
39
|
'Programming Language :: Python :: 3.7',
|
|
40
40
|
'Programming Language :: Python :: 3.8',
|
|
41
|
+
'Programming Language :: Python :: 3.9',
|
|
42
|
+
'Programming Language :: Python :: 3.10',
|
|
43
|
+
'Programming Language :: Python :: 3.11',
|
|
41
44
|
'License :: OSI Approved :: MIT License',
|
|
42
45
|
],
|
|
43
46
|
packages=find_packages(exclude=[
|