Skip to content

Commit b4c2904

Browse files
author
SDKAuto
committed
CodeGen from PR 3537 in test-repo-billy/azure-rest-api-specs
Merge 6296b8e5c14516850f6b39a7fee10b2f0db170a5 into 6c6e1713f03acaf37e5c89652b023dd2c9eae16e
1 parent b2b0c35 commit b4c2904

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+41289
-33579
lines changed

sdk/batch/azure-batch/MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include *.md
22
include LICENSE
3-
include azure/__init__.py
4-
recursive-include tests *.py
53
include azure/batch/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include azure/__init__.py

sdk/batch/azure-batch/_meta.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commit": "c29452397f8d29456182b951987a765d1ae01bb1",
3+
"repository_url": "https://github.com/test-repo-billy/azure-rest-api-specs",
4+
"typespec_src": "specification/batch/Azure.Batch",
5+
"@azure-tools/typespec-python": "0.31.1"
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
# coding=utf-8
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
4-
# Licensed under the MIT License. See License.txt in the project root for
5-
# license information.
6-
#
7-
# Code generated by Microsoft (R) AutoRest Code Generator.
8-
# Changes may cause incorrect behavior and will be lost if the code is
9-
# regenerated.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
107
# --------------------------------------------------------------------------
118

12-
from ._configuration import BatchServiceClientConfiguration
13-
from ._batch_service_client import BatchServiceClient
14-
__all__ = ['BatchServiceClient', 'BatchServiceClientConfiguration']
15-
9+
from ._client import BatchClient
1610
from ._version import VERSION
1711

1812
__version__ = VERSION
1913

14+
try:
15+
from ._patch import __all__ as _patch_all
16+
from ._patch import * # pylint: disable=unused-wildcard-import
17+
except ImportError:
18+
_patch_all = []
19+
from ._patch import patch_sdk as _patch_sdk
20+
21+
__all__ = [
22+
"BatchClient",
23+
]
24+
__all__.extend([p for p in _patch_all if p not in __all__])
25+
26+
_patch_sdk()

sdk/batch/azure-batch/azure/batch/_batch_service_client.py

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import Any, TYPE_CHECKING
11+
from typing_extensions import Self
12+
13+
from azure.core import PipelineClient
14+
from azure.core.pipeline import policies
15+
from azure.core.rest import HttpRequest, HttpResponse
16+
17+
from ._configuration import BatchClientConfiguration
18+
from ._operations import BatchClientOperationsMixin
19+
from ._serialization import Deserializer, Serializer
20+
21+
if TYPE_CHECKING:
22+
# pylint: disable=unused-import,ungrouped-imports
23+
from azure.core.credentials import TokenCredential
24+
25+
26+
class BatchClient(BatchClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
27+
"""BatchClient.
28+
29+
:param endpoint: Batch account endpoint (for example:
30+
https://batchaccount.eastus2.batch.azure.com). Required.
31+
:type endpoint: str
32+
:param credential: Credential used to authenticate requests to the service. Required.
33+
:type credential: ~azure.core.credentials.TokenCredential
34+
:keyword api_version: The API version to use for this operation. Default value is
35+
"2024-07-01.20.0". Note that overriding this default value may result in unsupported behavior.
36+
:paramtype api_version: str
37+
"""
38+
39+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
40+
_endpoint = "{endpoint}"
41+
self._config = BatchClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
42+
kwargs["request_id_header_name"] = "client-request-id"
43+
_policies = kwargs.pop("policies", None)
44+
if _policies is None:
45+
_policies = [
46+
policies.RequestIdPolicy(**kwargs),
47+
self._config.headers_policy,
48+
self._config.user_agent_policy,
49+
self._config.proxy_policy,
50+
policies.ContentDecodePolicy(**kwargs),
51+
self._config.redirect_policy,
52+
self._config.retry_policy,
53+
self._config.authentication_policy,
54+
self._config.custom_hook_policy,
55+
self._config.logging_policy,
56+
policies.DistributedTracingPolicy(**kwargs),
57+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
58+
self._config.http_logging_policy,
59+
]
60+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
61+
62+
self._serialize = Serializer()
63+
self._deserialize = Deserializer()
64+
self._serialize.client_side_validation = False
65+
66+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
67+
"""Runs the network request through the client's chained policies.
68+
69+
>>> from azure.core.rest import HttpRequest
70+
>>> request = HttpRequest("GET", "https://www.example.org/")
71+
<HttpRequest [GET], url: 'https://www.example.org/'>
72+
>>> response = client.send_request(request)
73+
<HttpResponse: 200 OK>
74+
75+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
76+
77+
:param request: The network request you want to make. Required.
78+
:type request: ~azure.core.rest.HttpRequest
79+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
80+
:return: The response of your network call. Does not do error handling on your response.
81+
:rtype: ~azure.core.rest.HttpResponse
82+
"""
83+
84+
request_copy = deepcopy(request)
85+
path_format_arguments = {
86+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
87+
}
88+
89+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
90+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
91+
92+
def close(self) -> None:
93+
self._client.close()
94+
95+
def __enter__(self) -> Self:
96+
self._client.__enter__()
97+
return self
98+
99+
def __exit__(self, *exc_details: Any) -> None:
100+
self._client.__exit__(*exc_details)
Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,65 @@
11
# coding=utf-8
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
4-
# Licensed under the MIT License. See License.txt in the project root for
5-
# license information.
6-
#
7-
# Code generated by Microsoft (R) AutoRest Code Generator.
8-
# Changes may cause incorrect behavior and will be lost if the code is
9-
# regenerated.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
107
# --------------------------------------------------------------------------
11-
from msrestazure import AzureConfiguration
8+
9+
from typing import Any, TYPE_CHECKING
10+
11+
from azure.core.pipeline import policies
1212

1313
from ._version import VERSION
1414

15+
if TYPE_CHECKING:
16+
# pylint: disable=unused-import,ungrouped-imports
17+
from azure.core.credentials import TokenCredential
18+
19+
20+
class BatchClientConfiguration: # pylint: disable=too-many-instance-attributes
21+
"""Configuration for BatchClient.
1522
16-
class BatchServiceClientConfiguration(AzureConfiguration):
17-
"""Configuration for BatchServiceClient
1823
Note that all parameters used to create this instance are saved as instance
1924
attributes.
2025
21-
:param credentials: Credentials needed for the client to connect to Azure.
22-
:type credentials: :mod:`A msrestazure Credentials
23-
object<msrestazure.azure_active_directory>`
24-
:param batch_url: The base URL for all Azure Batch service requests.
25-
:type batch_url: str
26+
:param endpoint: Batch account endpoint (for example:
27+
https://batchaccount.eastus2.batch.azure.com). Required.
28+
:type endpoint: str
29+
:param credential: Credential used to authenticate requests to the service. Required.
30+
:type credential: ~azure.core.credentials.TokenCredential
31+
:keyword api_version: The API version to use for this operation. Default value is
32+
"2024-07-01.20.0". Note that overriding this default value may result in unsupported behavior.
33+
:paramtype api_version: str
2634
"""
2735

28-
def __init__(
29-
self, credentials, batch_url):
30-
31-
if credentials is None:
32-
raise ValueError("Parameter 'credentials' must not be None.")
33-
if batch_url is None:
34-
raise ValueError("Parameter 'batch_url' must not be None.")
35-
base_url = '{batchUrl}'
36-
37-
super(BatchServiceClientConfiguration, self).__init__(base_url)
36+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
37+
api_version: str = kwargs.pop("api_version", "2024-07-01.20.0")
3838

39-
# Starting Autorest.Python 4.0.64, make connection pool activated by default
40-
self.keep_alive = True
39+
if endpoint is None:
40+
raise ValueError("Parameter 'endpoint' must not be None.")
41+
if credential is None:
42+
raise ValueError("Parameter 'credential' must not be None.")
4143

42-
self.add_user_agent('azure-batch/{}'.format(VERSION))
43-
self.add_user_agent('Azure-SDK-For-Python')
44+
self.endpoint = endpoint
45+
self.credential = credential
46+
self.api_version = api_version
47+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://batch.core.windows.net//.default"])
48+
kwargs.setdefault("sdk_moniker", "batch/{}".format(VERSION))
49+
self.polling_interval = kwargs.get("polling_interval", 30)
50+
self._configure(**kwargs)
4451

45-
self.credentials = credentials
46-
self.batch_url = batch_url
52+
def _configure(self, **kwargs: Any) -> None:
53+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
54+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
55+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
56+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
57+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
58+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
59+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
60+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
61+
self.authentication_policy = kwargs.get("authentication_policy")
62+
if self.credential and not self.authentication_policy:
63+
self.authentication_policy = policies.BearerTokenCredentialPolicy(
64+
self.credential, *self.credential_scopes, **kwargs
65+
)

0 commit comments

Comments
 (0)