Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit cf3d353

Browse files
feat!: migrate to use microgen (#52)
* feat!: migrate to use microgen * chore: update code * chore: lint
1 parent 886a007 commit cf3d353

294 files changed

Lines changed: 67081 additions & 68165 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.

.coveragerc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ branch = True
2121
[report]
2222
fail_under = 100
2323
show_missing = True
24+
omit = google/cloud/vision/__init__.py
2425
exclude_lines =
2526
# Re-enable the standard pragma
2627
pragma: NO COVER
2728
# Ignore debug-only repr
2829
def __repr__
29-
# Ignore abstract methods
30-
raise NotImplementedError
31-
omit =
32-
*/gapic/*.py
33-
*/proto/*.py
34-
*/core/*.py
35-
*/site-packages/*.py
30+
# Ignore pkg_resources exceptions.
31+
# This is added at the module level as a safeguard for if someone
32+
# generates the code and tries to run it without pip installing. This
33+
# makes it virtually impossible to test properly.
34+
except pkg_resources.DistributionNotFound

.kokoro/populate-secrets.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Copyright 2020 Google LLC.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
function now { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n' ;}
19+
function msg { println "$*" >&2 ;}
20+
function println { printf '%s\n' "$(now) $*" ;}
21+
22+
23+
# Populates requested secrets set in SECRET_MANAGER_KEYS from service account:
24+
# kokoro-trampoline@cloud-devrel-kokoro-resources.iam.gserviceaccount.com
25+
SECRET_LOCATION="${KOKORO_GFILE_DIR}/secret_manager"
26+
msg "Creating folder on disk for secrets: ${SECRET_LOCATION}"
27+
mkdir -p ${SECRET_LOCATION}
28+
for key in $(echo ${SECRET_MANAGER_KEYS} | sed "s/,/ /g")
29+
do
30+
msg "Retrieving secret ${key}"
31+
docker run --entrypoint=gcloud \
32+
--volume=${KOKORO_GFILE_DIR}:${KOKORO_GFILE_DIR} \
33+
gcr.io/google.com/cloudsdktool/cloud-sdk \
34+
secrets versions access latest \
35+
--project cloud-devrel-kokoro-resources \
36+
--secret ${key} > \
37+
"${SECRET_LOCATION}/${key}"
38+
if [[ $? == 0 ]]; then
39+
msg "Secret written to ${SECRET_LOCATION}/${key}"
40+
else
41+
msg "Error retrieving secret ${key}"
42+
fi
43+
done

.kokoro/release/common.cfg

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,18 @@ env_vars: {
2323
value: "github/python-vision/.kokoro/release.sh"
2424
}
2525

26-
# Fetch the token needed for reporting release status to GitHub
27-
before_action {
28-
fetch_keystore {
29-
keystore_resource {
30-
keystore_config_id: 73713
31-
keyname: "yoshi-automation-github-key"
32-
}
33-
}
34-
}
35-
36-
# Fetch PyPI password
37-
before_action {
38-
fetch_keystore {
39-
keystore_resource {
40-
keystore_config_id: 73713
41-
keyname: "google_cloud_pypi_password"
42-
}
43-
}
44-
}
45-
46-
# Fetch magictoken to use with Magic Github Proxy
47-
before_action {
48-
fetch_keystore {
49-
keystore_resource {
50-
keystore_config_id: 73713
51-
keyname: "releasetool-magictoken"
52-
}
53-
}
26+
# Fetch PyPI password
27+
before_action {
28+
fetch_keystore {
29+
keystore_resource {
30+
keystore_config_id: 73713
31+
keyname: "google_cloud_pypi_password"
32+
}
33+
}
5434
}
5535

56-
# Fetch api key to use with Magic Github Proxy
57-
before_action {
58-
fetch_keystore {
59-
keystore_resource {
60-
keystore_config_id: 73713
61-
keyname: "magic-github-proxy-api-key"
62-
}
63-
}
64-
}
36+
# Tokens needed to report release status back to GitHub
37+
env_vars: {
38+
key: "SECRET_MANAGER_KEYS"
39+
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem"
40+
}

.kokoro/trampoline.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515

1616
set -eo pipefail
1717

18-
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" || ret_code=$?
18+
# Always run the cleanup script, regardless of the success of bouncing into
19+
# the container.
20+
function cleanup() {
21+
chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
22+
${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
23+
echo "cleanup";
24+
}
25+
trap cleanup EXIT
1926

20-
chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
21-
${KOKORO_GFILE_DIR}/trampoline_cleanup.sh || true
22-
23-
exit ${ret_code}
27+
$(dirname $0)/populate-secrets.sh # Secret Manager secrets.
28+
python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"

CONTRIBUTING.rst

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,6 @@ We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.
8080

8181
.. nox: https://pypi.org/project/nox/
8282
83-
Note on Editable Installs / Develop Mode
84-
========================================
85-
86-
- As mentioned previously, using ``setuptools`` in `develop mode`_
87-
or a ``pip`` `editable install`_ is not possible with this
88-
library. This is because this library uses `namespace packages`_.
89-
For context see `Issue #2316`_ and the relevant `PyPA issue`_.
90-
91-
Since ``editable`` / ``develop`` mode can't be used, packages
92-
need to be installed directly. Hence your changes to the source
93-
tree don't get incorporated into the **already installed**
94-
package.
95-
96-
.. _namespace packages: https://www.python.org/dev/peps/pep-0420/
97-
.. _Issue #2316: https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2316
98-
.. _PyPA issue: https://github.com/pypa/packaging-problems/issues/12
99-
.. _develop mode: https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
100-
.. _editable install: https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs
101-
10283
*****************************************
10384
I'm getting weird errors... Can you help?
10485
*****************************************

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ dependencies.
6161

6262
Supported Python Versions
6363
^^^^^^^^^^^^^^^^^^^^^^^^^
64-
Python >= 3.5
64+
Python >= 3.6
6565

6666
Deprecated Python Versions
6767
^^^^^^^^^^^^^^^^^^^^^^^^^^
68-
Python == 2.7. Python 2.7 support will be removed on January 1, 2020.
68+
Python == 2.7.
69+
70+
The last version of this library compatible with Python 2.7 is google-cloud-vision==1.0.0.
6971

7072
RaspberryPi ARM devices
7173
^^^^^^^^^^^^^^^^^^^^^^^

UPGRADING.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# 2.0.0 Migration Guide
2+
3+
The 2.0 release of the `google-cloud-vision` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage.
4+
5+
If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-vision/issues).
6+
7+
## Supported Python Versions
8+
9+
> **WARNING**: Breaking change
10+
11+
The 2.0.0 release requires Python 3.6+.
12+
13+
14+
## Method Calls
15+
16+
> **WARNING**: Breaking change
17+
18+
Methods expect request objects. We provide a script that will convert most common use cases.
19+
20+
* Install the library
21+
22+
```py
23+
python3 -m pip install google-cloud-vision
24+
```
25+
26+
* The script `fixup_vision_v1_keywords.py` is shipped with the library. It expects
27+
an input directory (with the code to convert) and an empty destination directory.
28+
29+
```sh
30+
$ fixup_vision_v1_keywords.py --input-directory .samples/ --output-directory samples/
31+
```
32+
33+
**Before:**
34+
```py
35+
from google.cloud import vision_v1
36+
37+
client = vision_v1.ProductSearchClient()
38+
39+
product_set = client.get_product_set("name")
40+
```
41+
42+
43+
**After:**
44+
```py
45+
from google.cloud import vision_v1
46+
47+
client = vision_v1.ProductSearchClient()
48+
49+
product_set = client.get_product_set(request={"name": "name"})
50+
```
51+
52+
### More Details
53+
54+
In `google-cloud-vision<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters.
55+
56+
**Before:**
57+
```py
58+
def create_product_set(
59+
self,
60+
parent,
61+
product_set,
62+
product_set_id=None,
63+
retry=google.api_core.gapic_v1.method.DEFAULT,
64+
timeout=google.api_core.gapic_v1.method.DEFAULT,
65+
metadata=None,
66+
):
67+
```
68+
69+
In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional.
70+
71+
Some methods have additional keyword only parameters. The available parameters depend on the `google.api.method_signature` annotation specified by the API producer.
72+
73+
74+
**After:**
75+
```py
76+
def create_product_set(
77+
self,
78+
request: product_search_service.CreateProductSetRequest = None,
79+
*,
80+
parent: str = None,
81+
product_set: product_search_service.ProductSet = None,
82+
product_set_id: str = None,
83+
retry: retries.Retry = gapic_v1.method.DEFAULT,
84+
timeout: float = None,
85+
metadata: Sequence[Tuple[str, str]] = (),
86+
) -> product_search_service.ProductSet:
87+
```
88+
89+
> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive.
90+
> Passing both will result in an error.
91+
92+
93+
Both of these calls are valid:
94+
95+
```py
96+
response = client.create_product_set(
97+
request={
98+
"parent": parent,
99+
"product_set_id": product_set_id,
100+
"product_set": product_set
101+
}
102+
)
103+
```
104+
105+
```py
106+
response = client.create_product_set(
107+
parent=parent,
108+
product_set_id=product_set_id,
109+
product_set=product_set
110+
)
111+
```
112+
113+
This call is invalid because it mixes `request` with a keyword argument `product_set`. Executing this code
114+
will result in an error.
115+
116+
```py
117+
response = client.create_product_set(
118+
request={
119+
"parent": parent,
120+
"product_set_id": product_set_id
121+
},
122+
product_set=product_set
123+
)
124+
```
125+
126+
127+
128+
## Enums and Types
129+
130+
131+
> **WARNING**: Breaking change
132+
133+
The submodules `enums` and `types` have been removed.
134+
135+
**Before:**
136+
```py
137+
from google.cloud import vision_v1
138+
139+
likelihood = vision_v1.enums.Likelihood.UNKNOWN
140+
request = vision_v1.types.GetProductSetRequest(name="name")
141+
```
142+
143+
144+
**After:**
145+
```py
146+
from google.cloud import vision_v1
147+
148+
likelihood = vision_v1.Likelihood.UNKNOWN
149+
request = vision_v1.GetProductSetRequest(name="name")
150+
```
151+
152+
## Location Path Helper Method
153+
154+
Loation path helper method has been removed. Please construct
155+
the path manually.
156+
157+
```py
158+
project = "my-project"
159+
location = "location"
160+
161+
location_path = f"projects/{project}/locations/{location}"
162+
```

docs/UPGRADING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../UPGRADING.md

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"sphinx.ext.autosummary",
4040
"sphinx.ext.intersphinx",
4141
"sphinx.ext.coverage",
42+
"sphinx.ext.doctest",
4243
"sphinx.ext.napoleon",
4344
"sphinx.ext.todo",
4445
"sphinx.ext.viewcode",

docs/gapic/v1/api.rst

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

0 commit comments

Comments
 (0)