This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
feat!: migrate API to microgenerator #31
Merged
Merged
Changes from 99 commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
37a89ce
Add new "quickstart" samples [(#547)](https://github.com/GoogleCloudP…
jmdobry e3ef3df
Quickstart tests [(#569)](https://github.com/GoogleCloudPlatform/pyth…
73e12f0
Add translate samples [(#574)](https://github.com/GoogleCloudPlatform…
64a0a04
Generate most non-appengine readmes
52b7975
Update requirements.txt
puneith bcc3886
Merge pull request #653 from GoogleCloudPlatform/google-translate-ver…
9d6a764
added model in the sample [(#650)](https://github.com/GoogleCloudPlat…
puneith 51c5769
added with and without model separately [(#657)](https://github.com/G…
puneith b5ddbe3
Translate API no longer requires an API key. [(#659)](https://github.…
jmdobry a743ae0
Auto-update dependencies. [(#715)](https://github.com/GoogleCloudPlat…
dpebot a2cf9fb
Changes default model to premium [(#749)](https://github.com/GoogleCl…
gguuss 76c019a
Updates readme template to show credential auth instead of api key. […
gguuss f4502c0
Updates translate version to match speech and language. [(#843)](http…
gguuss ba65bb2
Translate update [(#886)](https://github.com/GoogleCloudPlatform/pyth…
gguuss 4de3659
Remove cloud config fixture [(#887)](https://github.com/GoogleCloudPl…
9fcaaf4
Unicode for translation
gguuss c38796e
Adds check for translated text
gguuss f8932fa
Unicode for translation
gguuss a948f73
Unicode for translation
gguuss 4de577b
Unicode for translation
gguuss 2c1a51f
missing newline
gguuss b8b38d4
Adds six for 2/3 compatibility
gguuss 2f5cb80
Changes encoding style.
gguuss 8d85abc
Fix unicode
52f0cba
renaming of the product to Google Translation API [(#910)](https://gi…
merla18 a697eb1
Update translate readme
108abe5
Re-generate all readmes
16186f4
Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/…
waprin de3d7f3
Auto-update dependencies. [(#1004)](https://github.com/GoogleCloudPla…
dpebot 22402fe
Auto-update dependencies. [(#1055)](https://github.com/GoogleCloudPla…
dpebot 0e7e947
Auto-update dependencies. [(#1093)](https://github.com/GoogleCloudPla…
dpebot 20d7d84
Update all generated readme auth instructions [(#1121)](https://githu…
0cbb423
Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleC…
cac8c70
Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPla…
dpebot 434eba0
Fixed failed tests on Kokoro (Spanner + Translate) [(#1192)](https://…
0d514cc
Added "Open in Cloud Shell" buttons to README files [(#1254)](https:/…
61265f2
Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPla…
dpebot 541a3a5
Regenerate the README files and fix the Open in Cloud Shell link for …
69abd4f
Update READMEs to fix numbering and add git clone [(#1464)](https://g…
frankyn ef12fcb
Add translate region tags [(#1488)](https://github.com/GoogleCloudPla…
averikitsch 294fe72
Include the comma in the translation [(#1787)](https://github.com/Goo…
engelke d2c3149
Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPla…
dpebot 7cba151
Translation v3beta1 samples [(#2084)](https://github.com/GoogleCloudP…
beccasaurus 458c33a
fixing translate-with-glossary bug [(#2323)](https://github.com/Googl…
crowdus 59fbf25
Translate beta samples fix [(#2327)](https://github.com/GoogleCloudPl…
crowdus 59be81d
Using glossaries with tts and vision tutorial sample code [(#2325)](h…
crowdus 2bd4ab3
fix: refactored MP3 file creation test for Hybrid glossaries samples …
crowdus 0443253
Fix variable names in comments [(#2400)](https://github.com/GoogleClo…
nnegrey 4ba3a44
Adds updates for samples profiler ... vision [(#2439)](https://github…
gguuss 9832634
Update v2 samples to explicitly use v2 library [(#2498)](https://gith…
nnegrey b400096
fix: translate test [(#2671)](https://github.com/GoogleCloudPlatform/…
leahecole 0666215
automl: add natural language sentiment analysis ga samples [(#2677)](…
nnegrey 42afcb4
fix region tag typo [(#2731)](https://github.com/GoogleCloudPlatform/…
leahecole a80d5f4
Migrate published samples [(#2759)](https://github.com/GoogleCloudPla…
texasmichelle d5f78a9
translate v3 snippets [(#2745)](https://github.com/GoogleCloudPlatfor…
munkhuushmgl 33f7ce0
Translate: migrate published samples [(#2768)](https://github.com/Goo…
texasmichelle 48850ab
Translate: migrate published glossaries samples [(#2769)](https://git…
texasmichelle aa59393
translate: increase timeout [(#2937)](https://github.com/GoogleCloudP…
nnegrey cc5c848
Translate: migrate published v3 translate batch samples [(#2914)](ht…
munkhuushmgl 3fa87ea
chore(deps): update dependency google-cloud-storage to v1.26.0 [(#304…
renovate-bot d02a0ae
chore(deps): update dependency google-cloud-translate to v1.7.0 [(#30…
renovate-bot 6809f72
translate: fix tests [(#3087)](https://github.com/GoogleCloudPlatform…
nnegrey 089c5d5
translate-v3: samples [(#3034)](https://github.com/GoogleCloudPlatfo…
munkhuushmgl 84e3684
chore(deps): update dependency google-cloud-vision to v0.42.0 [(#3170…
renovate-bot 8e6f3d8
chore(deps): update dependency google-cloud-texttospeech to v1 [(#321…
renovate-bot fb7dd90
chore(deps): update dependency google-cloud-translate to v2 [(#3211)]…
renovate-bot 723d450
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg 296f00e
Update dependency google-cloud-vision to v1 [(#3227)](https://github.…
renovate-bot 3aef3b1
translate: make test generic [(#3386)](https://github.com/GoogleCloud…
nnegrey 1b38db5
[translate] fix: mark some tests as flaky [(#3495)](https://github.co…
9acae80
testing: replace @flaky with @pytest.mark.flaky [(#3496)](https://git…
6ed8d4e
chore(deps): update dependency google-cloud-storage to v1.28.0 [(#326…
renovate-bot eb357b1
translate: fix glossary leak issue [(#3572)](https://github.com/Googl…
munkhuushmgl dcacff2
chore: some lint fixes [(#3751)](https://github.com/GoogleCloudPlatfo…
9556441
chore(deps): update dependency google-cloud-storage to v1.28.1 [(#378…
renovate-bot 7c4f9bf
[translate] fix hybrid glossaries tests [(#3936)](https://github.com/…
busunkim96 6f32e31
testing: start using btlr [(#3959)](https://github.com/GoogleCloudPla…
8ca332b
Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://g…
kurtisvg 79a6298
remove whitelist replace with allowlist [(#4050)](https://github.com/…
leahecole cb499dc
chore(deps): update dependency google-cloud-storage to v1.29.0 [(#404…
renovate-bot 58b3d2e
chore(deps): update dependency google-cloud-texttospeech to v2.1.0 [(…
renovate-bot 3bc8506
testing(translate): parameterize the timeout [(#4247)](https://github…
de0ee32
chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://git…
renovate-bot 135b228
Update dependency flaky to v3.7.0 [(#4300)](https://github.com/Google…
renovate-bot 6573d95
testing(translate): bump the timeout for operations [(#4258)](https:/…
0f9c755
Merge branch 'snippets-samples' into add-snippets-samples
danoscarmike 0081e92
chore: update templates
danoscarmike 0714f6d
chore: narrows samples CODEOWNERS to .py only
danoscarmike 3e7b19c
chore: wip migration to microgenerator
danoscarmike 5217b38
feat!: move API to python microgenerator
danoscarmike 67f317e
docs: readmegen updates
danoscarmike 0633064
chore: add build config for docs-presubmit
danoscarmike 753286b
Merge remote-tracking branch 'upstream/master' into master
danoscarmike fd045e3
chore: merge master
danoscarmike e1e1919
Merge branch 'master' into microgen
danoscarmike f2d4b18
Merge upstream into master
danoscarmike d3f4bfd
chore: rm protos
danoscarmike eebadb4
Merge branch 'master' into microgen
danoscarmike 6378cea
chore: uses PROJECT_ID env var in system test
danoscarmike d830f91
Merge branch 'microgen' of github.com:danoscarmike/python-translate i…
danoscarmike fbaa3ee
Merge remote-tracking branch 'upstream/master' into master
danoscarmike 7adc9fc
Merge branch 'master' into microgen
danoscarmike ec4ec30
chore: clarifies examples in migration guide
danoscarmike 688987e
chore: adds explicit variable
danoscarmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
# 3.0.0 Migration Guide | ||
|
||
The 3.0 release of the `google-cloud-translate` 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. | ||
|
||
If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-translate/issues). | ||
|
||
## Supported Python Versions | ||
|
||
> **WARNING**: Breaking change | ||
|
||
The 3.0.0 release requires Python 3.6+. | ||
|
||
|
||
## Method Calls | ||
|
||
> **WARNING**: Breaking change | ||
|
||
Methods expect request objects. We provide a script that will convert most common use cases. | ||
|
||
* Install the library | ||
|
||
```py | ||
python3 -m pip install google-cloud-translate | ||
``` | ||
|
||
* The script `fixup_translation_{version}_keywords.py` is shipped with the library. It expects | ||
an input directory (with the code to convert) and an empty destination directory. | ||
|
||
```sh | ||
$ fixup_translation_v3_keywords.py --input-directory .samples/ --output-directory samples/ | ||
``` | ||
|
||
**Before:** | ||
```py | ||
from google.cloud import translate | ||
|
||
client = translate.TranslationServiceClient() | ||
parent = client.location_path(<PROJECT_ID>, <LOCATION>) | ||
|
||
response = client.translate_text( | ||
parent=parent, | ||
contents=[text], | ||
danoscarmike marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mime_type="text/plain", | ||
source_language_code="en-US", | ||
target_language_code="fr", | ||
) | ||
``` | ||
|
||
|
||
**After:** | ||
```py | ||
from google.cloud import translate | ||
|
||
client = translate.TranslationServiceClient() | ||
parent = "projects/<PROJECT_ID>/locations/<LOCATION>" | ||
|
||
response = client.translate_text( | ||
request={ | ||
"parent": parent, | ||
"contents": [text], | ||
"mime_type": "text/plain", | ||
"source_language_code": "en-US", | ||
"target_language_code": "fr" | ||
} | ||
) | ||
``` | ||
|
||
### More Details | ||
|
||
In `google-cloud-translate<3.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters. | ||
|
||
**Before:** | ||
```py | ||
def translate_text( | ||
self, | ||
contents, | ||
target_language_code, | ||
parent, | ||
mime_type=None, | ||
source_language_code=None, | ||
model=None, | ||
glossary_config=None, | ||
labels=None, | ||
retry=google.api_core.gapic_v1.method.DEFAULT, | ||
timeout=google.api_core.gapic_v1.method.DEFAULT, | ||
metadata=None, | ||
): | ||
``` | ||
|
||
In the 3.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional. | ||
|
||
Some methods have additional keyword only parameters. The available parameters depend on the [`google.api.method_signature` annotation](https://github.com/googleapis/googleapis/blob/master/google/cloud/translate/v3/translation_service.proto#L55) specified by the API producer. | ||
|
||
|
||
**After:** | ||
```py | ||
def translate_text( | ||
self, | ||
request: translation_service.TranslateTextRequest = None, | ||
*, | ||
parent: str = None, | ||
target_language_code: str = None, | ||
contents: Sequence[str] = None, | ||
model: str = None, | ||
mime_type: str = None, | ||
source_language_code: str = None, | ||
retry: retries.Retry = gapic_v1.method.DEFAULT, | ||
timeout: float = None, | ||
metadata: Sequence[Tuple[str, str]] = (), | ||
) -> translation_service.TranslateTextResponse: | ||
``` | ||
|
||
> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive. | ||
> Passing both will result in an error. | ||
|
||
|
||
Both of these calls are valid: | ||
|
||
```py | ||
response = client.translate_text( | ||
request={ | ||
"parent": parent, | ||
"target_language_code": target_language_code, | ||
"contents": contents | ||
} | ||
) | ||
``` | ||
|
||
```py | ||
response = client.translate_text( | ||
parent=parent, | ||
target_language_code=target_language_code, | ||
contents=contents | ||
) | ||
``` | ||
|
||
This call is invalid because it mixes `request` with a keyword argument `target_language_code`. Executing this code | ||
will result in an error. | ||
|
||
```py | ||
response = client.translate_text( | ||
request={ | ||
"parent": parent, | ||
"contents": contents, | ||
}, | ||
target_language_code=target_language_code | ||
) | ||
``` | ||
|
||
|
||
|
||
## Enums and types | ||
|
||
|
||
> **WARNING**: Breaking change | ||
|
||
The submodule `enums` (containing enum classes for long running operation State) has been removed. | ||
|
||
The submodule `types` is still present. When using the primary version module alias (`translate`) | ||
it is possible to access the types classes directly. | ||
|
||
```py | ||
from google.cloud import translate # the primary version is imported by default | ||
|
||
client = translate.TranslationServiceClient() | ||
|
||
glossary_config = client.TranslateTextGlossaryConfig( | ||
glossary=glossary_path | ||
) | ||
``` | ||
|
||
When a specific version is imported, the full module name must be specified to access types classes. | ||
|
||
```py | ||
from google.cloud import translate_v3beta1 as translate | ||
|
||
client = translate.TranslationServiceClient() | ||
|
||
glossary_config = client.types.TranslateTextGlossaryConfig( | ||
glossary=glossary_path | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../UPGRADING.md |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Services for Google Cloud Translation v3 API | ||
============================================ | ||
|
||
.. automodule:: google.cloud.translate_v3.services.translation_service | ||
:members: | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Types for Google Cloud Translation v3 API | ||
========================================= | ||
|
||
.. automodule:: google.cloud.translate_v3.types | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Services for Google Cloud Translation v3beta1 API | ||
================================================= | ||
|
||
.. automodule:: google.cloud.translate_v3beta1.services.translation_service | ||
:members: | ||
:inherited-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Types for Google Cloud Translation v3beta1 API | ||
============================================== | ||
|
||
.. automodule:: google.cloud.translate_v3beta1.types | ||
:members: |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.