Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

feat(datastore): add datastore #35

Merged
merged 3 commits into from Jul 9, 2019

Conversation

KevinGDialpad
Copy link
Contributor

This based on the code for #34. I will rebase and remove the WIP after it's merged.

This adds support for the datastore, in a separate project.

The code is pretty much gcloud-aio's datastore

@KevinGDialpad KevinGDialpad requested review from TheKevJames and a team as code owners June 25, 2019 16:40
@ghost ghost requested a review from eddiedialpad June 25, 2019 16:40
Copy link
Contributor Author

@KevinGDialpad KevinGDialpad left a comment

Choose a reason for hiding this comment

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

This looks like a lot of code, but the actual code comes directly from gcloud-aio. The wiring is what's important here :)

Also, I didn't add integration tests. I'd like to write some but I can't run them.

Can we add issues to the GitHub project? I'd like to add one for running integration tests (like gcloud-aio's 53) and one for adding integration tests to the datastore and update the README.

.gitignore Show resolved Hide resolved
.pre-commit-config.py27.yaml Outdated Show resolved Hide resolved
@@ -56,9 +52,11 @@ repos:
rev: v1.4.4
hooks:
- id: autopep8
args:
- --in-place
- --ignore=E124,E226,E24,W50,W690 # E124 conflicts with pylint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think those kinds of problems are going to be fixed in #34.

This specific one is a conflict between pylint and pep8. See pylint-dev/pylint#747 It seems that this correction is not the right one. But #34 has the same problem so we can fix it there.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha -- not sure why this hasn't come up for us before, since these hooks are enabled on all of our other repos... what are all of these disables?

E124 in particular I'm ok with disabling -- I think we've generally defaulted to the pylint style anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other 4 are disabled by default in autopep8, so they were already ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of doing that, we're going to disable bad-continuation in Pylint, because Pylint is wrong in that case. See the last part of the indentation section of PEP-8:

The closing brace/bracket/parenthesis on multiline constructs may either line up under the first non-whitespace character of the last line of list [...]

(the other case is not relevant)

So I think we can remove these 3 lines and ignore bad-continuation in Pylint instead.

cc @gunjanswitchco

Copy link
Member

Choose a reason for hiding this comment

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

I could go either way on accepting the pylint of the autopep8 versions here; I would say pick whichever one our code already conforms to, since in this case I think its more important to have the standard than exactly which one it is. ++ for picking one and rolling with it 👍

README.rst Outdated Show resolved Hide resolved
datastore/README.rst Show resolved Hide resolved
datastore/gcloud/rest/datastore/datastore.py Show resolved Hide resolved
@@ -1,7 +1,10 @@
from pkg_resources import get_distribution
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. The auth files are not supposed to be here. Please ignore everything from that point down.

Copy link
Member

Choose a reason for hiding this comment

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

Sure thing -- we'll need to make sure these get removed before merge! We'll get the base auth PR in first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep - I'll rebase onto master once #34 is merged. Since the auth changes will be on master already, they will disappear from this PR.

Copy link
Member

@TheKevJames TheKevJames left a comment

Choose a reason for hiding this comment

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

Enabled issues on this repo -- not sure why they had been disabled in the first place /shrug

@@ -56,9 +52,11 @@ repos:
rev: v1.4.4
hooks:
- id: autopep8
args:
- --in-place
- --ignore=E124,E226,E24,W50,W690 # E124 conflicts with pylint
Copy link
Member

Choose a reason for hiding this comment

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

Gotcha -- not sure why this hasn't come up for us before, since these hooks are enabled on all of our other repos... what are all of these disables?

E124 in particular I'm ok with disabling -- I think we've generally defaulted to the pylint style anyway.

@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 TalkIQ
Copy link
Member

Choose a reason for hiding this comment

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

2019, please, since the datastore module is new!

import ujson as json
except ImportError:
import json # type: ignore
try:
Copy link
Member

Choose a reason for hiding this comment

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

nit: keep the linebreaks here, please -- I'm actually surprised our linting doesn't catch this, there should be two empty lines after all the imports.

if not self.session:
self.session = requests.Session()
session = session or self.session
resp = session.post(url, data=payload,
Copy link
Member

Choose a reason for hiding this comment

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

All of these callouts will need to be wrapped in a lock, as with the other gcloud-rest-* projects. Similarly, we'll need to add that argument to Datastore.__init__()



class PathElement(object):
def __init__(self, kind, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Could we make id_ and name explicit like we have in gcloud-aio rather than using kwargs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is, we can't make them keyword-only. And only one of them can be passed here.

One alternative is to force the caller to pass None, "name" when they want to use a name.
Another is to pass an id_or_name and look at the data type.

I'll think about it more.

Copy link
Member

Choose a reason for hiding this comment

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

I think I'm missing something -- why can we not make this def __init__(self, kind, id_=None, name=None): in the same way as we do in aio? I believe aio has a check in the body of the init method (if id_ and name: raise ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah I'm the one missing something :)
Some habits are hard to break and it didn't occur to me that I could use the method signature you propose and still call it with PathElement(Kind, name='name') - I blame my C# days

# TODO: support `projection` and `distinctOn`
def __init__(self,
kind='', # type: str
query_filter=None, # type: Filter
Copy link
Member

Choose a reason for hiding this comment

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

This should be Optional[Filter] -- could you go through the type hints and make sure you've marked down which are nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll admit I mindlessly converted the Python 3 annotations - gcloud-aio is wrong as well. Will fix

@@ -1,7 +1,10 @@
from pkg_resources import get_distribution
Copy link
Member

Choose a reason for hiding this comment

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

Sure thing -- we'll need to make sure these get removed before merge! We'll get the base auth PR in first.

@TheKevJames
Copy link
Member

This should now be rebase-able onto v1.6.0 :)

@KevinGDialpad KevinGDialpad changed the title [WIP] feat(datastore): add datastore feat(datastore): add datastore Jul 3, 2019
Copy link
Contributor Author

@KevinGDialpad KevinGDialpad left a comment

Choose a reason for hiding this comment

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

A bit of a long review but again, the code comes from gcloud-aio. For the most part, I just converted the type annotations to be Python2-compatible.

I also added the datastore as a separate project, as we do in gcloud-aio. Hoping to deprecate gcloud-rest and break it apart in the future. It just occurred to me that I should update the README and CONTRIBUTING files to explain that.

.pre-commit-config.yaml Show resolved Hide resolved
@@ -0,0 +1,69 @@
import requests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I split smoke_test.py, hoping to make it easier to add other query-related tests

datastore/tests/unit/value_test.py Show resolved Hide resolved
Copy link
Member

@TheKevJames TheKevJames left a comment

Choose a reason for hiding this comment

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

Verified tests locally

@TheKevJames TheKevJames merged commit c6be653 into talkiq:master Jul 9, 2019
@KevinGDialpad KevinGDialpad deleted the add_datastore branch July 9, 2019 18:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants