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

Implement a GAX version of '_PublisherAPI'. #1764

Merged
merged 13 commits into from May 16, 2016
Merged

Implement a GAX version of '_PublisherAPI'. #1764

merged 13 commits into from May 16, 2016

Conversation

tseaver
Copy link
Contributor

@tseaver tseaver commented Apr 28, 2016

Note: paging methods (list_topics and list_topic_subscriptions) are only partially implemented, because the GAX API does not permit passing in a page token (it cam be coerced into returning only a single page of results, and its token, though). See:

@tseaver tseaver added the api: pubsub Issues related to the Pub/Sub API. label Apr 28, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 28, 2016
@dhermes
Copy link
Contributor

dhermes commented Apr 28, 2016

gcloud/pubsub/_gax.py:23:5: E303 too many blank lines (2)
gcloud/pubsub/_gax.py:30:5: E303 too many blank lines (2)
gcloud/pubsub/_gax.py:68:76: W291 trailing whitespace

except ImportError:
_HAVE_GAX = False
else:
_HAVE_GAX = True

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented May 3, 2016

@tseaver To make the conditional definition comments a bit more clear let me describe what I have in mind (as a parallel to oauth2client.crypt).

  1. You implement everything in gcloud.pubsub._gax at the top-level, allowing for import failures.
  2. In the place where you use it (I assume gcloud.pubsub.connection, in a future PR?), there you conditionally import:
try:
    from gcloud.pubsub._gax import _PublisherAPI
    ...
    _HAVE_GAX = True
except ImportError:
    _PublisherAPI = None  # or maybe type(None) if you want it to be a class
    ...
    _HAVE_GAX = False

Having the conditional skip in test__gax rely on the import success also seems out of place, since we can just require the dependency in tox for Py2.7 and ignore it for other versions (I know the dependency is an extra right now in setup.py).

@tseaver
Copy link
Contributor Author

tseaver commented May 6, 2016

You implement everything in gcloud.pubsub._gax at the top-level, allowing for import failures.

How do you deal with those errors being triggered by tests in the tox environments where the grpc extra cannot be installed? That is what unittest.skipUnless is for, after all.

@dhermes
Copy link
Contributor

dhermes commented May 9, 2016

@tseaver You can still skipUnless, just use gcloud.pubsub.connection._HAVE_GAX.

@tseaver
Copy link
Contributor Author

tseaver commented May 9, 2016

@dhermes

  • The new module is the point where we're detecting the presence / absence of GAX.
  • The future PR will add the import to gcloud.pubsub.client, not connection: it will test the _HAVE_GAX flag, along with an optional environment variable, to determine whether to use the _gax helpers or the JSON ones (from gcloud.pubsub.connection).
  • Having tests of the "lower-level" module (gcloud.pubsub._gax) rely on the "higher-level" one (gcloud.pubsub.client) is just wrong.

@dhermes
Copy link
Contributor

dhermes commented May 9, 2016

The way you detect it isn't particularly important to me. My feedback is not all-encompassing, just that you don't conditionally define an entire module.

@tseaver
Copy link
Contributor Author

tseaver commented May 10, 2016

Don't conditionally define an entire module.

What is the difference for the user of the library? In this implementaiton, they can import gcloud.pubsub._gax without an exception, but the only member will be the _HAVE_GAX flag. In your version, trying to import gcloud.pubsub._gax would raise an ImportError.

WIthin gcloud, I can't see any win to deferring handling of the ImportError to the potential user (gcloud.pubsub.client). My way makes it easier to test the conditional code, because I can monkey-patch gcloud.pubsub._gax to have the desired value of _HAVE_GAX, as well as an appropriate stub for the helper objects.

@dhermes
Copy link
Contributor

dhermes commented May 11, 2016

Anything named gcloud.pubsub._gax is not for users. I'm not asking for the change for users, but for code quality. It's harder to read and understand a class defined somewhere other than the top level.

You could even just have _gax.py contain:

try:
    import google.gax
except ImportError:
    _HAVE_GAX = False
else:
    _HAVE_GAX = True
    from gcloud.pubsub._gax_impl import _PublisherAPI

I'm just advocating against conditionally defined top-level objects for the same of the code.

else:
_HAVE_GAX = True

from google.pubsub.v1.pubsub_pb2 import PubsubMessage

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented May 11, 2016

The cause stuff looks alright, so the last hangup is the conditionally defined stuff.

Note:  paging methods ('list_topics' and 'list_topic_subscriptions') are
only partially implemented, because the GAX API does not permit passing
in a page token (it can be coerced into *returning* only a single page of
results, and its token, though).  See:

- googleapis/gax-python#86
- googleapis/gax-python#94
Also, add docstring for private helper function.

Addresses:
#1764 (comment)
#1764 (comment)
@tseaver
Copy link
Contributor Author

tseaver commented May 13, 2016

@dhermes PTAL

@dhermes
Copy link
Contributor

dhermes commented May 13, 2016

@tseaver Trying to review the "latest" changes but all the commits are from May 11 and May 12. Does a rebase change a commit date? Which ones are relevant since last review?

@tseaver
Copy link
Contributor Author

tseaver commented May 13, 2016

@dhermes

@tseaver Trying to review the "latest" changes but all the commits are from May 11 and May 12. Does a rebase change a commit date?

I've never quite figured out what Github's UI was doing about dates.

Which [commits] are relevant since last review?

@dhermes
Copy link
Contributor

dhermes commented May 16, 2016

LGTM. Sorry for the delay.

@tseaver tseaver merged commit 14b1143 into googleapis:master May 16, 2016
@tseaver tseaver deleted the pubsub-wrap_gax_publisher_api branch May 16, 2016 13:48
@tseaver tseaver mentioned this pull request May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants