Skip to content

Commit

Permalink
[EG] update pyproject and samples (#35857)
Browse files Browse the repository at this point in the history
* update

* pylint changes
  • Loading branch information
l0lawrence authored Jun 3, 2024
1 parent 6e4a87f commit 6190bde
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
13 changes: 0 additions & 13 deletions scripts/devops_tasks/test_run_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,6 @@
"consume_eventgrid_events_from_service_bus_queue.py",
"sample_publish_events_to_a_topic_using_sas_credential.py",
"sample_publish_events_to_a_topic_using_sas_credential_async.py",
'sample_publish_operation.py',
'sample_receive_operation.py',
'sample_reject_operation.py',
'sample_eg_client_authentication.py',
'sample_all_operations.py',
'sample_release_operation.py',
'sample_acknowledge_operation.py',
'sample_publish_operation_async.py',
'sample_release_operation_async.py',
'sample_reject_operation_async.py',
'sample_acknowledge_operation_async.py',
'sample_receive_operation_async.py',
'sample_all_operations_async.py'
],
"azure-eventhub": [
"client_identity_authentication.py", # TODO: remove after fixing issue #29177
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Optional,
TypeVar,
Union,
overload,
TYPE_CHECKING,
)

Expand All @@ -28,7 +27,6 @@
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline import PipelineResponse
from azure.core.rest import HttpRequest, HttpResponse
from azure.core.utils import case_insensitive_dict

from ._operations import (
EventGridPublisherClientOperationsMixin as PublisherOperationsMixin,
Expand Down Expand Up @@ -105,8 +103,6 @@ def send(
) -> None: # pylint: disable=docstring-should-be-keyword, docstring-missing-param
"""Send events to the Event Grid Service.
:param topic_name: The name of the topic to send the event to.
:type topic_name: str
:param events: The event to send.
:type events: CloudEvent or List[CloudEvent] or Dict[str, Any] or List[Dict[str, Any]]
or CNCFCloudEvent or List[CNCFCloudEvent] or EventGridEvent or List[EventGridEvent]
Expand Down Expand Up @@ -143,24 +139,24 @@ def send(
# Try to send via namespace
self._publish(self._namespace, _serialize_events(events), **kwargs)
except Exception as exception: # pylint: disable=broad-except
self._http_response_error_handler(exception, "Namespaces")
self._http_response_error_handler(exception)
raise exception
else:
kwargs["content_type"] = content_type if content_type else "application/json; charset=utf-8"
try:
self._publish(events, channel_name=channel_name, **kwargs)
except Exception as exception:
self._http_response_error_handler(exception, "Basic")
self._http_response_error_handler(exception)
raise exception

def _http_response_error_handler(self, exception, level):
def _http_response_error_handler(self, exception):
if isinstance(exception, HttpResponseError):
if exception.status_code == 400:
raise HttpResponseError("Invalid event data. Please check the data and try again.") from exception
if exception.status_code == 404:
raise ResourceNotFoundError(
"Resource not found. "
f"Please check that the tier you are using, corresponds to the correct "
"Please check that the tier you are using, corresponds to the correct "
"endpoint and/or topic name."
) from exception
raise exception
Expand Down
3 changes: 2 additions & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def __init__(
)

def __repr__(self) -> str:
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, subscription={self._subscription}, credential type={type(self._credential)}>"
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, \
subscription={self._subscription}, credential type={type(self._credential)}>"


def patch_sdk():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from azure.core.pipeline import PipelineResponse
from azure.core.rest import HttpRequest, AsyncHttpResponse
from ...models._patch import ReceiveDetails
from ..._operations._patch import use_standard_only
from ._operations import (
EventGridPublisherClientOperationsMixin as PublisherOperationsMixin,
EventGridConsumerClientOperationsMixin as ConsumerOperationsMixin,
Expand All @@ -29,7 +28,7 @@
)

from ..._legacy import EventGridEvent
from ..._legacy._helpers import _is_eventgrid_event_format, _from_cncf_events
from ..._legacy._helpers import _is_eventgrid_event_format

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
Expand Down Expand Up @@ -65,8 +64,6 @@ async def send(
) -> None: # pylint: disable=docstring-should-be-keyword, docstring-missing-param
"""Send events to the Event Grid Service.
:param topic_name: The name of the topic to send the event to.
:type topic_name: str
:param events: The event to send.
:type events: CloudEvent or List[CloudEvent] or Dict[str, Any] or List[Dict[str, Any]]
or CNCFCloudEvent or List[CNCFCloudEvent] or EventGridEvent or List[EventGridEvent]
Expand Down Expand Up @@ -104,24 +101,24 @@ async def send(
# Try to send via namespace
await self._publish(self._namespace, _serialize_events(events), **kwargs)
except Exception as exception: # pylint: disable=broad-except
self._http_response_error_handler(exception, "Namespaces")
self._http_response_error_handler(exception)
raise exception
else:
kwargs["content_type"] = content_type if content_type else "application/json; charset=utf-8"
try:
await self._publish(events, channel_name=channel_name, **kwargs)
except Exception as exception:
self._http_response_error_handler(exception, "Basic")
self._http_response_error_handler(exception)
raise exception

def _http_response_error_handler(self, exception, level):
def _http_response_error_handler(self, exception):
if isinstance(exception, HttpResponseError):
if exception.status_code == 400:
raise HttpResponseError("Invalid event data. Please check the data and try again.") from exception
if exception.status_code == 404:
raise ResourceNotFoundError(
"Resource not found. "
f"Please check that the tier you are using, corresponds to the correct "
"Please check that the tier you are using, corresponds to the correct "
"endpoint and/or topic name."
) from exception
raise exception
Expand Down
3 changes: 2 additions & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def __init__(
)

def __repr__(self) -> str:
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, subscription={self._subscription}, credential type={type(self._credential)}>"
return f"<EventGridConsumerClient: namespace_topic={self._namespace}, \
subscription={self._subscription}, credential type={type(self._credential)}>"


def patch_sdk():
Expand Down
4 changes: 1 addition & 3 deletions sdk/eventgrid/azure-eventgrid/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[tool.azure-sdk-build]
pyright = false
verifytypes = false
strict_sphinx = false
pylint = false
verifytypes = false

0 comments on commit 6190bde

Please sign in to comment.