Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit b408b14

Browse files
feat: Migrate API to use python micro-generator (#41)
* migrate API to use micro-generator * migrate API to use micro-generator * update * doc changes * add samples * add samples * add samples and readme * Update README.md * Update README.md * Update UPGRADING.md file * update synth.py Co-authored-by: arithmetic1728 <[email protected]>
1 parent 8be89ed commit b408b14

File tree

82 files changed

+11359
-997
lines changed

Some content is hidden

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

82 files changed

+11359
-997
lines changed

.coveragerc

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ omit =
2323
[report]
2424
fail_under = 100
2525
show_missing = True
26+
omit = google/cloud/language/__init__.py
2627
exclude_lines =
2728
# Re-enable the standard pragma
2829
pragma: NO COVER
2930
# Ignore debug-only repr
3031
def __repr__
31-
# Ignore abstract methods
32-
raise NotImplementedError
33-
omit =
34-
*/gapic/*.py
35-
*/proto/*.py
36-
*/core/*.py
37-
*/site-packages/*.py
38-
google/cloud/__init__.py
32+
# Ignore pkg_resources exceptions.
33+
# This is added at the module level as a safeguard for if someone
34+
# generates the code and tries to run it without pip installing. This
35+
# makes it virtually impossible to test properly.
36+
except pkg_resources.DistributionNotFound

.kokoro/samples/python3.6/common.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ env_vars: {
1313
value: "py-3.6"
1414
}
1515

16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py36"
20+
}
21+
1622
env_vars: {
1723
key: "TRAMPOLINE_BUILD_FILE"
1824
value: "github/python-language/.kokoro/test-samples.sh"

.kokoro/samples/python3.7/common.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ env_vars: {
1313
value: "py-3.7"
1414
}
1515

16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py37"
20+
}
21+
1622
env_vars: {
1723
key: "TRAMPOLINE_BUILD_FILE"
1824
value: "github/python-language/.kokoro/test-samples.sh"

.kokoro/samples/python3.8/common.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ env_vars: {
1313
value: "py-3.8"
1414
}
1515

16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py38"
20+
}
21+
1622
env_vars: {
1723
key: "TRAMPOLINE_BUILD_FILE"
1824
value: "github/python-language/.kokoro/test-samples.sh"

README.rst

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ dependencies.
6262

6363
Supported Python Versions
6464
^^^^^^^^^^^^^^^^^^^^^^^^^
65-
Python >= 3.5
65+
Python >= 3.6
6666

67-
Deprecated Python Versions
68-
^^^^^^^^^^^^^^^^^^^^^^^^^^
69-
Python == 2.7. Python 2.7 support will be removed on January 1, 2020.
67+
Unsupported Python Versions
68+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
69+
Python == 2.7.
70+
71+
The last version of this library compatible with Python 2.7 is google-cloud-language=1.3.0
7072

7173

7274
Mac/Linux

UPGRADING.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# 2.0.0 Migration Guide
2+
3+
The 2.0 release of the `google-cloud-language` 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-language/issues).
6+
7+
## Supported Python Versions
8+
9+
> **WARNING**: Breaking change
10+
The 2.0.0 release requires Python 3.6+.
11+
12+
## Method Calls
13+
14+
> **WARNING**: Breaking change
15+
Methods expect request objects. We provide a script that will convert most common use cases.
16+
* Install the library
17+
18+
```py
19+
python3 -m pip install google-cloud-language
20+
```
21+
22+
* The script `fixup_language_v1_keywords.py` is shipped with the library. It expects
23+
an input directory (with the code to convert) and an empty destination directory.
24+
25+
```sh
26+
$ fixup_language_v1_keywords.py --input-directory .samples/ --output-directory samples/
27+
```
28+
29+
**Before:**
30+
```py
31+
from google.cloud import language_v1
32+
language = language_v1.LanguageClient()
33+
return language.analyze_sentiment(document=document).document_sentiment
34+
```
35+
36+
37+
**After:**
38+
```py
39+
from google.cloud import language_v1
40+
language = language_v1.LanguageServiceClient()
41+
return language.analyze_sentiment(request={'document': document}).document_sentiment
42+
```
43+
44+
### More Details
45+
46+
In `google-cloud-language<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters.
47+
48+
**Before:**
49+
```py
50+
def analyze_sentiment(
51+
self,
52+
document,
53+
encoding_type=None,
54+
retry=google.api_core.gapic_v1.method.DEFAULT,
55+
timeout=google.api_core.gapic_v1.method.DEFAULT,
56+
metadata=None,
57+
):
58+
```
59+
60+
In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional.
61+
62+
Some methods have additional keyword only parameters. The available parameters depend on the `google.api.method_signature` annotation specified by the API producer.
63+
64+
65+
**After:**
66+
```py
67+
def analyze_sentiment(
68+
self,
69+
request: language_service.AnalyzeSentimentRequest = None,
70+
*,
71+
document: language_service.Document = None,
72+
encoding_type: language_service.EncodingType = None,
73+
retry: retries.Retry = gapic_v1.method.DEFAULT,
74+
timeout: float = None,
75+
metadata: Sequence[Tuple[str, str]] = (),
76+
) -> language_service.AnalyzeSentimentResponse:
77+
```
78+
79+
> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive.
80+
> Passing both will result in an error.
81+
Both of these calls are valid:
82+
83+
```py
84+
response = client.analyze_sentiment(
85+
request={
86+
"document": document,
87+
"encoding_type": encoding_type
88+
}
89+
)
90+
```
91+
92+
```py
93+
response = client.analyze_sentiment(
94+
document=document,
95+
encoding_type=encoding_type
96+
) # Make an API request.
97+
```
98+
99+
This call is invalid because it mixes `request` with a keyword argument `entry_group`. Executing this code
100+
will result in an error.
101+
102+
```py
103+
response = client.analyze_sentiment(
104+
request={
105+
"document": document
106+
},
107+
encoding_type=encoding_type
108+
)
109+
```
110+
111+
112+
113+
## Enums and Types
114+
115+
116+
> **WARNING**: Breaking change
117+
The submodules `enums` and `types` have been removed.
118+
**Before:**
119+
```py
120+
from google.cloud import language_v1
121+
document = language_v1.types.Document(content=text, type=language_v1.enums.Document.Type.PLAIN_TEXT)
122+
encoding_type = language_v1.enums.EncodingType.UTF8
123+
```
124+
125+
126+
**After:**
127+
```py
128+
from google.cloud import language_v1
129+
document = language_v1.Document(content=text, type_=language_v1.Document.Type.PLAIN_TEXT)
130+
encoding_type = language_v1.EncodingType.UTF8
131+
```
132+
133+
## Project Path Helper Methods
134+
135+
The project path helper method `project_path` has been removed. Please construct
136+
this path manually.
137+
138+
```py
139+
project = 'my-project'
140+
project_path = f'projects/{project}'

docs/UPGRADING.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../UPGRADING.md

docs/api.rst

+14-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ API. By default, you will get ``v1``, the latest GA version.
77
.. toctree::
88
:maxdepth: 2
99

10-
gapic/v1/api
11-
gapic/v1/types
10+
language_v1/services
11+
language_v1/types
1212

1313
If you are interested in beta features ahead of the latest GA, you may
1414
opt-in to the v1.1 beta, which is spelled ``v1beta2``. In order to do this,
@@ -20,8 +20,18 @@ An API and type reference is provided for the v1.1 beta also:
2020
.. toctree::
2121
:maxdepth: 2
2222

23-
gapic/v1beta2/api
24-
gapic/v1beta2/types
23+
language_v1beta2/services
24+
language_v1beta2/types
25+
26+
Migration Guide
27+
---------------
28+
29+
See the guide below for instructions on migrating to the 2.x release of this library.
30+
31+
.. toctree::
32+
:maxdepth: 2
33+
34+
UPGRADING
2535

2636
.. note::
2737

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@
347347
intersphinx_mapping = {
348348
"python": ("http://python.readthedocs.org/en/latest/", None),
349349
"google-auth": ("https://google-auth.readthedocs.io/en/stable", None),
350-
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None),
350+
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
351351
"grpc": ("https://grpc.io/grpc/python/", None),
352352
}
353353

docs/gapic/v1/api.rst

-6
This file was deleted.

docs/gapic/v1/types.rst

-5
This file was deleted.

docs/gapic/v1beta2/api.rst

-6
This file was deleted.

docs/gapic/v1beta2/types.rst

-5
This file was deleted.

docs/language_v1/services.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Services for Google Cloud Language v1 API
2+
=========================================
3+
4+
.. automodule:: google.cloud.language_v1.services.language_service
5+
:members:
6+
:inherited-members:

docs/language_v1/types.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Types for Google Cloud Language v1 API
2+
======================================
3+
4+
.. automodule:: google.cloud.language_v1.types
5+
:members:

docs/language_v1beta2/services.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Services for Google Cloud Language v1beta2 API
2+
==============================================
3+
4+
.. automodule:: google.cloud.language_v1beta2.services.language_service
5+
:members:
6+
:inherited-members:

docs/language_v1beta2/types.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Types for Google Cloud Language v1beta2 API
2+
===========================================
3+
4+
.. automodule:: google.cloud.language_v1beta2.types
5+
:members:

google/cloud/language/__init__.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
from google.cloud.language_v1.services.language_service.async_client import (
19+
LanguageServiceAsyncClient,
20+
)
21+
from google.cloud.language_v1.services.language_service.client import (
22+
LanguageServiceClient,
23+
)
24+
from google.cloud.language_v1.types.language_service import AnalyzeEntitiesRequest
25+
from google.cloud.language_v1.types.language_service import AnalyzeEntitiesResponse
26+
from google.cloud.language_v1.types.language_service import (
27+
AnalyzeEntitySentimentRequest,
28+
)
29+
from google.cloud.language_v1.types.language_service import (
30+
AnalyzeEntitySentimentResponse,
31+
)
32+
from google.cloud.language_v1.types.language_service import AnalyzeSentimentRequest
33+
from google.cloud.language_v1.types.language_service import AnalyzeSentimentResponse
34+
from google.cloud.language_v1.types.language_service import AnalyzeSyntaxRequest
35+
from google.cloud.language_v1.types.language_service import AnalyzeSyntaxResponse
36+
from google.cloud.language_v1.types.language_service import AnnotateTextRequest
37+
from google.cloud.language_v1.types.language_service import AnnotateTextResponse
38+
from google.cloud.language_v1.types.language_service import ClassificationCategory
39+
from google.cloud.language_v1.types.language_service import ClassifyTextRequest
40+
from google.cloud.language_v1.types.language_service import ClassifyTextResponse
41+
from google.cloud.language_v1.types.language_service import DependencyEdge
42+
from google.cloud.language_v1.types.language_service import Document
43+
from google.cloud.language_v1.types.language_service import EncodingType
44+
from google.cloud.language_v1.types.language_service import Entity
45+
from google.cloud.language_v1.types.language_service import EntityMention
46+
from google.cloud.language_v1.types.language_service import PartOfSpeech
47+
from google.cloud.language_v1.types.language_service import Sentence
48+
from google.cloud.language_v1.types.language_service import Sentiment
49+
from google.cloud.language_v1.types.language_service import TextSpan
50+
from google.cloud.language_v1.types.language_service import Token
51+
52+
__all__ = (
53+
"AnalyzeEntitiesRequest",
54+
"AnalyzeEntitiesResponse",
55+
"AnalyzeEntitySentimentRequest",
56+
"AnalyzeEntitySentimentResponse",
57+
"AnalyzeSentimentRequest",
58+
"AnalyzeSentimentResponse",
59+
"AnalyzeSyntaxRequest",
60+
"AnalyzeSyntaxResponse",
61+
"AnnotateTextRequest",
62+
"AnnotateTextResponse",
63+
"ClassificationCategory",
64+
"ClassifyTextRequest",
65+
"ClassifyTextResponse",
66+
"DependencyEdge",
67+
"Document",
68+
"EncodingType",
69+
"Entity",
70+
"EntityMention",
71+
"LanguageServiceAsyncClient",
72+
"LanguageServiceClient",
73+
"PartOfSpeech",
74+
"Sentence",
75+
"Sentiment",
76+
"TextSpan",
77+
"Token",
78+
)

google/cloud/language/py.typed

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Marker file for PEP 561.
2+
# The google-cloud-language package uses inline types.

0 commit comments

Comments
 (0)