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

[AutoPR azure-ai-vision-imageanalysis] Batch 1 sdk gen test #8291

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions sdk/vision/azure-ai-vision-imageanalysis/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include *.md
include LICENSE
include azure/ai/vision/imageanalysis/py.typed
recursive-include tests *.py *.md sample.jpg
recursive-include samples *.py *.md sample.jpg run_all_samples.cmd run_all_samples.ps1
recursive-include tests *.py
recursive-include samples *.py *.md
include azure/__init__.py
include azure/ai/__init__.py
include azure/ai/vision/__init__.py
8 changes: 4 additions & 4 deletions sdk/vision/azure-ai-vision-imageanalysis/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"commit": "bef35d01d2572ba131d7f2d4cd8d6313ec649525",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/cognitiveservices/Vision.ImageAnalysis",
"@azure-tools/typespec-python": "0.15.0"
"commit": "854273eb1c13593ace77b57fabfb0d2f2b32f4ac",
"repository_url": "https://github.com/test-repo-billy/azure-rest-api-specs",
"typespec_src": "specification/ai/ImageAnalysis",
"@azure-tools/typespec-python": "0.29.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._patch import ImageAnalysisClient
from ._client import ImageAnalysisClient
from ._version import VERSION

__version__ = VERSION


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__ = [
"ImageAnalysisClient",
]

__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 @@ -476,6 +476,9 @@ def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typin

class Model(_MyMutableMapping):
_is_model = True
# label whether current class's _attr_to_rest_field has been calculated
# could not see _attr_to_rest_field directly because subclass inherits it from parent class
_calculated: typing.Set[str] = set()

def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None:
class_name = self.__class__.__name__
Expand Down Expand Up @@ -508,24 +511,27 @@ def copy(self) -> "Model":
return Model(self.__dict__)

def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: disable=unused-argument
# we know the last three classes in mro are going to be 'Model', 'dict', and 'object'
mros = cls.__mro__[:-3][::-1] # ignore model, dict, and object parents, and reverse the mro order
attr_to_rest_field: typing.Dict[str, _RestField] = { # map attribute name to rest_field property
k: v for mro_class in mros for k, v in mro_class.__dict__.items() if k[0] != "_" and hasattr(v, "_type")
}
annotations = {
k: v
for mro_class in mros
if hasattr(mro_class, "__annotations__") # pylint: disable=no-member
for k, v in mro_class.__annotations__.items() # pylint: disable=no-member
}
for attr, rf in attr_to_rest_field.items():
rf._module = cls.__module__
if not rf._type:
rf._type = rf._get_deserialize_callable_from_annotation(annotations.get(attr, None))
if not rf._rest_name_input:
rf._rest_name_input = attr
cls._attr_to_rest_field: typing.Dict[str, _RestField] = dict(attr_to_rest_field.items())
if f"{cls.__module__}.{cls.__qualname__}" not in cls._calculated:
# we know the last nine classes in mro are going to be 'Model', '_MyMutableMapping', 'MutableMapping',
# 'Mapping', 'Collection', 'Sized', 'Iterable', 'Container' and 'object'
mros = cls.__mro__[:-9][::-1] # ignore parents, and reverse the mro order
attr_to_rest_field: typing.Dict[str, _RestField] = { # map attribute name to rest_field property
k: v for mro_class in mros for k, v in mro_class.__dict__.items() if k[0] != "_" and hasattr(v, "_type")
}
annotations = {
k: v
for mro_class in mros
if hasattr(mro_class, "__annotations__") # pylint: disable=no-member
for k, v in mro_class.__annotations__.items() # pylint: disable=no-member
}
for attr, rf in attr_to_rest_field.items():
rf._module = cls.__module__
if not rf._type:
rf._type = rf._get_deserialize_callable_from_annotation(annotations.get(attr, None))
if not rf._rest_name_input:
rf._rest_name_input = attr
cls._attr_to_rest_field: typing.Dict[str, _RestField] = dict(attr_to_rest_field.items())
cls._calculated.add(f"{cls.__module__}.{cls.__qualname__}")

return super().__new__(cls) # pylint: disable=no-value-for-parameter

Expand Down Expand Up @@ -563,6 +569,7 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing.
"""

result = {}
readonly_props = []
if exclude_readonly:
readonly_props = [p._rest_name for p in self._attr_to_rest_field.values() if _is_readonly(p)]
for k, v in self.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
ResourceExistsError,
ResourceNotFoundError,
ResourceNotModifiedError,
StreamClosedError,
StreamConsumedError,
map_error,
)
from azure.core.pipeline import PipelineResponse
Expand Down Expand Up @@ -173,119 +175,6 @@ def _analyze_from_image_data(
:return: ImageAnalysisResult. The ImageAnalysisResult is compatible with MutableMapping
:rtype: ~azure.ai.vision.imageanalysis.models.ImageAnalysisResult
:raises ~azure.core.exceptions.HttpResponseError:

Example:
.. code-block:: python

# response body for status code(s): 200
response == {
"metadata": {
"height": 0,
"width": 0
},
"modelVersion": "str",
"captionResult": {
"confidence": 0.0,
"text": "str"
},
"denseCaptionsResult": {
"values": [
{
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
},
"confidence": 0.0,
"text": "str"
}
]
},
"objectsResult": {
"values": [
{
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
},
"tags": [
{
"confidence": 0.0,
"name": "str"
}
]
}
]
},
"peopleResult": {
"values": [
{
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
},
"confidence": 0.0
}
]
},
"readResult": {
"blocks": [
{
"lines": [
{
"boundingPolygon": [
{
"x": 0,
"y": 0
}
],
"text": "str",
"words": [
{
"boundingPolygon": [
{
"x":
0,
"y":
0
}
],
"confidence": 0.0,
"text": "str"
}
]
}
]
}
]
},
"smartCropsResult": {
"values": [
{
"aspectRatio": 0.0,
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
}
}
]
},
"tagsResult": {
"values": [
{
"confidence": 0.0,
"name": "str"
}
]
}
}
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
Expand Down Expand Up @@ -329,7 +218,10 @@ def _analyze_from_image_data(

if response.status_code not in [200]:
if _stream:
response.read() # Load the body in memory and close the socket
try:
response.read() # Load the body in memory and close the socket
except (StreamConsumedError, StreamClosedError):
pass
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

Expand Down Expand Up @@ -433,124 +325,6 @@ def _analyze_from_url(
:return: ImageAnalysisResult. The ImageAnalysisResult is compatible with MutableMapping
:rtype: ~azure.ai.vision.imageanalysis.models.ImageAnalysisResult
:raises ~azure.core.exceptions.HttpResponseError:

Example:
.. code-block:: python

# JSON input template you can fill out and use as your body input.
image_url = {
"url": "str"
}

# response body for status code(s): 200
response == {
"metadata": {
"height": 0,
"width": 0
},
"modelVersion": "str",
"captionResult": {
"confidence": 0.0,
"text": "str"
},
"denseCaptionsResult": {
"values": [
{
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
},
"confidence": 0.0,
"text": "str"
}
]
},
"objectsResult": {
"values": [
{
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
},
"tags": [
{
"confidence": 0.0,
"name": "str"
}
]
}
]
},
"peopleResult": {
"values": [
{
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
},
"confidence": 0.0
}
]
},
"readResult": {
"blocks": [
{
"lines": [
{
"boundingPolygon": [
{
"x": 0,
"y": 0
}
],
"text": "str",
"words": [
{
"boundingPolygon": [
{
"x":
0,
"y":
0
}
],
"confidence": 0.0,
"text": "str"
}
]
}
]
}
]
},
"smartCropsResult": {
"values": [
{
"aspectRatio": 0.0,
"boundingBox": {
"h": 0,
"w": 0,
"x": 0,
"y": 0
}
}
]
},
"tagsResult": {
"values": [
{
"confidence": 0.0,
"name": "str"
}
]
}
}
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
Expand Down Expand Up @@ -599,7 +373,10 @@ def _analyze_from_url(

if response.status_code not in [200]:
if _stream:
response.read() # Load the body in memory and close the socket
try:
response.read() # Load the body in memory and close the socket
except (StreamConsumedError, StreamClosedError):
pass
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

Expand Down
Loading