Skip to content

Commit 9fb905c

Browse files
authored
Re-generate Image Analysis SDK with: tox run -e generate -c ..\..\..\eng\tox\tox.ini --root . (#33772)
* After running tox run -e generate -c ..\..\..\eng\tox\tox.ini --root . * Run again, this time with added pyproject.toml * Pick up new TypeSpec change, with prop name `list` instead of `values` * Update samples & test to use 'list' prop name instead of 'values' * No need to suppress mypy `attr-defined` error. Update README.md code snippets * Use uniform style in sample code * Hand fix emitter bug (GitHub issue filed). Remove mypy.ini (no longer needed). Fix code style I don't like * Fix pylint issues
1 parent da79b36 commit 9fb905c

28 files changed

+455
-460
lines changed

sdk/vision/azure-ai-vision-imageanalysis/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ from azure.ai.vision.imageanalysis import ImageAnalysisClient
5353
from azure.ai.vision.imageanalysis.models import VisualFeatures
5454
from azure.core.credentials import AzureKeyCredential
5555

56-
# Set the values of your computer vision endpoint and computer vision key
56+
# Set the values of your computer vision endpoint and computer vision key
5757
# as environment variables:
5858
try:
5959
endpoint = os.environ["VISION_ENDPOINT"]
@@ -65,8 +65,8 @@ except KeyError:
6565

6666
# Create an Image Analysis client for synchronous operations
6767
client = ImageAnalysisClient(
68-
endpoint = endpoint,
69-
credential = AzureKeyCredential(key)
68+
endpoint=endpoint,
69+
credential=AzureKeyCredential(key)
7070
)
7171
```
7272

@@ -135,14 +135,14 @@ Notes:
135135

136136
```python
137137
# Load image to analyze into a 'bytes' object
138-
with open("sample.jpg", 'rb') as f:
138+
with open("sample.jpg", "rb") as f:
139139
image_data = f.read()
140140

141141
# Get a caption for the image. This will be a synchronously (blocking) call.
142142
result = client.analyze(
143-
image_data = image_data,
144-
visual_features = [ VisualFeatures.CAPTION ],
145-
gender_neutral_caption = True # Optional (default is False)
143+
image_data=image_data,
144+
visual_features=[VisualFeatures.CAPTION],
145+
gender_neutral_caption=True, # Optional (default is False)
146146
)
147147

148148
# Print caption results to the console
@@ -165,9 +165,9 @@ This example is similar to the above, expect it calls the `analyze` method and p
165165
```python
166166
# Get a caption for the image. This will be a synchronously (blocking) call.
167167
result = client.analyze(
168-
image_url = "https://aka.ms/azsdk/image-analysis/sample.jpg",
169-
visual_features = [ VisualFeatures.CAPTION ],
170-
gender_neutral_caption = True # Optional (default is False)
168+
image_url="https://aka.ms/azsdk/image-analysis/sample.jpg",
169+
visual_features=[VisualFeatures.CAPTION],
170+
gender_neutral_caption=True, # Optional (default is False)
171171
)
172172

173173
# Print caption results to the console
@@ -187,13 +187,13 @@ This example demonstrates how to extract printed or hand-written text for the im
187187

188188
```python
189189
# Load image to analyze into a 'bytes' object
190-
with open("sample.jpg", 'rb') as f:
190+
with open("sample.jpg", "rb") as f:
191191
image_data = f.read()
192192

193193
# Extract text (OCR) from an image stream. This will be a synchronously (blocking) call.
194194
result = client.analyze(
195-
image_data = image_data,
196-
visual_features = [ VisualFeatures.READ ]
195+
image_data=image_data,
196+
visual_features=[VisualFeatures.READ]
197197
)
198198

199199
# Print text (OCR) analysis results to the console
@@ -221,8 +221,8 @@ This example is similar to the above, expect it calls the `analyze` method and p
221221
```python
222222
# Extract text (OCR) from an image stream. This will be a synchronously (blocking) call.
223223
result = client.analyze(
224-
image_url = "https://aka.ms/azsdk/image-analysis/sample.jpg",
225-
visual_features = [ VisualFeatures.READ ]
224+
image_url="https://aka.ms/azsdk/image-analysis/sample.jpg",
225+
visual_features=[VisualFeatures.READ]
226226
)
227227

228228
# Print text (OCR) analysis results to the console
@@ -277,21 +277,21 @@ The client uses the standard [Python logging library](https://docs.python.org/3/
277277
import sys
278278
import logging
279279

280-
# Acquire the logger for this client library. Use 'azure' to affect both
280+
# Acquire the logger for this client library. Use 'azure' to affect both
281281
# 'azure.core` and `azure.ai.vision.imageanalysis' libraries.
282-
logger = logging.getLogger('azure')
282+
logger = logging.getLogger("azure")
283283

284284
# Set the desired logging level. logging.INFO or logging.DEBUG are good options.
285285
logger.setLevel(logging.INFO)
286286

287287
# Direct logging output to stdout (the default):
288-
handler = logging.StreamHandler(stream = sys.stdout)
288+
handler = logging.StreamHandler(stream=sys.stdout)
289289
# Or direct logging output to a file:
290290
# handler = logging.FileHandler(filename = 'sample.log')
291291
logger.addHandler(handler)
292292

293293
# Optional: change the default logging format. Here we add a timestamp.
294-
formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')
294+
formatter = logging.Formatter("%(asctime)s:%(levelname)s:%(name)s:%(message)s")
295295
handler.setFormatter(formatter)
296296
```
297297

@@ -304,9 +304,9 @@ By default logs redact the values of URL query strings, the values of some HTTP
304304
```python
305305
# Create an Image Analysis client with none redacted log
306306
client = ImageAnalysisClient(
307-
endpoint = endpoint,
308-
credential = AzureKeyCredential(key),
309-
logging_enable = True
307+
endpoint=endpoint,
308+
credential=AzureKeyCredential(key),
309+
logging_enable=True
310310
)
311311
```
312312

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/__init__.py

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

9-
from ._client import ImageAnalysisClient
9+
from ._patch import ImageAnalysisClient
1010
from ._version import VERSION
1111

1212
__version__ = VERSION
1313

14-
try:
15-
from ._patch import __all__ as _patch_all
16-
from ._patch import * # pylint: disable=unused-wildcard-import
17-
except ImportError:
18-
_patch_all = []
14+
1915
from ._patch import patch_sdk as _patch_sdk
2016

2117
__all__ = [
2218
"ImageAnalysisClient",
2319
]
24-
__all__.extend([p for p in _patch_all if p not in __all__])
20+
2521

2622
_patch_sdk()

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/_operations/_operations.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ def _analyze_from_buffer(
147147
:paramtype visual_features: list[str or ~azure.ai.vision.imageanalysis.models.VisualFeatures]
148148
:keyword language: The desired language for result generation (a two-letter language code).
149149
If this option is not specified, the default value 'en' is used (English).
150-
See https://aka.ms/cv-languages for a list of supported languages.
151-
At the moment, only tags can be generated in non-English languages. Default value is None.
150+
See https://aka.ms/cv-languages for a list of supported languages. Default value is None.
152151
:paramtype language: str
153152
:keyword gender_neutral_caption: Boolean flag for enabling gender-neutral captioning for
154153
Caption and Dense Captions features.
@@ -468,8 +467,7 @@ def _analyze_from_url(
468467
:paramtype visual_features: list[str or ~azure.ai.vision.imageanalysis.models.VisualFeatures]
469468
:keyword language: The desired language for result generation (a two-letter language code).
470469
If this option is not specified, the default value 'en' is used (English).
471-
See https://aka.ms/cv-languages for a list of supported languages.
472-
At the moment, only tags can be generated in non-English languages. Default value is None.
470+
See https://aka.ms/cv-languages for a list of supported languages. Default value is None.
473471
:paramtype language: str
474472
:keyword gender_neutral_caption: Boolean flag for enabling gender-neutral captioning for
475473
Caption and Dense Captions features.

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/_operations/_patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# --------------------------------------------------------------------------
66
from typing import List
77

8-
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
8+
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
9+
910

1011
def patch_sdk():
1112
"""Do not remove from this file.

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/_patch.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ._operations._operations import ImageAnalysisClientOperationsMixin
2222
from ._client import ImageAnalysisClient as ImageAnalysisClientGenerated
2323

24+
2425
class ImageAnalysisClient(ImageAnalysisClientGenerated):
2526
"""ImageAnalysisClient.
2627
@@ -115,29 +116,32 @@ def analyze(
115116
visual_features_impl: List[Union[str, _models.VisualFeatures]] = list(visual_features)
116117

117118
if image_url is not None:
118-
return ImageAnalysisClientOperationsMixin._analyze_from_url( # pylint: disable=protected-access
119+
return ImageAnalysisClientOperationsMixin._analyze_from_url( # pylint: disable=protected-access
119120
self,
120-
image_content = _models._models.ImageUrl(url = image_url), # pylint: disable=protected-access
121-
visual_features = visual_features_impl,
122-
language = language,
123-
gender_neutral_caption = gender_neutral_caption,
124-
smart_crops_aspect_ratios = smart_crops_aspect_ratios,
125-
model_version = model_version,
126-
**kwargs)
121+
image_content=_models._models.ImageUrl(url=image_url), # pylint: disable=protected-access
122+
visual_features=visual_features_impl,
123+
language=language,
124+
gender_neutral_caption=gender_neutral_caption,
125+
smart_crops_aspect_ratios=smart_crops_aspect_ratios,
126+
model_version=model_version,
127+
**kwargs
128+
)
127129

128130
if image_data is not None:
129-
return ImageAnalysisClientOperationsMixin._analyze_from_buffer( # pylint: disable=protected-access
131+
return ImageAnalysisClientOperationsMixin._analyze_from_buffer( # pylint: disable=protected-access
130132
self,
131-
image_content = image_data,
132-
visual_features = visual_features_impl,
133-
language = language,
134-
gender_neutral_caption = gender_neutral_caption,
135-
smart_crops_aspect_ratios = smart_crops_aspect_ratios,
136-
model_version = model_version,
137-
**kwargs)
133+
image_content=image_data,
134+
visual_features=visual_features_impl,
135+
language=language,
136+
gender_neutral_caption=gender_neutral_caption,
137+
smart_crops_aspect_ratios=smart_crops_aspect_ratios,
138+
model_version=model_version,
139+
**kwargs
140+
)
138141

139142
raise ValueError("Either image_data or image_url must be specified.")
140143

144+
141145
__all__: List[str] = [
142146
"ImageAnalysisClient"
143147
] # Add all objects you want publicly available to users at this package level

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/aio/__init__.py

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

9-
from ._client import ImageAnalysisClient
9+
from ._patch import ImageAnalysisClient
10+
1011

11-
try:
12-
from ._patch import __all__ as _patch_all
13-
from ._patch import * # pylint: disable=unused-wildcard-import
14-
except ImportError:
15-
_patch_all = []
1612
from ._patch import patch_sdk as _patch_sdk
1713

1814
__all__ = [
1915
"ImageAnalysisClient",
2016
]
21-
__all__.extend([p for p in _patch_all if p not in __all__])
17+
2218

2319
_patch_sdk()

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/aio/_operations/_patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# --------------------------------------------------------------------------
66
from typing import List
77

8-
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
8+
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
9+
910

1011
def patch_sdk():
1112
"""Do not remove from this file.

sdk/vision/azure-ai-vision-imageanalysis/azure/ai/vision/imageanalysis/aio/_patch.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ._operations._operations import ImageAnalysisClientOperationsMixin
2222
from ._client import ImageAnalysisClient as ImageAnalysisClientGenerated
2323

24+
2425
class ImageAnalysisClient(ImageAnalysisClientGenerated):
2526
"""ImageAnalysisClient.
2627
@@ -115,29 +116,32 @@ async def analyze(
115116
visual_features_impl: List[Union[str, _models.VisualFeatures]] = list(visual_features)
116117

117118
if image_url is not None:
118-
return await ImageAnalysisClientOperationsMixin._analyze_from_url( # pylint: disable=protected-access
119+
return await ImageAnalysisClientOperationsMixin._analyze_from_url( # pylint: disable=protected-access
119120
self,
120-
image_content = _models._models.ImageUrl(url = image_url), # pylint: disable=protected-access
121-
visual_features = visual_features_impl,
122-
language = language,
123-
gender_neutral_caption = gender_neutral_caption,
124-
smart_crops_aspect_ratios = smart_crops_aspect_ratios,
125-
model_version = model_version,
126-
**kwargs)
121+
image_content=_models._models.ImageUrl(url=image_url), # pylint: disable=protected-access
122+
visual_features=visual_features_impl,
123+
language=language,
124+
gender_neutral_caption=gender_neutral_caption,
125+
smart_crops_aspect_ratios=smart_crops_aspect_ratios,
126+
model_version=model_version,
127+
**kwargs
128+
)
127129

128130
if image_data is not None:
129-
return await ImageAnalysisClientOperationsMixin._analyze_from_buffer( # pylint: disable=protected-access
131+
return await ImageAnalysisClientOperationsMixin._analyze_from_buffer( # pylint: disable=protected-access
130132
self,
131-
image_content = image_data,
132-
visual_features = visual_features_impl,
133-
language = language,
134-
gender_neutral_caption = gender_neutral_caption,
135-
smart_crops_aspect_ratios = smart_crops_aspect_ratios,
136-
model_version = model_version,
137-
**kwargs)
133+
image_content=image_data,
134+
visual_features=visual_features_impl,
135+
language=language,
136+
gender_neutral_caption=gender_neutral_caption,
137+
smart_crops_aspect_ratios=smart_crops_aspect_ratios,
138+
model_version=model_version,
139+
**kwargs
140+
)
138141

139142
raise ValueError("Either image_data or image_url must be specified.")
140143

144+
141145
__all__: List[str] = [
142146
"ImageAnalysisClient"
143147
] # Add all objects you want publicly available to users at this package level

0 commit comments

Comments
 (0)