Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination feature #652

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions azure-quantum/azure/quantum/_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position

from ._client import QuantumClient
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import

from ._client import ServicesClient # type: ignore
from ._version import VERSION

__version__ = VERSION

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

__all__ = [
"QuantumClient",
"ServicesClient",
]
__all__.extend([p for p in _patch_all if p not in __all__])
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore

_patch_sdk()
89 changes: 40 additions & 49 deletions azure-quantum/azure/quantum/_client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

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

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

from . import models as _models
from ._configuration import QuantumClientConfiguration
from ._configuration import ServicesClientConfiguration
from ._serialization import Deserializer, Serializer
from .operations import (
JobsOperations,
Expand All @@ -26,59 +27,50 @@
)

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


class QuantumClient: # pylint: disable=client-accepts-api-version-keyword
"""Azure Quantum REST API client.
class ServicesClient:
"""Azure Quantum Workspace Services.

:ivar jobs: JobsOperations operations
:vartype jobs: azure.quantum._client.operations.JobsOperations
:vartype jobs: azure.quantum.operations.JobsOperations
:ivar sessions: SessionsOperations operations
:vartype sessions: azure.quantum.operations.SessionsOperations
:ivar providers: ProvidersOperations operations
:vartype providers: azure.quantum._client.operations.ProvidersOperations
:vartype providers: azure.quantum.operations.ProvidersOperations
:ivar storage: StorageOperations operations
:vartype storage: azure.quantum._client.operations.StorageOperations
:vartype storage: azure.quantum.operations.StorageOperations
:ivar quotas: QuotasOperations operations
:vartype quotas: azure.quantum._client.operations.QuotasOperations
:ivar sessions: SessionsOperations operations
:vartype sessions: azure.quantum._client.operations.SessionsOperations
:vartype quotas: azure.quantum.operations.QuotasOperations
:ivar top_level_items: TopLevelItemsOperations operations
:vartype top_level_items: azure.quantum._client.operations.TopLevelItemsOperations
:param azure_region: Supported Azure regions for Azure Quantum Services. For example, "eastus".
Required.
:type azure_region: str
:param subscription_id: The Azure subscription ID. This is a GUID-formatted string (e.g.
00000000-0000-0000-0000-000000000000). Required.
:type subscription_id: str
:param resource_group_name: Name of an Azure resource group. Required.
:type resource_group_name: str
:param workspace_name: Name of the workspace. Required.
:type workspace_name: str
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.TokenCredential
:keyword api_version: Api Version. Default value is "2023-11-13-preview". Note that overriding
this default value may result in unsupported behavior.
:vartype top_level_items: azure.quantum.operations.TopLevelItemsOperations
:param region: The Azure region where the Azure Quantum Workspace is located. Required.
:type region: str
:param credential: Credential used to authenticate requests to the service. Is either a
TokenCredential type or a AzureKeyCredential type. Required.
:type credential: ~azure.core.credentials.TokenCredential or
~azure.core.credentials.AzureKeyCredential
:keyword service_base_url: The Azure Quantum service base url. Default value is
"quantum.azure.com".
:paramtype service_base_url: str
:keyword api_version: The API version to use for this operation. Default value is
"2024-10-01-preview". Note that overriding this default value may result in unsupported
behavior.
:paramtype api_version: str
"""

def __init__(
self,
azure_region: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
credential: "TokenCredential",
region: str,
credential: Union["TokenCredential", AzureKeyCredential],
*,
service_base_url: str = "quantum.azure.com",
**kwargs: Any
) -> None:
_endpoint = kwargs.pop("endpoint", f"https://{azure_region}.quantum.azure.com")
self._config = QuantumClientConfiguration(
azure_region=azure_region,
subscription_id=subscription_id,
resource_group_name=resource_group_name,
workspace_name=workspace_name,
credential=credential,
**kwargs
_endpoint = "https://{region}.{serviceBaseUrl}"
self._config = ServicesClientConfiguration(
region=region, credential=credential, service_base_url=service_base_url, **kwargs
)
_policies = kwargs.pop("policies", None)
if _policies is None:
Expand All @@ -99,16 +91,14 @@ def __init__(
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
client_models.update({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 = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize)
self.sessions = SessionsOperations(self._client, self._config, self._serialize, self._deserialize)
self.providers = ProvidersOperations(self._client, self._config, self._serialize, self._deserialize)
self.storage = StorageOperations(self._client, self._config, self._serialize, self._deserialize)
self.quotas = QuotasOperations(self._client, self._config, self._serialize, self._deserialize)
self.sessions = SessionsOperations(self._client, self._config, self._serialize, self._deserialize)
self.top_level_items = TopLevelItemsOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
Expand All @@ -131,8 +121,9 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:

request_copy = deepcopy(request)
path_format_arguments = {
"azureRegion": self._serialize.url(
"self._config.azure_region", self._config.azure_region, "str", skip_quote=True
"region": self._serialize.url("self._config.region", self._config.region, "str"),
"serviceBaseUrl": self._serialize.url(
"self._config.service_base_url", self._config.service_base_url, "str"
),
}

Expand All @@ -142,7 +133,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
def close(self) -> None:
self._client.close()

def __enter__(self) -> "QuantumClient":
def __enter__(self) -> Self:
self._client.__enter__()
return self

Expand Down
75 changes: 34 additions & 41 deletions azure-quantum/azure/quantum/_client/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,72 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any, TYPE_CHECKING
from typing import Any, TYPE_CHECKING, Union

from azure.core.credentials import AzureKeyCredential
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


class QuantumClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for QuantumClient.
class ServicesClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for ServicesClient.

Note that all parameters used to create this instance are saved as instance
attributes.

:param azure_region: Supported Azure regions for Azure Quantum Services. For example, "eastus".
Required.
:type azure_region: str
:param subscription_id: The Azure subscription ID. This is a GUID-formatted string (e.g.
00000000-0000-0000-0000-000000000000). Required.
:type subscription_id: str
:param resource_group_name: Name of an Azure resource group. Required.
:type resource_group_name: str
:param workspace_name: Name of the workspace. Required.
:type workspace_name: str
:param credential: Credential needed for the client to connect to Azure. Required.
:type credential: ~azure.core.credentials.TokenCredential
:keyword api_version: Api Version. Default value is "2023-11-13-preview". Note that overriding
this default value may result in unsupported behavior.
:param region: The Azure region where the Azure Quantum Workspace is located. Required.
:type region: str
:param credential: Credential used to authenticate requests to the service. Is either a
TokenCredential type or a AzureKeyCredential type. Required.
:type credential: ~azure.core.credentials.TokenCredential or
~azure.core.credentials.AzureKeyCredential
:param service_base_url: The Azure Quantum service base url. Default value is
"quantum.azure.com".
:type service_base_url: str
:keyword api_version: The API version to use for this operation. Default value is
"2024-10-01-preview". Note that overriding this default value may result in unsupported
behavior.
:paramtype api_version: str
"""

def __init__(
self,
azure_region: str,
subscription_id: str,
resource_group_name: str,
workspace_name: str,
credential: "TokenCredential",
**kwargs: Any
region: str,
credential: Union["TokenCredential", AzureKeyCredential],
service_base_url: str = "quantum.azure.com",
**kwargs: Any,
) -> None:
api_version: str = kwargs.pop("api_version", "2022-09-12-preview")
api_version: str = kwargs.pop("api_version", "2024-10-01-preview")

if azure_region is None:
raise ValueError("Parameter 'azure_region' must not be None.")
if subscription_id is None:
raise ValueError("Parameter 'subscription_id' must not be None.")
if resource_group_name is None:
raise ValueError("Parameter 'resource_group_name' must not be None.")
if workspace_name is None:
raise ValueError("Parameter 'workspace_name' must not be None.")
if region is None:
raise ValueError("Parameter 'region' must not be None.")
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")

self.azure_region = azure_region
self.subscription_id = subscription_id
self.resource_group_name = resource_group_name
self.workspace_name = workspace_name
self.region = region
self.credential = credential
self.service_base_url = service_base_url
self.api_version = api_version
self.credential_scopes = kwargs.pop("credential_scopes", ["https://quantum.microsoft.com/.default"])
kwargs.setdefault("sdk_moniker", "quantum/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _infer_policy(self, **kwargs):
if hasattr(self.credential, "get_token"):
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "x-ms-quantum-api-key", **kwargs)
raise TypeError(f"Unsupported credential: {self.credential}")

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)
Expand All @@ -84,6 +79,4 @@ def _configure(self, **kwargs: Any) -> None:
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(
self.credential, *self.credential_scopes, **kwargs
)
self.authentication_policy = self._infer_policy(**kwargs)
Loading
Loading