@autorest/python 5.15.0 → 5.16.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 +20 -0
- package/autorest/__init__.py +1 -2
- package/autorest/black/__init__.py +12 -5
- package/autorest/codegen/__init__.py +145 -73
- package/autorest/codegen/models/__init__.py +29 -18
- package/autorest/codegen/models/base_builder.py +48 -11
- package/autorest/codegen/models/base_model.py +6 -4
- package/autorest/codegen/models/base_schema.py +19 -18
- package/autorest/codegen/models/client.py +65 -21
- package/autorest/codegen/models/code_model.py +107 -61
- package/autorest/codegen/models/constant_schema.py +25 -13
- package/autorest/codegen/models/credential_model.py +23 -15
- package/autorest/codegen/models/credential_schema.py +18 -14
- package/autorest/codegen/models/credential_schema_policy.py +11 -15
- package/autorest/codegen/models/dictionary_schema.py +20 -17
- package/autorest/codegen/models/enum_schema.py +35 -25
- package/autorest/codegen/models/imports.py +70 -41
- package/autorest/codegen/models/list_schema.py +25 -13
- package/autorest/codegen/models/lro_operation.py +58 -22
- package/autorest/codegen/models/lro_paging_operation.py +2 -3
- package/autorest/codegen/models/object_schema.py +99 -49
- package/autorest/codegen/models/operation.py +236 -117
- package/autorest/codegen/models/operation_group.py +64 -34
- package/autorest/codegen/models/paging_operation.py +45 -18
- package/autorest/codegen/models/parameter.py +151 -83
- package/autorest/codegen/models/parameter_list.py +183 -162
- package/autorest/codegen/models/primitive_schemas.py +84 -55
- package/autorest/codegen/models/property.py +44 -26
- package/autorest/codegen/models/request_builder.py +65 -30
- package/autorest/codegen/models/request_builder_parameter.py +47 -23
- package/autorest/codegen/models/request_builder_parameter_list.py +77 -108
- package/autorest/codegen/models/schema_request.py +16 -6
- package/autorest/codegen/models/schema_response.py +18 -13
- package/autorest/codegen/models/utils.py +5 -2
- package/autorest/codegen/serializers/__init__.py +182 -91
- package/autorest/codegen/serializers/builder_serializer.py +667 -331
- package/autorest/codegen/serializers/client_serializer.py +98 -37
- package/autorest/codegen/serializers/general_serializer.py +61 -26
- package/autorest/codegen/serializers/import_serializer.py +93 -31
- package/autorest/codegen/serializers/metadata_serializer.py +73 -24
- package/autorest/codegen/serializers/model_base_serializer.py +35 -15
- package/autorest/codegen/serializers/model_generic_serializer.py +1 -4
- package/autorest/codegen/serializers/model_init_serializer.py +5 -1
- package/autorest/codegen/serializers/model_python3_serializer.py +7 -6
- package/autorest/codegen/serializers/operation_groups_serializer.py +20 -9
- package/autorest/codegen/serializers/operations_init_serializer.py +23 -11
- package/autorest/codegen/serializers/patch_serializer.py +4 -1
- package/autorest/codegen/serializers/{rest_serializer.py → request_builders_serializer.py} +29 -12
- package/autorest/codegen/serializers/utils.py +35 -21
- package/autorest/codegen/templates/init.py.jinja2 +2 -2
- package/autorest/codegen/templates/lro_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +5 -7
- package/autorest/codegen/templates/metadata.json.jinja2 +7 -6
- package/autorest/codegen/templates/operation.py.jinja2 +7 -9
- package/autorest/codegen/templates/operation_group.py.jinja2 +2 -8
- package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -1
- package/autorest/codegen/templates/paging_operation.py.jinja2 +7 -8
- package/autorest/codegen/templates/request_builder.py.jinja2 +18 -11
- package/autorest/jsonrpc/__init__.py +7 -12
- package/autorest/jsonrpc/localapi.py +4 -3
- package/autorest/jsonrpc/server.py +13 -6
- package/autorest/jsonrpc/stdstream.py +13 -6
- package/autorest/m2r/__init__.py +5 -8
- 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 +18 -23
- package/autorest/multiapi/serializers/import_serializer.py +47 -17
- package/autorest/multiapi/serializers/multiapi_serializer.py +17 -17
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/multiapi/utils.py +3 -3
- package/autorest/namer/__init__.py +2 -4
- package/autorest/namer/name_converter.py +200 -103
- package/autorest/namer/python_mappings.py +10 -22
- package/package.json +2 -2
- package/run-python3.js +2 -3
- package/venvtools.py +1 -1
- package/autorest/codegen/models/rest.py +0 -42
|
@@ -7,21 +7,34 @@ from copy import deepcopy
|
|
|
7
7
|
from typing import Dict, Set, Optional, List
|
|
8
8
|
from ..models import ImportType, FileImport, TypingSection
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
def _serialize_package(
|
|
12
|
+
package_name: str, module_list: Set[Optional[str]], delimiter: str
|
|
13
|
+
) -> str:
|
|
11
14
|
buffer = []
|
|
12
15
|
if None in module_list:
|
|
13
16
|
buffer.append(f"import {package_name}")
|
|
14
17
|
if module_list != {None}:
|
|
15
18
|
buffer.append(
|
|
16
19
|
"from {} import {}".format(
|
|
17
|
-
package_name,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
package_name,
|
|
21
|
+
", ".join(
|
|
22
|
+
sorted(
|
|
23
|
+
[
|
|
24
|
+
mod if isinstance(mod, str) else f"{mod[0]} as {mod[1]}"
|
|
25
|
+
for mod in module_list
|
|
26
|
+
if mod is not None
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
),
|
|
20
30
|
)
|
|
21
31
|
)
|
|
22
32
|
return delimiter.join(buffer)
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
|
|
35
|
+
def _serialize_type(
|
|
36
|
+
import_type_dict: Dict[str, Set[Optional[str]]], delimiter: str
|
|
37
|
+
) -> str:
|
|
25
38
|
"""Serialize a given import type."""
|
|
26
39
|
import_list = []
|
|
27
40
|
for package_name in sorted(list(import_type_dict.keys())):
|
|
@@ -29,7 +42,10 @@ def _serialize_type(import_type_dict: Dict[str, Set[Optional[str]]], delimiter:
|
|
|
29
42
|
import_list.append(_serialize_package(package_name, module_list, delimiter))
|
|
30
43
|
return delimiter.join(import_list)
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
|
|
46
|
+
def _get_import_clauses(
|
|
47
|
+
imports: Dict[ImportType, Dict[str, Set[Optional[str]]]], delimiter: str
|
|
48
|
+
) -> List[str]:
|
|
33
49
|
import_clause = []
|
|
34
50
|
for import_type in ImportType:
|
|
35
51
|
if import_type in imports:
|
|
@@ -44,33 +60,44 @@ class FileImportSerializer:
|
|
|
44
60
|
|
|
45
61
|
def _switch_typing_section_key(self, new_key: TypingSection):
|
|
46
62
|
switched_dictionary = {}
|
|
47
|
-
switched_dictionary[new_key] = self._file_import.imports[
|
|
63
|
+
switched_dictionary[new_key] = self._file_import.imports[
|
|
64
|
+
TypingSection.CONDITIONAL
|
|
65
|
+
]
|
|
48
66
|
return switched_dictionary
|
|
49
67
|
|
|
50
|
-
def _get_imports_dict(
|
|
68
|
+
def _get_imports_dict(
|
|
69
|
+
self, baseline_typing_section: TypingSection, add_conditional_typing: bool
|
|
70
|
+
):
|
|
51
71
|
# If this is a python 3 file, our regular imports include the CONDITIONAL category
|
|
52
72
|
# If this is not a python 3 file, our typing imports include the CONDITIONAL category
|
|
53
73
|
file_import_copy = deepcopy(self._file_import)
|
|
54
|
-
if add_conditional_typing and self._file_import.imports.get(
|
|
74
|
+
if add_conditional_typing and self._file_import.imports.get(
|
|
75
|
+
TypingSection.CONDITIONAL
|
|
76
|
+
):
|
|
55
77
|
# we switch the TypingSection key for the CONDITIONAL typing imports so we can merge
|
|
56
78
|
# the imports together
|
|
57
|
-
switched_imports_dictionary = self._switch_typing_section_key(
|
|
79
|
+
switched_imports_dictionary = self._switch_typing_section_key(
|
|
80
|
+
baseline_typing_section
|
|
81
|
+
)
|
|
58
82
|
switched_imports = FileImport(switched_imports_dictionary)
|
|
59
83
|
file_import_copy.merge(switched_imports)
|
|
60
84
|
return file_import_copy.imports.get(baseline_typing_section, {})
|
|
61
85
|
|
|
62
86
|
def _add_type_checking_import(self):
|
|
63
|
-
if (
|
|
64
|
-
self.
|
|
65
|
-
|
|
87
|
+
if self._file_import.imports.get(TypingSection.TYPING) or (
|
|
88
|
+
not self.is_python3_file
|
|
89
|
+
and self._file_import.imports.get(TypingSection.CONDITIONAL)
|
|
66
90
|
):
|
|
67
|
-
self._file_import.add_submodule_import(
|
|
91
|
+
self._file_import.add_submodule_import(
|
|
92
|
+
"typing", "TYPE_CHECKING", ImportType.STDLIB
|
|
93
|
+
)
|
|
68
94
|
|
|
69
95
|
def __str__(self) -> str:
|
|
70
96
|
self._add_type_checking_import()
|
|
71
97
|
regular_imports = ""
|
|
72
98
|
regular_imports_dict = self._get_imports_dict(
|
|
73
|
-
baseline_typing_section=TypingSection.REGULAR,
|
|
99
|
+
baseline_typing_section=TypingSection.REGULAR,
|
|
100
|
+
add_conditional_typing=self.is_python3_file,
|
|
74
101
|
)
|
|
75
102
|
|
|
76
103
|
if regular_imports_dict:
|
|
@@ -80,10 +107,13 @@ class FileImportSerializer:
|
|
|
80
107
|
|
|
81
108
|
typing_imports = ""
|
|
82
109
|
typing_imports_dict = self._get_imports_dict(
|
|
83
|
-
baseline_typing_section=TypingSection.TYPING,
|
|
110
|
+
baseline_typing_section=TypingSection.TYPING,
|
|
111
|
+
add_conditional_typing=not self.is_python3_file,
|
|
84
112
|
)
|
|
85
113
|
if typing_imports_dict:
|
|
86
114
|
typing_imports += "\n\nif TYPE_CHECKING:\n # pylint: disable=unused-import,ungrouped-imports\n "
|
|
87
|
-
typing_imports += "\n\n ".join(
|
|
115
|
+
typing_imports += "\n\n ".join(
|
|
116
|
+
_get_import_clauses(typing_imports_dict, "\n ")
|
|
117
|
+
)
|
|
88
118
|
|
|
89
119
|
return regular_imports + typing_imports
|
|
@@ -12,7 +12,11 @@ from ...jsonrpc import AutorestAPI
|
|
|
12
12
|
|
|
13
13
|
class MultiAPISerializer:
|
|
14
14
|
def __init__(
|
|
15
|
-
self,
|
|
15
|
+
self,
|
|
16
|
+
conf: Dict[str, Any],
|
|
17
|
+
async_mode: bool,
|
|
18
|
+
autorestapi: AutorestAPI,
|
|
19
|
+
service_client_filename: str,
|
|
16
20
|
):
|
|
17
21
|
self.conf = conf
|
|
18
22
|
self.async_mode = async_mode
|
|
@@ -33,64 +37,60 @@ class MultiAPISerializer:
|
|
|
33
37
|
return Path(filename)
|
|
34
38
|
|
|
35
39
|
def serialize(self):
|
|
36
|
-
self._autorestapi.write_file(
|
|
40
|
+
self._autorestapi.write_file(
|
|
41
|
+
self._get_file_path("__init__.py"), self.serialize_multiapi_init()
|
|
42
|
+
)
|
|
37
43
|
|
|
38
44
|
service_client_filename_with_py_extension = self.service_client_filename + ".py"
|
|
39
45
|
self._autorestapi.write_file(
|
|
40
46
|
self._get_file_path(service_client_filename_with_py_extension),
|
|
41
|
-
self.serialize_multiapi_client()
|
|
47
|
+
self.serialize_multiapi_client(),
|
|
42
48
|
)
|
|
43
49
|
|
|
44
50
|
configuration_filename = "_configuration.py"
|
|
45
51
|
self._autorestapi.write_file(
|
|
46
52
|
self._get_file_path(configuration_filename),
|
|
47
|
-
self.serialize_multiapi_config()
|
|
53
|
+
self.serialize_multiapi_config(),
|
|
48
54
|
)
|
|
49
55
|
|
|
50
56
|
operation_mixins_filename = "_operations_mixin.py"
|
|
51
57
|
if self.conf["mixin_operations"]:
|
|
52
58
|
self._autorestapi.write_file(
|
|
53
59
|
self._get_file_path(operation_mixins_filename),
|
|
54
|
-
self.serialize_multiapi_operation_mixins()
|
|
60
|
+
self.serialize_multiapi_operation_mixins(),
|
|
55
61
|
)
|
|
56
62
|
|
|
57
63
|
if self._autorestapi.read_file("_version.py"):
|
|
58
64
|
self._autorestapi.write_file(
|
|
59
|
-
"_version.py",
|
|
60
|
-
self._autorestapi.read_file("_version.py")
|
|
65
|
+
"_version.py", self._autorestapi.read_file("_version.py")
|
|
61
66
|
)
|
|
62
67
|
elif self._autorestapi.read_file("version.py"):
|
|
63
68
|
self._autorestapi.write_file(
|
|
64
|
-
"_version.py",
|
|
65
|
-
self._autorestapi.read_file("version.py")
|
|
69
|
+
"_version.py", self._autorestapi.read_file("version.py")
|
|
66
70
|
)
|
|
67
71
|
else:
|
|
68
72
|
self._autorestapi.write_file(
|
|
69
|
-
Path("_version.py"),
|
|
70
|
-
self.serialize_multiapi_version()
|
|
73
|
+
Path("_version.py"), self.serialize_multiapi_version()
|
|
71
74
|
)
|
|
72
75
|
|
|
73
76
|
# don't erase patch file
|
|
74
77
|
if self._autorestapi.read_file("_patch.py"):
|
|
75
78
|
self._autorestapi.write_file(
|
|
76
|
-
"_patch.py",
|
|
77
|
-
self._autorestapi.read_file("_patch.py")
|
|
79
|
+
"_patch.py", self._autorestapi.read_file("_patch.py")
|
|
78
80
|
)
|
|
79
81
|
|
|
80
82
|
self._autorestapi.write_file(
|
|
81
|
-
Path("models.py"),
|
|
82
|
-
self.serialize_multiapi_models()
|
|
83
|
+
Path("models.py"), self.serialize_multiapi_models()
|
|
83
84
|
)
|
|
84
85
|
|
|
85
86
|
self._autorestapi.write_file(Path("py.typed"), "# Marker file for PEP 561.")
|
|
86
87
|
|
|
87
|
-
|
|
88
88
|
def serialize_multiapi_init(self) -> str:
|
|
89
89
|
template = self.env.get_template("multiapi_init.py.jinja2")
|
|
90
90
|
return template.render(
|
|
91
91
|
service_client_filename=self.service_client_filename,
|
|
92
92
|
client_name=self.conf["client_name"],
|
|
93
|
-
async_mode=self.async_mode
|
|
93
|
+
async_mode=self.async_mode,
|
|
94
94
|
)
|
|
95
95
|
|
|
96
96
|
def serialize_multiapi_client(self) -> str:
|
|
@@ -34,5 +34,5 @@ class {{ code_model.service_client.name }}OperationsMixin(object):
|
|
|
34
34
|
mixin_instance._serialize.client_side_validation = False
|
|
35
35
|
{% endif %}
|
|
36
36
|
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
|
|
37
|
-
return {{ "await " if mixin_operation.coroutine(async_mode) }}mixin_instance.{{ mixin_operation.name }}({{ mixin_operation.call }}
|
|
37
|
+
return {{ "await " if mixin_operation.coroutine(async_mode) }}mixin_instance.{{ mixin_operation.name }}({{ mixin_operation.call(async_mode) }})
|
|
38
38
|
{% endfor %}
|
|
@@ -12,14 +12,14 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
12
12
|
def _sync_or_async(async_mode: bool) -> str:
|
|
13
13
|
return "async" if async_mode else "sync"
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
def _get_default_api_version_from_list(
|
|
16
17
|
mod_to_api_version: Dict[str, str],
|
|
17
18
|
api_versions_list: List[str],
|
|
18
19
|
preview_mode: bool,
|
|
19
|
-
user_specified_default_api: Optional[str]
|
|
20
|
+
user_specified_default_api: Optional[str],
|
|
20
21
|
) -> str:
|
|
21
|
-
"""Get the floating latest, from a random list of API versions.
|
|
22
|
-
"""
|
|
22
|
+
"""Get the floating latest, from a random list of API versions."""
|
|
23
23
|
|
|
24
24
|
# I need user_specified_default_api to be v2019_06_07_preview shaped if it exists, let's be smart
|
|
25
25
|
# and change it automatically so I can take both syntax as input
|
|
@@ -16,10 +16,8 @@ _LOGGER = logging.getLogger(__name__)
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class Namer(YamlUpdatePlugin):
|
|
19
|
-
"""Add Python naming information.
|
|
20
|
-
"""
|
|
19
|
+
"""Add Python naming information."""
|
|
21
20
|
|
|
22
21
|
def update_yaml(self, yaml_data: Dict[str, Any]) -> None:
|
|
23
|
-
"""Convert in place the YAML str.
|
|
24
|
-
"""
|
|
22
|
+
"""Convert in place the YAML str."""
|
|
25
23
|
NameConverter.convert_yaml_names(yaml_data)
|