Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: transition the library to the new microgenerator #158

Merged
merged 35 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d218232
chore: regenerate the library with microgenerator
plamut Jul 14, 2020
529c853
Update setup.py for Python 3.6+
plamut Jul 14, 2020
a744caf
Fix GAPIC types imports
plamut Jul 14, 2020
f416327
Inject SERVICE_ADDRESS and _DEFAULT_SCOPES to generated classes
plamut Jul 15, 2020
256081a
Cleanup types.py
plamut Jul 15, 2020
dbf76f0
Adjust determining message size to new protobufs
plamut Jul 14, 2020
1c08fc4
Adjust Message.publish_time property to new protobuf
plamut Jul 14, 2020
8568830
Remove client_config argument to publisher client
plamut Jul 14, 2020
5a881e5
Remove subscriber client config
plamut Jul 14, 2020
022e710
Fix method patch in gapic instance method test
plamut Jul 14, 2020
d44494f
Fix transport-related test failures
plamut Jul 14, 2020
19952aa
Adjust calls to changed client.publish() signature
plamut Jul 14, 2020
d8b0a34
Remove obsolete replacement rules from synth.py
plamut Jul 15, 2020
cd8ad7e
Fix streaming pull monkeypatch (no prefetch)
plamut Jul 15, 2020
1253156
Update supported Python versions in README
plamut Jul 15, 2020
5a78181
Adjust system tests to new method signatures
plamut Jul 16, 2020
2b01cc4
Adjust method calls in samples to new client
plamut Jul 14, 2020
b336b2f
Fix tests creating subscription with custom settings
plamut Jul 17, 2020
1170672
Regenerate library with latest synthtool
plamut Jul 23, 2020
466a8db
Adjust IAM tests to new IAM method signatures
plamut Jul 23, 2020
7d82ece
Fix docstring format in generated *_iam_policy() methods
plamut Jul 23, 2020
4add1b9
Iterate directly over topic subscriptions response
plamut Jul 24, 2020
758a470
Copy default publish Retry to a class variable
plamut Jul 28, 2020
62d0d07
Adjust retry deadline if publish with ordering key
plamut Jul 30, 2020
2ed758e
Add suport for custom publish retry settings
plamut Jul 30, 2020
4c6a6a0
Add UPGRADING guide to docs
plamut Jul 31, 2020
5624026
Mention default retry settings in sample comments
plamut Aug 5, 2020
fe3d041
Merge branch 'master' into use-microgenerator
plamut Aug 15, 2020
3eb9a05
Remove synth URL changes from templates
plamut Aug 15, 2020
3bc393b
Adjust the ordering key sample to new code
plamut Aug 18, 2020
9f5aeee
Adjust client to changes in generated code
plamut Aug 19, 2020
c57c8b2
Regenerate the code to pick the latest changes
plamut Aug 19, 2020
cca5683
Bump dependencies to latest versions
plamut Aug 19, 2020
c29d7f8
Optimize creating and accesing pubsub messages
plamut Aug 20, 2020
23e1612
Regenerate the code with the latest changes
plamut Sep 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ dependencies.

Supported Python Versions
^^^^^^^^^^^^^^^^^^^^^^^^^
Python >= 3.5
Python >= 3.6

Deprecated Python Versions
^^^^^^^^^^^^^^^^^^^^^^^^^^
Python == 2.7. Python 2.7 support will be removed on January 1, 2020.
Python == 2.7.

The last version of this library compatible with Python 2.7 is google-cloud-pubsub==1.7.0.


Mac/Linux
Expand Down
160 changes: 160 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 2.0.0 Migration Guide

The 2.0 release of the `google-cloud-pubsub` 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-pubsub/issues).


## Supported Python Versions

> **WARNING**: Breaking change

The 2.0.0 release requires Python 3.6+.


## Method Calls

> **WARNING**: Breaking change

Almost all methods that send requests to the backend expect request objects. We
provide a script that will convert most common use cases.

* Install the library

```py
python3 -m pip install google-cloud-pubsub
```

* The script `fixup_pubsub_v1_keywords.py` is shipped with the library. It expects
an input directory (with the code to convert) and an empty destination directory.

```sh
$ scripts/fixup_pubsub_v1_keywords.py --input-directory .samples/ --output-directory samples/
```

**Before:**
```py
from google.cloud import pubsub

publisher = pubsub.PublisherClient()

project_path = "projects/{}".format(PROJECT_ID)
topics = publisher.list_topics(project_path)
```


**After:**
```py
from google.cloud import pubsub

publisher = pubsub.PublisherClient()

project_path = f"projects/{PROJECT_ID}"
topics = publisher.list_topics(request={"project": project_path})
```

### More Details

In `google-cloud-pubsub<2.0.0`, parameters required by the API were positional
parameters and optional parameters were keyword parameters.

**Before:**
```py
def list_topics(
self,
project,
page_size=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
```

In the 2.0.0 release, almost all methods that interact with the backend have a single
positional parameter `request`. Method docstrings indicate whether a parameter is
required or optional.

> **NOTE:** The exception are hand written methods such as `publisher.publish()` and
> `subscriber.subscribe()` that implement additional logic (e.g. request batching) and
> sit on top of the API methods from the generated parts of the library. The signatures
> of these methods have in large part been preserved.

Some methods have additional keyword only parameters. The available parameters depend
on the [`google.api.method_signature` annotation](https://github.com/googleapis/python-pubsub/blob/master/google/cloud/pubsub_v1/proto/pubsub.proto#L88)
specified by the API producer.


**After:**
```py
def list_topics(
self,
request: pubsub.ListTopicsRequest = None,
*,
project: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListTopicsPager:
```

> **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.list_topics(
request={
"project": project_path,
"metadata": [("foo", "bar"), ("baz", "quux")],
}
)
```

```py
response = client.list_topics(
project=project_path,
metadata=[("foo", "bar"), ("baz", "quux")],
)
```

This call is invalid because it mixes `request` with a keyword argument `metadata`.
Executing this code will result in an error:

```py
response = client.synthesize_speech(
request={"project": project_path},
metadata=[("foo", "bar"), ("baz", "quux")],
)
```

> **NOTE:** The `request` parameter of some methods can also contain a more rich set of
> options that are otherwise not available as explicit keyword only parameters, thus
> these _must_ be passed through `request`.


## Removed Utility Methods

> **WARNING**: Breaking change

Some utility methods such as publisher client's `subscription_path()` have been removed
and now only exist in the relevant client, e.g. `subscriber.subscription_path()`.

The `project_path()` method has been removed from both the publisher and subscriber
client, this path must now be constructed manually:
```py
project_path = f"project/{PROJECT_ID}"
```

## Removed `client_config` Parameter

The publisher and subscriber clients cannot be constructed with `client_config`
argument anymore. If you want to customize retry and timeout settings for a particular
method, you need to do it upon method invocation by passing the custom `timeout` and
`retry` arguments, respectively.
1 change: 1 addition & 0 deletions docs/UPGRADING.md
27 changes: 23 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@

.. include:: multiprocessing.rst


API Documentation
-----------------

.. note::

The client library version (currently ``2.x``) should not be confused with the
backend API version (currently ``v1``), hence some references to ``v1`` can be found
across the documentation.

.. toctree::
:maxdepth: 3

Publisher Client <publisher/index>
Subscriber Client <subscriber/index>
Types <types>


Migration Guide
---------------

See the guide below for instructions on migrating to the 2.x release of this library.

.. toctree::
:maxdepth: 3
:maxdepth: 2

UPGRADING

publisher/index
subscriber/index
types

Changelog
---------
Expand Down
4 changes: 2 additions & 2 deletions docs/publisher/api/client.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Publisher Client API
====================
Publisher Client API (v1)
=========================

.. automodule:: google.cloud.pubsub_v1.publisher.client
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/subscriber/api/client.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Subscriber Client API
=====================
Subscriber Client API (v1)
==========================

.. automodule:: google.cloud.pubsub_v1.subscriber.client
:members:
Expand Down
Empty file.
Loading