@autorest/python 6.32.3 → 6.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autorest/m2r.py +1 -2
- package/autorest/m4reformatter/__init__.py +1 -2
- package/autorest/multiapi/models/imports.py +7 -2
- package/autorest/multiapi/serializers/__init__.py +5 -1
- package/autorest/multiapi/templates/multiapi_operations_mixin.py.jinja2 +1 -1
- package/autorest/multiapi/templates/multiapi_service_client.py.jinja2 +13 -2
- package/autorest/multiapi/templates/multiapi_utils_init.py.jinja2 +10 -0
- package/autorest/preprocess.py +1 -2
- package/generator/build/lib/pygen/codegen/models/client.py +39 -2
- package/generator/build/lib/pygen/codegen/models/code_model.py +22 -11
- package/generator/build/lib/pygen/codegen/models/enum_type.py +2 -2
- package/generator/build/lib/pygen/codegen/models/imports.py +13 -9
- package/generator/build/lib/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/build/lib/pygen/codegen/models/model_type.py +4 -3
- package/generator/build/lib/pygen/codegen/models/operation.py +10 -3
- package/generator/build/lib/pygen/codegen/models/operation_group.py +27 -31
- package/generator/build/lib/pygen/codegen/models/paging_operation.py +3 -1
- package/generator/build/lib/pygen/codegen/models/parameter.py +4 -1
- package/generator/build/lib/pygen/codegen/models/primitive_types.py +2 -2
- package/generator/build/lib/pygen/codegen/models/property.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/__init__.py +31 -29
- package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +1 -1
- package/generator/build/lib/pygen/codegen/serializers/client_serializer.py +32 -6
- package/generator/build/lib/pygen/codegen/serializers/general_serializer.py +57 -35
- package/generator/build/lib/pygen/codegen/serializers/model_serializer.py +4 -3
- package/generator/build/lib/pygen/codegen/serializers/parameter_serializer.py +6 -1
- package/generator/build/lib/pygen/codegen/serializers/sample_serializer.py +2 -2
- package/generator/build/lib/pygen/codegen/templates/client.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/config.py.jinja2 +2 -8
- package/generator/build/lib/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/build/lib/pygen/codegen/templates/operation_group.py.jinja2 +3 -3
- package/generator/build/lib/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +12 -11
- package/generator/build/lib/pygen/codegen/templates/{vendor.py.jinja2 → utils.py.jinja2} +11 -12
- package/generator/component-detection-pip-report.json +4 -5
- package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
- package/generator/pygen/codegen/models/client.py +39 -2
- package/generator/pygen/codegen/models/code_model.py +22 -11
- package/generator/pygen/codegen/models/enum_type.py +2 -2
- package/generator/pygen/codegen/models/imports.py +13 -9
- package/generator/pygen/codegen/models/lro_operation.py +1 -1
- package/generator/pygen/codegen/models/model_type.py +4 -3
- package/generator/pygen/codegen/models/operation.py +10 -3
- package/generator/pygen/codegen/models/operation_group.py +27 -31
- package/generator/pygen/codegen/models/paging_operation.py +3 -1
- package/generator/pygen/codegen/models/parameter.py +4 -1
- package/generator/pygen/codegen/models/primitive_types.py +2 -2
- package/generator/pygen/codegen/models/property.py +1 -1
- package/generator/pygen/codegen/serializers/__init__.py +31 -29
- package/generator/pygen/codegen/serializers/builder_serializer.py +1 -1
- package/generator/pygen/codegen/serializers/client_serializer.py +32 -6
- package/generator/pygen/codegen/serializers/general_serializer.py +57 -35
- package/generator/pygen/codegen/serializers/model_serializer.py +4 -3
- package/generator/pygen/codegen/serializers/parameter_serializer.py +6 -1
- package/generator/pygen/codegen/serializers/sample_serializer.py +2 -2
- package/generator/pygen/codegen/templates/client.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/config.py.jinja2 +2 -8
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +1 -1
- package/generator/pygen/codegen/templates/operation_group.py.jinja2 +3 -3
- package/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +12 -11
- package/generator/pygen/codegen/templates/{vendor.py.jinja2 → utils.py.jinja2} +11 -12
- package/generator/pygen.egg-info/SOURCES.txt +1 -1
- package/package.json +2 -2
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
|
@@ -3,10 +3,10 @@
|
|
|
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 List
|
|
6
|
+
from typing import List, cast
|
|
7
7
|
|
|
8
8
|
from . import utils
|
|
9
|
-
from ..models import Client, ParameterMethodLocation
|
|
9
|
+
from ..models import Client, ParameterMethodLocation, Parameter, ParameterLocation
|
|
10
10
|
from .parameter_serializer import ParameterSerializer, PopKwargType
|
|
11
11
|
from ...utils import build_policies
|
|
12
12
|
|
|
@@ -77,17 +77,40 @@ class ClientSerializer:
|
|
|
77
77
|
retval.append('"""')
|
|
78
78
|
return retval
|
|
79
79
|
|
|
80
|
-
def initialize_config(self) -> str:
|
|
80
|
+
def initialize_config(self) -> List[str]:
|
|
81
|
+
retval = []
|
|
82
|
+
additional_signatures = []
|
|
83
|
+
if self.client.need_cloud_setting:
|
|
84
|
+
additional_signatures.append("credential_scopes=credential_scopes")
|
|
85
|
+
endpoint_parameter = cast(Parameter, self.client.endpoint_parameter)
|
|
86
|
+
retval.extend(
|
|
87
|
+
[
|
|
88
|
+
'_cloud = kwargs.pop("cloud_setting", None) or settings.current.azure_cloud # type: ignore',
|
|
89
|
+
"_endpoints = get_arm_endpoints(_cloud)",
|
|
90
|
+
f"if not {endpoint_parameter.client_name}:",
|
|
91
|
+
f' {endpoint_parameter.client_name} = _endpoints["resource_manager"]',
|
|
92
|
+
'credential_scopes = kwargs.pop("credential_scopes", _endpoints["credential_scopes"])',
|
|
93
|
+
]
|
|
94
|
+
)
|
|
81
95
|
config_name = f"{self.client.name}Configuration"
|
|
82
96
|
config_call = ", ".join(
|
|
83
97
|
[
|
|
84
|
-
|
|
98
|
+
(
|
|
99
|
+
f"{p.client_name}="
|
|
100
|
+
+ (
|
|
101
|
+
f"cast(str, {p.client_name})"
|
|
102
|
+
if self.client.need_cloud_setting and p.location == ParameterLocation.ENDPOINT_PATH
|
|
103
|
+
else p.client_name
|
|
104
|
+
)
|
|
105
|
+
)
|
|
85
106
|
for p in self.client.config.parameters.method
|
|
86
107
|
if p.method_location != ParameterMethodLocation.KWARG
|
|
87
108
|
]
|
|
109
|
+
+ additional_signatures
|
|
88
110
|
+ ["**kwargs"]
|
|
89
111
|
)
|
|
90
|
-
|
|
112
|
+
retval.append(f"self._config = {config_name}({config_call})")
|
|
113
|
+
return retval
|
|
91
114
|
|
|
92
115
|
@property
|
|
93
116
|
def host_variable_name(self) -> str:
|
|
@@ -104,8 +127,11 @@ class ClientSerializer:
|
|
|
104
127
|
result = []
|
|
105
128
|
pipeline_client_name = self.client.pipeline_class(async_mode)
|
|
106
129
|
endpoint_name = "base_url" if self.client.code_model.is_azure_flavor else "endpoint"
|
|
130
|
+
host_variable_name = (
|
|
131
|
+
f"cast(str, {self.host_variable_name})" if self.client.need_cloud_setting else self.host_variable_name
|
|
132
|
+
)
|
|
107
133
|
params = {
|
|
108
|
-
endpoint_name:
|
|
134
|
+
endpoint_name: host_variable_name,
|
|
109
135
|
"policies": "_policies",
|
|
110
136
|
}
|
|
111
137
|
if not self.client.code_model.is_legacy and self.client.request_id_header_name:
|
|
@@ -16,13 +16,29 @@ from ..models.utils import NamespaceType
|
|
|
16
16
|
from .client_serializer import ClientSerializer, ConfigSerializer
|
|
17
17
|
from .base_serializer import BaseSerializer
|
|
18
18
|
|
|
19
|
+
VERSION_MAP = {
|
|
20
|
+
"msrest": "0.7.1",
|
|
21
|
+
"isodate": "0.6.1",
|
|
22
|
+
"azure-mgmt-core": "1.5.0",
|
|
23
|
+
"azure-core": "1.30.0",
|
|
24
|
+
"typing-extensions": "4.6.0",
|
|
25
|
+
"corehttp": "1.0.0b6",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
MIN_PYTHON_VERSION = "3.9"
|
|
29
|
+
MAX_PYTHON_VERSION = "3.12"
|
|
30
|
+
|
|
19
31
|
|
|
20
32
|
class GeneralSerializer(BaseSerializer):
|
|
21
33
|
"""General serializer for SDK root level files"""
|
|
22
34
|
|
|
23
35
|
def serialize_setup_file(self) -> str:
|
|
24
36
|
template = self.env.get_template("packaging_templates/setup.py.jinja2")
|
|
25
|
-
params = {
|
|
37
|
+
params = {
|
|
38
|
+
"VERSION_MAP": VERSION_MAP,
|
|
39
|
+
"MIN_PYTHON_VERSION": MIN_PYTHON_VERSION,
|
|
40
|
+
"MAX_PYTHON_VERSION": MAX_PYTHON_VERSION,
|
|
41
|
+
}
|
|
26
42
|
params.update(self.code_model.options)
|
|
27
43
|
return template.render(code_model=self.code_model, **params)
|
|
28
44
|
|
|
@@ -48,6 +64,9 @@ class GeneralSerializer(BaseSerializer):
|
|
|
48
64
|
"pkgutil_names": [".".join(package_parts[: i + 1]) for i in range(len(package_parts))],
|
|
49
65
|
"init_names": ["/".join(package_parts[: i + 1]) + "/__init__.py" for i in range(len(package_parts))],
|
|
50
66
|
"client_name": self.code_model.clients[0].name,
|
|
67
|
+
"VERSION_MAP": VERSION_MAP,
|
|
68
|
+
"MIN_PYTHON_VERSION": MIN_PYTHON_VERSION,
|
|
69
|
+
"MAX_PYTHON_VERSION": MAX_PYTHON_VERSION,
|
|
51
70
|
}
|
|
52
71
|
params.update(self.code_model.options)
|
|
53
72
|
params.update(kwargs)
|
|
@@ -88,44 +107,33 @@ class GeneralSerializer(BaseSerializer):
|
|
|
88
107
|
serialize_namespace=self.serialize_namespace,
|
|
89
108
|
)
|
|
90
109
|
|
|
91
|
-
def
|
|
92
|
-
template = self.env.get_template("
|
|
110
|
+
def need_utils_utils_file(self) -> str:
|
|
111
|
+
template = self.env.get_template("utils.py.jinja2")
|
|
93
112
|
clients = self.code_model.get_clients(self.client_namespace)
|
|
94
113
|
|
|
95
114
|
# configure imports
|
|
96
115
|
file_import = FileImport(self.code_model)
|
|
97
|
-
if self.code_model.
|
|
116
|
+
if self.code_model.need_utils_mixin:
|
|
98
117
|
file_import.add_submodule_import(
|
|
99
118
|
"abc",
|
|
100
119
|
"ABC",
|
|
101
120
|
ImportType.STDLIB,
|
|
102
121
|
)
|
|
103
|
-
file_import.add_submodule_import(
|
|
104
|
-
"" if self.code_model.is_azure_flavor else "runtime",
|
|
105
|
-
f"{'Async' if self.async_mode else ''}PipelineClient",
|
|
106
|
-
ImportType.SDKCORE,
|
|
107
|
-
TypingSection.TYPING,
|
|
108
|
-
)
|
|
109
122
|
file_import.add_msrest_import(
|
|
110
|
-
serialize_namespace=self.serialize_namespace,
|
|
123
|
+
serialize_namespace=f"{self.serialize_namespace}._utils",
|
|
111
124
|
msrest_import_type=MsrestImportType.SerializerDeserializer,
|
|
112
125
|
typing_section=TypingSection.TYPING,
|
|
113
126
|
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"._configuration",
|
|
118
|
-
f"{client.name}Configuration",
|
|
119
|
-
ImportType.LOCAL,
|
|
120
|
-
)
|
|
121
|
-
if self.code_model.need_vendored_etag(self.client_namespace):
|
|
127
|
+
file_import.add_submodule_import("typing", "TypeVar", ImportType.STDLIB)
|
|
128
|
+
file_import.add_submodule_import("typing", "Generic", ImportType.STDLIB)
|
|
129
|
+
if self.code_model.need_utils_etag(self.client_namespace):
|
|
122
130
|
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
|
|
123
131
|
file_import.add_submodule_import(
|
|
124
132
|
"",
|
|
125
133
|
"MatchConditions",
|
|
126
134
|
ImportType.SDKCORE,
|
|
127
135
|
)
|
|
128
|
-
if self.code_model.
|
|
136
|
+
if self.code_model.need_utils_form_data(self.async_mode, self.client_namespace):
|
|
129
137
|
file_import.add_submodule_import("typing", "IO", ImportType.STDLIB)
|
|
130
138
|
file_import.add_submodule_import("typing", "Tuple", ImportType.STDLIB)
|
|
131
139
|
file_import.add_submodule_import("typing", "Union", ImportType.STDLIB)
|
|
@@ -135,12 +143,12 @@ class GeneralSerializer(BaseSerializer):
|
|
|
135
143
|
file_import.add_submodule_import("typing", "Any", ImportType.STDLIB)
|
|
136
144
|
file_import.add_submodule_import("typing", "List", ImportType.STDLIB)
|
|
137
145
|
file_import.add_submodule_import(
|
|
138
|
-
".
|
|
146
|
+
".._utils.model_base",
|
|
139
147
|
"SdkJSONEncoder",
|
|
140
148
|
ImportType.LOCAL,
|
|
141
149
|
)
|
|
142
150
|
file_import.add_submodule_import(
|
|
143
|
-
".
|
|
151
|
+
".._utils.model_base",
|
|
144
152
|
"Model",
|
|
145
153
|
ImportType.LOCAL,
|
|
146
154
|
)
|
|
@@ -206,19 +214,33 @@ class GeneralSerializer(BaseSerializer):
|
|
|
206
214
|
if not enum.internal
|
|
207
215
|
}
|
|
208
216
|
)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
for client in self.code_model.clients:
|
|
218
|
+
for operation_group in client.operation_groups:
|
|
219
|
+
for operation in operation_group.operations:
|
|
220
|
+
if operation.name.startswith("_"):
|
|
221
|
+
continue
|
|
222
|
+
cross_langauge_def_dict.update(
|
|
223
|
+
{
|
|
224
|
+
f"{self.code_model.namespace}."
|
|
225
|
+
+ (
|
|
226
|
+
f"{client.name}."
|
|
227
|
+
if operation_group.is_mixin
|
|
228
|
+
else f"operations.{operation_group.class_name}."
|
|
229
|
+
)
|
|
230
|
+
+ f"{operation.name}": operation.cross_language_definition_id
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
cross_langauge_def_dict.update(
|
|
234
|
+
{
|
|
235
|
+
f"{self.code_model.namespace}.aio."
|
|
236
|
+
+ (
|
|
237
|
+
f"{client.name}."
|
|
238
|
+
if operation_group.is_mixin
|
|
239
|
+
else f"operations.{operation_group.class_name}."
|
|
240
|
+
)
|
|
241
|
+
+ f"{operation.name}": operation.cross_language_definition_id
|
|
242
|
+
}
|
|
243
|
+
)
|
|
222
244
|
return json.dumps(
|
|
223
245
|
{
|
|
224
246
|
"CrossLanguagePackageId": self.code_model.cross_language_package_id,
|
|
@@ -230,10 +230,11 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
230
230
|
file_import = FileImport(self.code_model)
|
|
231
231
|
if any(not m.parents for m in self.models):
|
|
232
232
|
file_import.add_submodule_import(
|
|
233
|
-
self.code_model.get_relative_import_path(self.serialize_namespace),
|
|
234
|
-
"
|
|
233
|
+
self.code_model.get_relative_import_path(self.serialize_namespace, module_name="_utils.model_base"),
|
|
234
|
+
"Model",
|
|
235
235
|
ImportType.LOCAL,
|
|
236
236
|
TypingSection.REGULAR,
|
|
237
|
+
alias="_Model",
|
|
237
238
|
)
|
|
238
239
|
for model in self.models:
|
|
239
240
|
if model.base == "json":
|
|
@@ -272,7 +273,7 @@ class DpgModelSerializer(_ModelSerializer):
|
|
|
272
273
|
return file_import
|
|
273
274
|
|
|
274
275
|
def declare_model(self, model: ModelType) -> str:
|
|
275
|
-
basename = "
|
|
276
|
+
basename = "_Model"
|
|
276
277
|
if model.parents:
|
|
277
278
|
basename = ", ".join([m.name for m in model.parents])
|
|
278
279
|
if model.discriminator_value:
|
|
@@ -109,6 +109,7 @@ class ParameterSerializer:
|
|
|
109
109
|
return f"[{serialize_line} if q is not None else '' for q in {origin_name}]"
|
|
110
110
|
return serialize_line
|
|
111
111
|
|
|
112
|
+
# pylint: disable=line-too-long
|
|
112
113
|
def serialize_path(
|
|
113
114
|
self,
|
|
114
115
|
parameters: Union[
|
|
@@ -124,7 +125,11 @@ class ParameterSerializer:
|
|
|
124
125
|
[
|
|
125
126
|
' "{}": {},'.format(
|
|
126
127
|
path_parameter.wire_name,
|
|
127
|
-
|
|
128
|
+
(
|
|
129
|
+
f'"" if {path_parameter.full_client_name} is None else "/" + {self.serialize_parameter(path_parameter, serializer_name)}'
|
|
130
|
+
if path_parameter.optional and isinstance(path_parameter, RequestBuilderParameter)
|
|
131
|
+
else self.serialize_parameter(path_parameter, serializer_name)
|
|
132
|
+
),
|
|
128
133
|
)
|
|
129
134
|
for path_parameter in parameters
|
|
130
135
|
]
|
|
@@ -62,7 +62,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
62
62
|
ImportType.SDKCORE,
|
|
63
63
|
)
|
|
64
64
|
for param in self.operation.parameters.positional + self.operation.parameters.keyword_only:
|
|
65
|
-
if
|
|
65
|
+
if param.client_default_value is None and not param.optional and param.wire_name in self.sample_params:
|
|
66
66
|
imports.merge(param.type.imports_for_sample())
|
|
67
67
|
return FileImportSerializer(imports, True)
|
|
68
68
|
|
|
@@ -80,7 +80,7 @@ class SampleSerializer(BaseSerializer):
|
|
|
80
80
|
for p in (
|
|
81
81
|
self.code_model.clients[0].parameters.positional + self.code_model.clients[0].parameters.keyword_only
|
|
82
82
|
)
|
|
83
|
-
if not
|
|
83
|
+
if not p.optional and p.client_default_value is None
|
|
84
84
|
]
|
|
85
85
|
client_params = {
|
|
86
86
|
p.client_name: special_param.get(
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
{% if client.has_parameterized_host %}
|
|
10
10
|
{{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
|
|
11
11
|
{% endif %}
|
|
12
|
-
{{ serializer.initialize_config() }}
|
|
12
|
+
{{ op_tools.serialize(serializer.initialize_config()) | indent(8) }}
|
|
13
13
|
{{ op_tools.serialize(serializer.initialize_pipeline_client(async_mode)) | indent(8) }}
|
|
14
14
|
|
|
15
15
|
{{ op_tools.serialize(serializer.serializers_and_operation_groups_properties()) | indent(8) }}
|
|
@@ -21,14 +21,8 @@ class {{ client.name }}Configuration: {{ client.config.pylint_disable() }}
|
|
|
21
21
|
{% if serializer.set_constants() %}
|
|
22
22
|
{{ op_tools.serialize(serializer.set_constants()) | indent(8) -}}
|
|
23
23
|
{% endif %}
|
|
24
|
-
{% if client.
|
|
25
|
-
|
|
26
|
-
{% if not cred_scopes %}
|
|
27
|
-
{% set cred_scopes = client.credential.type.types | selectattr("policy.credential_scopes") | first if client.credential.type.types is defined %}
|
|
28
|
-
{% endif %}
|
|
29
|
-
{% if cred_scopes %}
|
|
30
|
-
self.credential_scopes = kwargs.pop('credential_scopes', {{ cred_scopes.policy.credential_scopes }})
|
|
31
|
-
{% endif %}
|
|
24
|
+
{% if client.credential_scopes is not none %}
|
|
25
|
+
self.credential_scopes = kwargs.pop('credential_scopes', {{ client.credential_scopes }})
|
|
32
26
|
{% endif %}
|
|
33
27
|
kwargs.setdefault('sdk_moniker', '{{ client.config.sdk_moniker }}/{}'.format(VERSION))
|
|
34
28
|
self.polling_interval = kwargs.get("polling_interval", 30)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{% set base_class = ("(" + operation_group.base_class + ")") if operation_group.base_class else "" %}
|
|
1
|
+
{% set base_class = ("(" + operation_group.base_class(async_mode) + ")") if operation_group.base_class(async_mode) else "" %}
|
|
2
2
|
{% macro check_abstract_methods() %}
|
|
3
3
|
{% if operation_group.has_abstract_operations %}
|
|
4
4
|
raise_if_not_implemented(self.__class__, [
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
])
|
|
9
9
|
{% endif %}
|
|
10
10
|
{% endmacro %}
|
|
11
|
-
{% if operation_group.base_class %}
|
|
11
|
+
{% if operation_group.base_class(async_mode) %}
|
|
12
12
|
class {{ operation_group.class_name }}( {{ operation_group.pylint_disable() }}
|
|
13
|
-
{{ operation_group.base_class }}
|
|
13
|
+
{{ operation_group.base_class(async_mode) }}
|
|
14
14
|
):
|
|
15
15
|
{% else %}
|
|
16
16
|
class {{ operation_group.class_name }}: {{ operation_group.pylint_disable() }}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
+
{% set min_version = MIN_PYTHON_VERSION.split('.')[1] | int %}
|
|
3
|
+
{% set max_version = MAX_PYTHON_VERSION.split('.')[1] | int %}
|
|
2
4
|
{% if code_model.license_header %}
|
|
3
5
|
{{ code_model.license_header }}
|
|
4
6
|
{% endif %}
|
|
@@ -67,10 +69,9 @@ setup(
|
|
|
67
69
|
"Programming Language :: Python",
|
|
68
70
|
"Programming Language :: Python :: 3 :: Only",
|
|
69
71
|
"Programming Language :: Python :: 3",
|
|
70
|
-
|
|
71
|
-
"Programming Language :: Python :: 3.
|
|
72
|
-
|
|
73
|
-
"Programming Language :: Python :: 3.12",
|
|
72
|
+
{% for version in range(min_version, max_version + 1) %}
|
|
73
|
+
"Programming Language :: Python :: 3.{{ version }}",
|
|
74
|
+
{% endfor %}
|
|
74
75
|
"License :: OSI Approved :: MIT License",
|
|
75
76
|
],
|
|
76
77
|
zip_safe=False,
|
|
@@ -95,21 +96,21 @@ setup(
|
|
|
95
96
|
{% endif %}
|
|
96
97
|
install_requires=[
|
|
97
98
|
{% if code_model.is_legacy %}
|
|
98
|
-
"msrest>=
|
|
99
|
+
"msrest>={{ VERSION_MAP["msrest"] }}",
|
|
99
100
|
{% else %}
|
|
100
|
-
"isodate>=
|
|
101
|
+
"isodate>={{ VERSION_MAP["isodate"] }}",
|
|
101
102
|
{% endif %}
|
|
102
103
|
{% if azure_arm %}
|
|
103
|
-
"azure-mgmt-core>=
|
|
104
|
+
"azure-mgmt-core>={{ VERSION_MAP["azure-mgmt-core"] }}",
|
|
104
105
|
{% elif code_model.is_azure_flavor %}
|
|
105
|
-
"azure-core>=
|
|
106
|
+
"azure-core>={{ VERSION_MAP["azure-core"] }}",
|
|
106
107
|
{% else %}
|
|
107
|
-
"corehttp[requests]",
|
|
108
|
+
"corehttp[requests]>={{ VERSION_MAP["corehttp"] }}",
|
|
108
109
|
{% endif %}
|
|
109
|
-
"typing-extensions>=
|
|
110
|
+
"typing-extensions>={{ VERSION_MAP['typing-extensions'] }}",
|
|
110
111
|
],
|
|
111
112
|
{% if package_mode %}
|
|
112
|
-
python_requires=">=
|
|
113
|
+
python_requires=">={{ MIN_PYTHON_VERSION }}",
|
|
113
114
|
{% else %}
|
|
114
115
|
long_description="""\
|
|
115
116
|
{{ code_model.description }}
|
|
@@ -5,20 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
{{ imports }}
|
|
7
7
|
|
|
8
|
-
{% if code_model.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
):
|
|
8
|
+
{% if code_model.need_utils_mixin %}
|
|
9
|
+
|
|
10
|
+
TClient = TypeVar("TClient")
|
|
11
|
+
TConfig = TypeVar("TConfig")
|
|
12
|
+
|
|
13
|
+
class ClientMixinABC(ABC, Generic[TClient, TConfig]):
|
|
14
14
|
"""DO NOT use this class. It is for internal typing use only."""
|
|
15
|
-
_client:
|
|
16
|
-
_config:
|
|
15
|
+
_client: TClient
|
|
16
|
+
_config: TConfig
|
|
17
17
|
_serialize: "Serializer"
|
|
18
18
|
_deserialize: "Deserializer"
|
|
19
|
-
{% endfor %}
|
|
20
19
|
{% endif %}
|
|
21
|
-
{% if code_model.
|
|
20
|
+
{% if code_model.need_utils_abstract(client_namespace) %}
|
|
22
21
|
|
|
23
22
|
def raise_if_not_implemented(cls, abstract_methods):
|
|
24
23
|
not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))]
|
|
@@ -29,7 +28,7 @@ def raise_if_not_implemented(cls, abstract_methods):
|
|
|
29
28
|
)
|
|
30
29
|
{% endif %}
|
|
31
30
|
|
|
32
|
-
{% if code_model.
|
|
31
|
+
{% if code_model.need_utils_etag(client_namespace) %}
|
|
33
32
|
def quote_etag(etag: Optional[str]) -> Optional[str]:
|
|
34
33
|
if not etag or etag == "*":
|
|
35
34
|
return etag
|
|
@@ -59,7 +58,7 @@ def prep_if_none_match(etag: Optional[str], match_condition: Optional[MatchCondi
|
|
|
59
58
|
return "*"
|
|
60
59
|
return None
|
|
61
60
|
{% endif %}
|
|
62
|
-
{% if code_model.
|
|
61
|
+
{% if code_model.need_utils_form_data(async_mode, client_namespace) %}
|
|
63
62
|
# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)`
|
|
64
63
|
FileContent = Union[str, bytes, IO[str], IO[bytes]]
|
|
65
64
|
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
"install": [
|
|
5
5
|
{
|
|
6
6
|
"download_info": {
|
|
7
|
-
"url": "https://files.pythonhosted.org/packages/
|
|
7
|
+
"url": "https://files.pythonhosted.org/packages/cc/ea/d53f2f8897c46a36df085964d07761ea4c2d1f2cf92019693b6742b7aabb/setuptools-79.0.0-py3-none-any.whl",
|
|
8
8
|
"archive_info": {
|
|
9
|
-
"hash": "sha256=
|
|
9
|
+
"hash": "sha256=b9ab3a104bedb292323f53797b00864e10e434a3ab3906813a7169e4745b912a",
|
|
10
10
|
"hashes": {
|
|
11
|
-
"sha256": "
|
|
11
|
+
"sha256": "b9ab3a104bedb292323f53797b00864e10e434a3ab3906813a7169e4745b912a"
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"metadata": {
|
|
19
19
|
"metadata_version": "2.4",
|
|
20
20
|
"name": "setuptools",
|
|
21
|
-
"version": "
|
|
21
|
+
"version": "79.0.0",
|
|
22
22
|
"dynamic": [
|
|
23
23
|
"license-file"
|
|
24
24
|
],
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"classifier": [
|
|
40
40
|
"Development Status :: 5 - Production/Stable",
|
|
41
41
|
"Intended Audience :: Developers",
|
|
42
|
-
"License :: OSI Approved :: MIT License",
|
|
43
42
|
"Programming Language :: Python :: 3",
|
|
44
43
|
"Programming Language :: Python :: 3 :: Only",
|
|
45
44
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
Binary file
|
|
@@ -15,7 +15,7 @@ from .request_builder import (
|
|
|
15
15
|
OverloadedRequestBuilder,
|
|
16
16
|
get_request_builder,
|
|
17
17
|
)
|
|
18
|
-
from .parameter import Parameter, ParameterMethodLocation
|
|
18
|
+
from .parameter import Parameter, ParameterMethodLocation, ParameterLocation
|
|
19
19
|
from .lro_operation import LROOperation
|
|
20
20
|
from .lro_paging_operation import LROPagingOperation
|
|
21
21
|
from ...utils import extract_original_name, NAME_LENGTH_LIMIT
|
|
@@ -54,7 +54,7 @@ class _ClientConfigBase(Generic[ParameterListType], BaseModel):
|
|
|
54
54
|
return self.yaml_data["name"]
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
57
|
+
class Client(_ClientConfigBase[ClientGlobalParameterList]): # pylint: disable=too-many-public-methods
|
|
58
58
|
"""Model representing our service client"""
|
|
59
59
|
|
|
60
60
|
def __init__(
|
|
@@ -79,6 +79,27 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
79
79
|
self.request_id_header_name = self.yaml_data.get("requestIdHeaderName", None)
|
|
80
80
|
self.has_etag: bool = yaml_data.get("hasEtag", False)
|
|
81
81
|
|
|
82
|
+
# update the host parameter value. In later logic, SDK will overwrite it
|
|
83
|
+
# with value from cloud_setting if users don't provide it.
|
|
84
|
+
if self.need_cloud_setting:
|
|
85
|
+
for p in self.parameters.parameters:
|
|
86
|
+
if p.location == ParameterLocation.ENDPOINT_PATH:
|
|
87
|
+
p.client_default_value = None
|
|
88
|
+
p.optional = True
|
|
89
|
+
break
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def need_cloud_setting(self) -> bool:
|
|
93
|
+
return bool(
|
|
94
|
+
self.code_model.options.get("azure_arm", False)
|
|
95
|
+
and self.credential_scopes is not None
|
|
96
|
+
and self.endpoint_parameter is not None
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def endpoint_parameter(self) -> Optional[Parameter]:
|
|
101
|
+
return next((p for p in self.parameters.parameters if p.location == ParameterLocation.ENDPOINT_PATH), None)
|
|
102
|
+
|
|
82
103
|
def _build_request_builders(
|
|
83
104
|
self,
|
|
84
105
|
) -> List[Union[RequestBuilder, OverloadedRequestBuilder]]:
|
|
@@ -233,6 +254,10 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
233
254
|
"Self",
|
|
234
255
|
ImportType.STDLIB,
|
|
235
256
|
)
|
|
257
|
+
if self.need_cloud_setting:
|
|
258
|
+
file_import.add_submodule_import("typing", "cast", ImportType.STDLIB)
|
|
259
|
+
file_import.add_submodule_import("azure.core.settings", "settings", ImportType.SDKCORE)
|
|
260
|
+
file_import.add_submodule_import("azure.mgmt.core.tools", "get_arm_endpoints", ImportType.SDKCORE)
|
|
236
261
|
return file_import
|
|
237
262
|
|
|
238
263
|
@property
|
|
@@ -332,6 +357,18 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
332
357
|
)
|
|
333
358
|
return file_import
|
|
334
359
|
|
|
360
|
+
@property
|
|
361
|
+
def credential_scopes(self) -> Optional[List[str]]:
|
|
362
|
+
"""Credential scopes for this client"""
|
|
363
|
+
|
|
364
|
+
if self.credential:
|
|
365
|
+
if hasattr(getattr(self.credential.type, "policy", None), "credential_scopes"):
|
|
366
|
+
return self.credential.type.policy.credential_scopes # type: ignore
|
|
367
|
+
for t in getattr(self.credential.type, "types", []):
|
|
368
|
+
if hasattr(getattr(t, "policy", None), "credential_scopes"):
|
|
369
|
+
return t.policy.credential_scopes
|
|
370
|
+
return None
|
|
371
|
+
|
|
335
372
|
@classmethod
|
|
336
373
|
def from_yaml(
|
|
337
374
|
cls,
|
|
@@ -242,16 +242,26 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
242
242
|
"""
|
|
243
243
|
return client_namespace == self.namespace
|
|
244
244
|
|
|
245
|
-
def
|
|
246
|
-
"""Whether we need to vendor code in the _vendor.py in specific namespace"""
|
|
245
|
+
def need_utils_folder(self, async_mode: bool, client_namespace: str) -> bool:
|
|
247
246
|
return (
|
|
248
|
-
self.
|
|
249
|
-
or self.
|
|
250
|
-
or self.
|
|
251
|
-
or self.need_vendored_mixin(client_namespace)
|
|
247
|
+
self.need_utils_utils(async_mode, client_namespace)
|
|
248
|
+
or self.need_utils_serialization
|
|
249
|
+
or self.options["models_mode"] == "dpg"
|
|
252
250
|
)
|
|
253
251
|
|
|
254
|
-
|
|
252
|
+
@property
|
|
253
|
+
def need_utils_serialization(self) -> bool:
|
|
254
|
+
return not self.options["client_side_validation"]
|
|
255
|
+
|
|
256
|
+
def need_utils_utils(self, async_mode: bool, client_namespace: str) -> bool:
|
|
257
|
+
return (
|
|
258
|
+
self.need_utils_form_data(async_mode, client_namespace)
|
|
259
|
+
or self.need_utils_etag(client_namespace)
|
|
260
|
+
or self.need_utils_abstract(client_namespace)
|
|
261
|
+
or self.need_utils_mixin
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
def need_utils_form_data(self, async_mode: bool, client_namespace: str) -> bool:
|
|
255
265
|
return (
|
|
256
266
|
(not async_mode)
|
|
257
267
|
and self.is_top_namespace(client_namespace)
|
|
@@ -259,14 +269,15 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
259
269
|
and self.options["models_mode"] == "dpg"
|
|
260
270
|
)
|
|
261
271
|
|
|
262
|
-
def
|
|
272
|
+
def need_utils_etag(self, client_namespace: str) -> bool:
|
|
263
273
|
return self.is_top_namespace(client_namespace) and self.has_etag
|
|
264
274
|
|
|
265
|
-
def
|
|
275
|
+
def need_utils_abstract(self, client_namespace: str) -> bool:
|
|
266
276
|
return self.is_top_namespace(client_namespace) and self.has_abstract_operations
|
|
267
277
|
|
|
268
|
-
|
|
269
|
-
|
|
278
|
+
@property
|
|
279
|
+
def need_utils_mixin(self) -> bool:
|
|
280
|
+
return any(c_n for c_n in self.client_namespace_types if self.has_mixin(c_n))
|
|
270
281
|
|
|
271
282
|
def has_mixin(self, client_namespace: str) -> bool:
|
|
272
283
|
return any(c for c in self.get_clients(client_namespace) if c.has_mixin)
|
|
@@ -52,7 +52,7 @@ class EnumValue(BaseType):
|
|
|
52
52
|
"""The python type used for RST syntax input and type annotation."""
|
|
53
53
|
|
|
54
54
|
type_annotation = self.value_type.type_annotation(**kwargs)
|
|
55
|
-
enum_type_annotation = f"{self.
|
|
55
|
+
enum_type_annotation = f"{self.enum_type.client_namespace}.models.{self.name}"
|
|
56
56
|
return f"{type_annotation} or ~{enum_type_annotation}"
|
|
57
57
|
|
|
58
58
|
def get_json_template_representation(
|
|
@@ -198,7 +198,7 @@ class EnumType(BaseType):
|
|
|
198
198
|
"""The python type used for RST syntax input and type annotation."""
|
|
199
199
|
if self.code_model.options["models_mode"]:
|
|
200
200
|
type_annotation = self.value_type.type_annotation(**kwargs)
|
|
201
|
-
enum_type_annotation = f"{self.
|
|
201
|
+
enum_type_annotation = f"{self.client_namespace}.models.{self.name}"
|
|
202
202
|
return f"{type_annotation} or ~{enum_type_annotation}"
|
|
203
203
|
return self.value_type.type_annotation(**kwargs)
|
|
204
204
|
|