Skip to content

Commit a68505f

Browse files
authored
Rewrite azure-maps-route sdk (#37776)
* Fix pylint error * Finish generating * Finish tests and samples * Fix errors * Fix ci errors * Update cspell.json * Fix pylint error * Resolve conflicts * Resolve comments
1 parent 2e2309b commit a68505f

Some content is hidden

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

45 files changed

+4494
-6016
lines changed

.vscode/cspell.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,16 @@
18971897
"words": [
18981898
"stringized"
18991899
]
1900+
},
1901+
{
1902+
"filename": "sdk/maps/azure-maps-route/**",
1903+
"words": [
1904+
"uturn",
1905+
"Einsteinweg",
1906+
"Hundredkm",
1907+
"TPEG",
1908+
"Hundredkm"
1909+
]
19001910
}
19011911
],
19021912
"allowCompoundWords": true

sdk/maps/azure-maps-route/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/maps/azure-maps-route",
5-
"Tag": "python/maps/azure-maps-route_543cdfb1f8"
5+
"Tag": "python/maps/azure-maps-route_fe9d365729"
66
}

sdk/maps/azure-maps-route/azure/maps/route/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from ._version import VERSION
10-
from ._route_client import MapsRouteClient
9+
try:
10+
from ._patch import __all__ as _patch_all
11+
from ._patch import * # pylint: disable=unused-wildcard-import
12+
except ImportError:
13+
_patch_all = []
14+
from ._patch import patch_sdk as _patch_sdk
1115

1216
__all__ = [
13-
'MapsRouteClient'
17+
"MapsRouteClient",
1418
]
15-
__version__ = VERSION
19+
__all__.extend([p for p in _patch_all if p not in __all__])
20+
21+
_patch_sdk()

sdk/maps/azure-maps-route/azure/maps/route/_generated/_client.py renamed to sdk/maps/azure-maps-route/azure/maps/route/_client.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
from copy import deepcopy
1010
from typing import Any, Optional, TYPE_CHECKING
11+
from typing_extensions import Self
1112

1213
from azure.core import PipelineClient
14+
from azure.core.pipeline import policies
1315
from azure.core.rest import HttpRequest, HttpResponse
1416

15-
from . import models
17+
from . import models as _models
1618
from ._configuration import MapsRouteClientConfiguration
1719
from ._serialization import Deserializer, Serializer
1820
from .operations import RouteOperations
@@ -22,13 +24,13 @@
2224
from azure.core.credentials import TokenCredential
2325

2426

25-
class MapsRouteClient: # pylint: disable=client-accepts-api-version-keyword
27+
class MapsRouteClient(RouteOperations):
2628
"""Azure Maps Route REST APIs.
2729
2830
:ivar route: RouteOperations operations
2931
:vartype route: azure.maps.route.operations.RouteOperations
3032
:param credential: Credential needed for the client to connect to Azure. Required.
31-
:type credential: ~azure.core.credentials.TokenCredential
33+
:type credential: ~azure.core.credentials.AzureKeyCredential
3234
:param client_id: Specifies which account is intended for usage in conjunction with the Azure
3335
AD security model. It represents a unique ID for the Azure Maps account and can be retrieved
3436
from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see
@@ -52,15 +54,37 @@ def __init__(
5254
**kwargs: Any
5355
) -> None:
5456
self._config = MapsRouteClientConfiguration(credential=credential, client_id=client_id, **kwargs)
55-
self._client = PipelineClient(base_url=endpoint, config=self._config, **kwargs)
56-
57-
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
57+
_policies = kwargs.pop("policies", None)
58+
if _policies is None:
59+
_policies = [
60+
policies.RequestIdPolicy(**kwargs),
61+
self._config.headers_policy,
62+
self._config.user_agent_policy,
63+
self._config.proxy_policy,
64+
policies.ContentDecodePolicy(**kwargs),
65+
self._config.redirect_policy,
66+
self._config.retry_policy,
67+
self._config.authentication_policy,
68+
self._config.custom_hook_policy,
69+
self._config.logging_policy,
70+
policies.DistributedTracingPolicy(**kwargs),
71+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
72+
self._config.http_logging_policy,
73+
]
74+
self._client: PipelineClient = PipelineClient(base_url=endpoint, policies=_policies, **kwargs)
75+
76+
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
5877
self._serialize = Serializer(client_models)
5978
self._deserialize = Deserializer(client_models)
6079
self._serialize.client_side_validation = False
61-
self.route = RouteOperations(self._client, self._config, self._serialize, self._deserialize)
62-
63-
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
80+
super().__init__(
81+
client=self._client,
82+
config=self._config,
83+
serializer=self._serialize,
84+
deserializer=self._deserialize
85+
)
86+
87+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
6488
"""Runs the network request through the client's chained policies.
6589
6690
>>> from azure.core.rest import HttpRequest
@@ -80,17 +104,14 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
80104

81105
request_copy = deepcopy(request)
82106
request_copy.url = self._client.format_url(request_copy.url)
83-
return self._client.send_request(request_copy, **kwargs)
107+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
84108

85-
def close(self):
86-
# type: () -> None
109+
def close(self) -> None:
87110
self._client.close()
88111

89-
def __enter__(self):
90-
# type: () -> MapsRouteClient
112+
def __enter__(self) -> Self:
91113
self._client.__enter__()
92114
return self
93115

94-
def __exit__(self, *exc_details):
95-
# type: (Any) -> None
116+
def __exit__(self, *exc_details: Any) -> None:
96117
self._client.__exit__(*exc_details)

sdk/maps/azure-maps-route/azure/maps/route/_generated/_configuration.py renamed to sdk/maps/azure-maps-route/azure/maps/route/_configuration.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,69 @@
88

99
from typing import Any, Optional, TYPE_CHECKING
1010

11-
from azure.core.configuration import Configuration
1211
from azure.core.pipeline import policies
1312

14-
from ._version import VERSION
15-
1613
if TYPE_CHECKING:
1714
# pylint: disable=unused-import,ungrouped-imports
1815
from azure.core.credentials import TokenCredential
1916

17+
VERSION = "1.0.0b2"
18+
2019

21-
class MapsRouteClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
20+
class MapsRouteClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
2221
"""Configuration for MapsRouteClient.
2322
2423
Note that all parameters used to create this instance are saved as instance
2524
attributes.
2625
2726
:param credential: Credential needed for the client to connect to Azure. Required.
2827
:type credential: ~azure.core.credentials.TokenCredential
29-
:param client_id: Specifies which account is intended for usage in conjunction with the Azure
30-
AD security model. It represents a unique ID for the Azure Maps account and can be retrieved
31-
from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see
32-
the following `articles <https://aka.ms/amauthdetails>`_ for guidance. Default value is None.
28+
:param accept: The Accept header field can be used to specify preferences regarding response
29+
media types. Allowed media types include image/jpeg and image/png. Return image in image/png if
30+
Accept header is not specified. Known values are: "image/png" and "image/jpeg". Default value
31+
is None.
32+
:type accept: str
33+
:param client_id: Specifies which account is intended for usage in conjunction with the
34+
Microsoft Entra ID security model. It represents a unique ID for the Azure Maps account and
35+
can be retrieved from the Azure Maps management plane Account API. To use Microsoft Entra ID
36+
security in Azure Maps see the following `articles <https://aka.ms/amauthdetails>`_ for
37+
guidance. Default value is None.
3338
:type client_id: str
34-
:keyword api_version: Api Version. Default value is "1.0". Note that overriding this default
35-
value may result in unsupported behavior.
39+
:keyword api_version: Api Version. Default value is "1.0". Note that overriding this
40+
default value may result in unsupported behavior.
3641
:paramtype api_version: str
3742
"""
3843

39-
def __init__(self, credential: "TokenCredential", client_id: Optional[str] = None, **kwargs: Any) -> None:
40-
super(MapsRouteClientConfiguration, self).__init__(**kwargs)
41-
api_version = kwargs.pop("api_version", "1.0") # type: str
44+
def __init__(
45+
self,
46+
credential: "TokenCredential",
47+
accept: Optional[str] = None,
48+
client_id: Optional[str] = None,
49+
**kwargs: Any
50+
) -> None:
51+
api_version: str = kwargs.pop("api_version", "1.0")
4252

4353
if credential is None:
4454
raise ValueError("Parameter 'credential' must not be None.")
4555

4656
self.credential = credential
57+
self.accept = accept
4758
self.client_id = client_id
4859
self.api_version = api_version
4960
self.credential_scopes = kwargs.pop("credential_scopes", ["https://atlas.microsoft.com/.default"])
5061
kwargs.setdefault("sdk_moniker", "maps-route/{}".format(VERSION))
62+
self.polling_interval = kwargs.get("polling_interval", 30)
5163
self._configure(**kwargs)
5264

53-
def _configure(
54-
self, **kwargs # type: Any
55-
):
56-
# type: (...) -> None
65+
def _configure(self, **kwargs: Any) -> None:
5766
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
5867
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
5968
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
6069
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
6170
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
62-
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
6371
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
6472
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
73+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
6574
self.authentication_policy = kwargs.get("authentication_policy")
6675
if self.credential and not self.authentication_policy:
6776
self.authentication_policy = policies.BearerTokenCredentialPolicy(

sdk/maps/azure-maps-route/azure/maps/route/_generated/__init__.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

sdk/maps/azure-maps-route/azure/maps/route/_generated/_vendor.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

sdk/maps/azure-maps-route/azure/maps/route/_generated/_version.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

sdk/maps/azure-maps-route/azure/maps/route/_generated/aio/__init__.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

sdk/maps/azure-maps-route/azure/maps/route/_generated/aio/_patch.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

sdk/maps/azure-maps-route/azure/maps/route/_generated/aio/operations/_patch.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)