Skip to content

Commit 792b2fa

Browse files
authored
chore!: promote Vision to v2 (#7904)
* chore!: promote Vision to v2 * fix snippet tests, throw exception in ServiceBuilder * fix vision tests * fix cs * fix phpstan
1 parent 49efa37 commit 792b2fa

193 files changed

Lines changed: 589 additions & 15388 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

β€ŽCore/src/ServiceBuilder.phpβ€Ž

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
use Google\Cloud\Logging\LoggingClient;
2727
use Google\Cloud\PubSub\PubSubClient;
2828
use Google\Cloud\Spanner\SpannerClient;
29-
use Google\Cloud\Speech\V2\Client\SpeechClient;
3029
use Google\Cloud\Speech\SpeechClient as DeprecatedSpeechClient;
30+
use Google\Cloud\Speech\V2\Client\SpeechClient;
3131
use Google\Cloud\Storage\StorageClient;
3232
use Google\Cloud\Trace\TraceClient;
3333
use Google\Cloud\Translate\V2\TranslateClient as DeprecatedTranslateClient;
3434
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
35-
use Google\Cloud\Vision\VisionClient;
35+
use Google\Cloud\Vision\V1\Client\ImageAnnotatorClient;
36+
use Google\Cloud\Vision\VisionClient as DeprecatedVisionClient;
3637
use Psr\Cache\CacheItemPoolInterface;
3738

3839
/**
@@ -326,23 +327,19 @@ public function trace(array $config = [])
326327
}
327328

328329
/**
329-
* Google Cloud Vision allows you to understand the content of an image,
330-
* classify images into categories, detect text, objects, faces and more.
331-
* Find more information at the
332-
* [Google Cloud Vision docs](https://cloud.google.com/vision/docs/).
333-
*
334-
* Example:
335-
* ```
336-
* $vision = $cloud->vision();
337-
* ```
338-
*
339-
* @param array $config [optional] Configuration options. See
340-
* {@see \Google\Cloud\Core\ServiceBuilder::__construct()} for the available options.
341-
* @return VisionClient
330+
* @deprecated
331+
* @see ImageAnnotatorClient
332+
* @throws \BadMethodCallException
342333
*/
343334
public function vision(array $config = [])
344335
{
345-
return $this->createClient(VisionClient::class, 'vision', $config);
336+
if (class_exists(DeprecatedVisionClient::class)) {
337+
return $this->createClient(DeprecatedVisionClient::class, 'vision', $config);
338+
}
339+
throw new \BadMethodCallException(sprintf(
340+
'This method is no longer supported, create %s directly instead.',
341+
ImageAnnotatorClient::class
342+
));
346343
}
347344

348345
/**

β€ŽCore/tests/Snippet/ServiceBuilderTest.phpβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Google\Cloud\Spanner\SpannerClient;
2929
use Google\Cloud\Storage\StorageClient;
3030
use Google\Cloud\Trace\TraceClient;
31-
use Google\Cloud\Vision\VisionClient;
3231

3332
/**
3433
* @group root
@@ -60,7 +59,6 @@ public function serviceBuilderMethods()
6059
['spanner', SpannerClient::class, 'spanner', true],
6160
['storage', StorageClient::class, 'storage'],
6261
['trace', TraceClient::class, 'trace'],
63-
['vision', VisionClient::class, 'vision'],
6462
];
6563
}
6664

β€ŽCore/tests/Unit/ServiceBuilderTest.phpβ€Ž

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Google\Cloud\Spanner\SpannerClient;
2828
use Google\Cloud\Storage\StorageClient;
2929
use Google\Cloud\Core\Tests\Unit\Fixtures;
30-
use Google\Cloud\Vision\VisionClient;
3130
use GuzzleHttp\Psr7\Response;
3231
use PHPUnit\Framework\TestCase;
3332
use Psr\Http\Message\RequestInterface;
@@ -170,9 +169,6 @@ public function serviceProvider()
170169
], [
171170
'storage',
172171
StorageClient::class
173-
], [
174-
'vision',
175-
VisionClient::class
176172
]
177173
];
178174
}

β€ŽCore/tests/Unit/ServicesNotFoundTest.phpβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ private static function getApis()
7979
"Storage",
8080
"Trace",
8181
"VideoIntelligence",
82-
"Vision",
8382
];
8483
}
8584

@@ -94,7 +93,6 @@ public function serviceBuilderMethods()
9493
['spanner'],
9594
['storage'],
9695
['trace'],
97-
['vision'],
9896
];
9997
}
10098

β€ŽVision/.OwlBot.yamlβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
deep-copy-regex:
2-
- source: /google/cloud/vision/v1/.*-php/(.*)
3-
dest: /owl-bot-staging/Vision/V1/$1
2+
- source: /google/cloud/vision/(v1)/.*-php/(.*)
3+
dest: /owl-bot-staging/Vision/$1/$2
44
api-name: Vision

β€ŽVision/owlbot.pyβ€Ž

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,8 +16,9 @@
1616

1717
import logging
1818
from pathlib import Path
19-
import synthtool as s
2019
import subprocess
20+
21+
import synthtool as s
2122
from synthtool.languages import php
2223
from synthtool import _tracked_paths
2324

@@ -29,65 +30,27 @@
2930
# Added so that we can pass copy_excludes in the owlbot_main() call
3031
_tracked_paths.add(src)
3132

32-
# Exclude partial veneer files.
33-
php.owlbot_main(
34-
src=src,
35-
dest=dest,
36-
copy_excludes=[
37-
src / "*/src/V1/ProductSearchClient.php",
38-
src / "*/src/V1/ImageAnnotatorClient.php",
39-
]
40-
)
41-
42-
# Change the wording for the deprecation warning.
43-
s.replace(
44-
'src/*/*_*.php',
45-
r'will be removed in the next major release',
46-
'will be removed in a future release')
47-
48-
### [START] protect vision backwards compatibility
49-
50-
# format generated clients
51-
subprocess.run([
52-
'git',
53-
'apply',
54-
'.owlbot/safesearchannotation.patch'])
55-
56-
### [START] protoc backwards compatibility fixes
57-
58-
# roll back to private properties.
59-
s.replace(
60-
"src/**/V*/**/*.php",
61-
r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$",
62-
r"""Generated from protobuf field \1
63-
*/
64-
private $""")
65-
66-
# Replace "Unwrapped" with "Value" for method names.
67-
s.replace(
68-
"src/**/V*/**/*.php",
69-
r"public function ([s|g]\w{3,})Unwrapped",
70-
r"public function \1Value"
71-
)
72-
73-
### [END] protoc backwards compatibility fixes
33+
php.owlbot_main(src=src, dest=dest)
7434

75-
# fix relative cloud.google.com links
35+
# remove class_alias code
7636
s.replace(
77-
"src/**/V*/**/*.php",
78-
r"(.{0,})\]\((/.{0,})\)",
79-
r"\1](https://cloud.google.com\2)"
80-
)
37+
"src/V*/**/*.php",
38+
r"^// Adding a class alias for backwards compatibility with the previous class name.$"
39+
+ "\n"
40+
+ r"^class_alias\(.*\);$"
41+
+ "\n",
42+
'')
8143

8244
# format generated clients
8345
subprocess.run([
84-
'npx',
85-
'-y',
86-
'-p',
87-
'@prettier/plugin-php@^0.16',
46+
'npm',
47+
'exec',
48+
'--yes',
49+
'--package=@prettier/plugin-php@^0.16',
50+
'--',
8851
'prettier',
89-
'**/Gapic/*',
52+
'**/Client/*',
9053
'--write',
9154
'--parser=php',
9255
'--single-quote',
93-
'--print-width=80'])
56+
'--print-width=120'])

β€ŽVision/phpunit-snippets.xml.distβ€Ž

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)