-
Notifications
You must be signed in to change notification settings - Fork 4
Conversation
There was a problem hiding this 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.
.pre-commit-config.py27.yaml
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
gcloud/rest/auth/__init__.py
Outdated
@@ -1,7 +1,10 @@ | |||
from pkg_resources import get_distribution |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
.pre-commit-config.py27.yaml
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
datastore/LICENSE
Outdated
@@ -0,0 +1,21 @@ | |||
MIT License | |||
|
|||
Copyright (c) 2017 TalkIQ |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ...
)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
gcloud/rest/auth/__init__.py
Outdated
@@ -1,7 +1,10 @@ | |||
from pkg_resources import get_distribution |
There was a problem hiding this comment.
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.
This should now be rebase-able onto v1.6.0 :) |
666d9db
to
d8916f0
Compare
There was a problem hiding this 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.
@@ -0,0 +1,69 @@ | |||
import requests |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified tests locally
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