Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions core/.flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
import-order-style=google
exclude =
__pycache__,
.git,
Expand Down
2 changes: 2 additions & 0 deletions core/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google namespace package."""

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
Expand Down
2 changes: 2 additions & 0 deletions core/google/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google Cloud namespace package."""

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
Expand Down
3 changes: 1 addition & 2 deletions core/google/cloud/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
This module is not part of the public API surface.
"""

# Avoid the grpc and google.cloud.grpc collision.
from __future__ import absolute_import

import calendar
Expand Down Expand Up @@ -104,7 +103,7 @@ def top(self):
:rtype: object
:returns: the top-most item, or None if the stack is empty.
"""
if len(self._stack) > 0:
if self._stack:
return self._stack[-1]


Expand Down
4 changes: 3 additions & 1 deletion core/google/cloud/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ def api_request(self, method, path, query_params=None,
can allow custom behavior, for example, to defer an HTTP request
and complete initialization of the object at a later time.

:raises: Exception if the response code is not 200 OK.
:raises ~google.cloud.exceptions.GoogleCloudError: if the response code
is not 200 OK.
:raises TypeError: if the response content type is not JSON.

This comment was marked as spam.

This comment was marked as spam.

:rtype: dict or str
:returns: The API response payload, either as a raw string or
a dictionary if the response is valid JSON.
Expand Down
14 changes: 9 additions & 5 deletions core/google/cloud/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@

"""Shared testing utilities."""


# Avoid the grpc and google.cloud.grpc collision.
from __future__ import absolute_import


class _Monkey(object):
# context-manager for replacing module names in the scope of a test.
"""Context-manager for replacing module names in the scope of a test."""

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 __init__(self, module, **kw):
self.module = module
if len(kw) == 0: # pragma: NO COVER
if not kw: # pragma: NO COVER
raise ValueError('_Monkey was used with nothing to monkey-patch')
self.to_restore = {key: getattr(module, key) for key in kw}
for key, value in kw.items():
Expand Down Expand Up @@ -68,8 +66,12 @@ def _tempdir_mgr():
return _tempdir_mgr


# pylint: disable=invalid-name
# Retain _tempdir as a constant for backwards compatibility despite

This comment was marked as spam.

This comment was marked as spam.

# being an invalid name.
_tempdir = _tempdir_maker()
del _tempdir_maker
# pylint: enable=invalid-name


class _GAXBaseAPI(object):
Expand All @@ -79,7 +81,8 @@ class _GAXBaseAPI(object):
def __init__(self, **kw):
self.__dict__.update(kw)

def _make_grpc_error(self, status_code, trailing=None):
@staticmethod
def _make_grpc_error(status_code, trailing=None):
from grpc._channel import _RPCState
from google.cloud.exceptions import GrpcRendezvous

Expand Down Expand Up @@ -111,6 +114,7 @@ def __init__(self, *pages, **kwargs):
self.page_token = kwargs.get('page_token')

def next(self):
"""Iterate to the next page."""
import six
return six.next(self._pages)

Expand Down
2 changes: 1 addition & 1 deletion core/google/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def from_service_account_json(cls, json_credentials_path, *args, **kwargs):

:rtype: :class:`_ClientFactoryMixin`
:returns: The client created with the retrieved JSON credentials.
:raises: :class:`TypeError` if there is a conflict with the kwargs
:raises TypeError: if there is a conflict with the kwargs
and the credentials created by the factory.

This comment was marked as spam.

This comment was marked as spam.

"""
if 'credentials' in kwargs:
Expand Down
2 changes: 1 addition & 1 deletion core/google/cloud/future/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Operation(base.PollingFuture):
initial operation.
refresh (Callable[[], Operation]): A callable that returns the
latest state of the operation.
cancel (Callable[[], None]), A callable that tries to cancel
cancel (Callable[[], None]): A callable that tries to cancel
the operation.
result_type (type): The protobuf type for the operation's result.
metadata_type (type): The protobuf type for the operation's
Expand Down
6 changes: 3 additions & 3 deletions core/google/cloud/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ def to_api_repr(self):
if self.version is not None:
resource['version'] = self.version

if len(self._bindings) > 0:
if self._bindings:
bindings = resource['bindings'] = []
for role, members in sorted(self._bindings.items()):
if len(members) > 0:
if members:
bindings.append(
{'role': role, 'members': sorted(set(members))})

if len(bindings) == 0:
if not bindings:
del resource['bindings']

return resource
Expand Down
5 changes: 4 additions & 1 deletion core/google/cloud/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def _page_iter(self, increment):
results per page while an items iterator will want
to increment per item.

Yields :class:`Page` instances.
:rtype: :class:`Page`
:returns: pages

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

"""
page = self._next_page()
while page is not None:
Expand Down Expand Up @@ -387,6 +388,8 @@ def _get_next_page_response(self):

:rtype: dict
:returns: The parsed JSON response of the next page's contents.

:raises ValueError: If the HTTP method is not ``GET`` or ``POST``.
"""
params = self._get_query_params()
if self._HTTP_METHOD == 'GET':
Expand Down
4 changes: 2 additions & 2 deletions core/google/cloud/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def register_type(klass, type_url=None):
:param type_url: (Optional) URL naming the type. If not provided,
infers the URL from the type descriptor.

:raises: ValueError if a registration already exists for the URL.
:raises ValueError: if a registration already exists for the URL.
"""
if type_url is None:
type_url = _compute_type_url(klass)
Expand Down Expand Up @@ -258,7 +258,7 @@ def poll(self):

:rtype: bool
:returns: A boolean indicating if the current operation has completed.
:raises: :class:`~exceptions.ValueError` if the operation
:raises ValueError: if the operation
has already completed.
"""
if self.complete:
Expand Down
3 changes: 2 additions & 1 deletion core/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def lint(session):
serious code quality issues.
"""
session.interpreter = 'python3.6'
session.install('flake8', 'pylint', 'gcp-devrel-py-tools')
session.install(
'flake8', 'flake8-import-order', 'pylint', 'gcp-devrel-py-tools')
session.install('.')
session.run('flake8', 'google/cloud/core')
session.run(
Expand Down