Skip to content

Commit

Permalink
Rewrite azure-maps-route sdk (#37776)
Browse files Browse the repository at this point in the history
* Fix pylint error

* Finish generating

* Finish tests and samples

* Fix errors

* Fix ci errors

* Update cspell.json

* Fix pylint error

* Resolve conflicts

* Resolve comments
  • Loading branch information
zhz0704 authored Oct 10, 2024
1 parent 2e2309b commit a68505f
Show file tree
Hide file tree
Showing 45 changed files with 4,494 additions and 6,016 deletions.
10 changes: 10 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,16 @@
"words": [
"stringized"
]
},
{
"filename": "sdk/maps/azure-maps-route/**",
"words": [
"uturn",
"Einsteinweg",
"Hundredkm",
"TPEG",
"Hundredkm"
]
}
],
"allowCompoundWords": true
Expand Down
2 changes: 1 addition & 1 deletion sdk/maps/azure-maps-route/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/maps/azure-maps-route",
"Tag": "python/maps/azure-maps-route_543cdfb1f8"
"Tag": "python/maps/azure-maps-route_fe9d365729"
}
14 changes: 10 additions & 4 deletions sdk/maps/azure-maps-route/azure/maps/route/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._version import VERSION
from ._route_client import MapsRouteClient
try:
from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk

__all__ = [
'MapsRouteClient'
"MapsRouteClient",
]
__version__ = VERSION
__all__.extend([p for p in _patch_all if p not in __all__])

_patch_sdk()
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

from copy import deepcopy
from typing import Any, Optional, TYPE_CHECKING
from typing_extensions import Self

from azure.core import PipelineClient
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse

from . import models
from . import models as _models
from ._configuration import MapsRouteClientConfiguration
from ._serialization import Deserializer, Serializer
from .operations import RouteOperations
Expand All @@ -22,13 +24,13 @@
from azure.core.credentials import TokenCredential


class MapsRouteClient: # pylint: disable=client-accepts-api-version-keyword
class MapsRouteClient(RouteOperations):
"""Azure Maps Route REST APIs.
:ivar route: RouteOperations operations
:vartype route: azure.maps.route.operations.RouteOperations
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.TokenCredential
:type credential: ~azure.core.credentials.AzureKeyCredential
:param client_id: Specifies which account is intended for usage in conjunction with the Azure
AD security model. It represents a unique ID for the Azure Maps account and can be retrieved
from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see
Expand All @@ -52,15 +54,37 @@ def __init__(
**kwargs: Any
) -> None:
self._config = MapsRouteClientConfiguration(credential=credential, client_id=client_id, **kwargs)
self._client = PipelineClient(base_url=endpoint, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=endpoint, policies=_policies, **kwargs)

client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False
self.route = RouteOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
super().__init__(
client=self._client,
config=self._config,
serializer=self._serialize,
deserializer=self._deserialize
)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.
>>> from azure.core.rest import HttpRequest
Expand All @@ -80,17 +104,14 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:

request_copy = deepcopy(request)
request_copy.url = self._client.format_url(request_copy.url)
return self._client.send_request(request_copy, **kwargs)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self):
# type: () -> None
def close(self) -> None:
self._client.close()

def __enter__(self):
# type: () -> MapsRouteClient
def __enter__(self) -> Self:
self._client.__enter__()
return self

def __exit__(self, *exc_details):
# type: (Any) -> None
def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,69 @@

from typing import Any, Optional, TYPE_CHECKING

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

from ._version import VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential

VERSION = "1.0.0b2"


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

def __init__(self, credential: "TokenCredential", client_id: Optional[str] = None, **kwargs: Any) -> None:
super(MapsRouteClientConfiguration, self).__init__(**kwargs)
api_version = kwargs.pop("api_version", "1.0") # type: str
def __init__(
self,
credential: "TokenCredential",
accept: Optional[str] = None,
client_id: Optional[str] = None,
**kwargs: Any
) -> None:
api_version: str = kwargs.pop("api_version", "1.0")

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

self.credential = credential
self.accept = accept
self.client_id = client_id
self.api_version = api_version
self.credential_scopes = kwargs.pop("credential_scopes", ["https://atlas.microsoft.com/.default"])
kwargs.setdefault("sdk_moniker", "maps-route/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _configure(
self, **kwargs # type: Any
):
# type: (...) -> None
def _configure(self, **kwargs: Any) -> None:
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
if self.credential and not self.authentication_policy:
self.authentication_policy = policies.BearerTokenCredentialPolicy(
Expand Down
24 changes: 0 additions & 24 deletions sdk/maps/azure-maps-route/azure/maps/route/_generated/__init__.py

This file was deleted.

17 changes: 0 additions & 17 deletions sdk/maps/azure-maps-route/azure/maps/route/_generated/_vendor.py

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a68505f

Please sign in to comment.