Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NDB: Start in on ndb.client.Client #6876

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

Merged
merged 11 commits into from
Dec 17, 2018
Merged

Conversation

chrisrossi
Copy link

This is patterned off of datastore.client.Client and depends heavily on google.cloud.client.

@chrisrossi chrisrossi requested a review from dhermes December 7, 2018 20:15
@chrisrossi chrisrossi requested a review from crwilcox as a code owner December 7, 2018 20:15
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 7, 2018
Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisrossi I'm not clear why this special Client class is needed. A parallel to ndb would be https://github.com/googleapis/google-cloud-python-happybase, which doesn't define a Client of it's own (but does have a similar metaphor).

from google.cloud.client import ClientWithProject
from google.cloud import _helpers

_DATASTORE_HOST = "datastore.googleapis.com"

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

def test_constructor_no_args():
with patch_credentials("testing"):
client = client_module.Client()
assert client.SCOPE == ("https://www.googleapis.com/auth/datastore",)

This comment was marked as spam.

This comment was marked as spam.

@chrisrossi
Copy link
Author

chrisrossi commented Dec 8, 2018

@dhermes

@chrisrossi I'm not clear why this special Client class is needed. A parallel to ndb would be https://github.com/googleapis/google-cloud-python-happybase, which doesn't define a Client of it's own (but does have a similar metaphor).

A couple of days ago, before starting this, I sent around an email entitled "NDB client story", where I was pretty much fishing for exactly this kind of input. Did you see that?

I can look at happybase--I'm not familiar with it at the moment. Basically, if we're going to interact with datastore, we need to get credentials, figure out the project/app, and possibly get a namespace. Since this is just a layer on datastore, I looked to datastore for the model on how to do it. I'm not wed to anything in particular, but I try not to invent new idioms if there is one already available, and I figured datastore probably represented some kind of "best practice" for Google APIs.

@chrisrossi
Copy link
Author

@dhermes

@chrisrossi I'm not clear why this special Client class is needed. A parallel to ndb would be https://github.com/googleapis/google-cloud-python-happybase, which doesn't define a Client of it's own (but does have a similar metaphor).

A couple of days ago, before starting this, I sent around an email entitled "NDB client story", where I was pretty much fishing for exactly this kind of input. Did you see that?

I can look at happybase--I'm not familiar with it at the moment. Basically, if we're going to interact with datastore, we need to get credentials, figure out the project/app, and possibly get a namespace. Since this is just a layer on datastore, I looked to datastore for the model on how to do it. I'm not wed to anything in particular, but I try not to invent new idioms if there is one already available, and I figured datastore probably represented some kind of "best practice" for Google APIs.

I've looked at HappyBase this morning and it has a Connection object which is the moral equivalent of the Client object here. We need some way to manage the little bit of state that gets used to talk to Datastore. google.cloud.datastore uses a Client object and it makes sense to me for us also to use a Client object that is the parallel of that.

@chrisrossi chrisrossi requested a review from tseaver December 11, 2018 18:23
@dhermes
Copy link
Contributor

dhermes commented Dec 12, 2018

@chrisrossi I'd say push on with Client, but try to think of a way not to have this if we can avoid it. ndb's design is essentially going to force global state to be stored on the module, joy!

@chrisrossi
Copy link
Author

@chrisrossi I'd say push on with Client, but try to think of a way not to have this if we can avoid it. ndb's design is essentially going to force global state to be stored on the module, joy!

@dhermes I'm reasonably confident we can contain all the state we need in client.Client and the thread locals in _runstate.

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisrossi You have an uncovered branch in conftest.py, so you need a no cover pragma?

from google.cloud.client import ClientWithProject
from google.cloud import _helpers

_DATASTORE_HOST = "datastore.googleapis.com"

This comment was marked as spam.

@chrisrossi
Copy link
Author

@dhermes Yep, fixed.

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

super(Client, self).__init__(project=project, credentials=credentials)
self.namespace = namespace
self.host = os.environ.get(
environment_vars.GCD_HOST, _http.DATASTORE_API_HOST

This comment was marked as spam.


from google.cloud import environment_vars
from google.cloud import _helpers
from google.cloud.client import ClientWithProject

This comment was marked as spam.

def environ():
"""Copy of ``os.environ``"""
original = os.environ
environ = original.copy()

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@chrisrossi chrisrossi merged commit 122850b into googleapis:master Dec 17, 2018
@chrisrossi chrisrossi deleted the ndb-client branch December 18, 2018 13:45
chrisrossi pushed a commit to chrisrossi/google-cloud-python that referenced this pull request Feb 22, 2019
NDB: Start implementation of ndb.client.Client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: ndb cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants