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

Add gcloud.* and gcloud.datastore.* docstrings to pacify pylint. #240

Merged
merged 5 commits into from
Oct 14, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions gcloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""GCloud API wrappers in idiomatic Python.
"""

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

__version__ = '0.02.2'
6 changes: 6 additions & 0 deletions gcloud/connection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
""" Shared implementation of connections to API servers.
"""

This comment was marked as spam.

from pkg_resources import get_distribution

import httplib2
Expand Down Expand Up @@ -31,6 +33,10 @@ def __init__(self, credentials=None):

@property
def credentials(self):
"""
:rtype: :class:`oauth2client.client.OAuth2Credentials`, or None
:returns: The credentials object associated with this connection.
"""
return self._credentials

@property
Expand Down
70 changes: 68 additions & 2 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Connections to gcloud datastore API servers.
"""
from gcloud import connection
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
from gcloud.datastore import _helpers
Expand Down Expand Up @@ -59,6 +61,22 @@ def _request(self, dataset_id, method, data):
return content

def _rpc(self, dataset_id, method, request_pb, response_pb_cls):
""" Make an protobuf RPC request.

This comment was marked as spam.


:type dataset_id: string
:param dataset_id: The ID of the dataset to connect to. This is
usually your project name in the cloud console.

:type method: string
:param method: The name of the method to invoke.

:type request_pb: :class:`google.protobuf.message.Message` instance
:param method: the protobuf instance representing the request.

:type response_pb_cls: a :class:`google.protobuf.message.Message'
subclass.
:param method: The class used to unmarshall the response protobuf.
"""
response = self._request(dataset_id=dataset_id, method=method,
data=request_pb.SerializeToString())
return response_pb_cls.FromString(response)
Expand Down Expand Up @@ -94,13 +112,29 @@ def build_api_url(cls, dataset_id, method, base_url=None,
dataset_id=dataset_id, method=method)

def transaction(self, transaction=connection.Connection._EMPTY):
"""Getter/setter for the connection's transaction object.

:type transaction: :class:`gcloud.datastore.transaction.Transaction`,
(setting), or omitted (getting).
:param transaction: The new transaction (if passed).

:rtype: :class:`gcloud.datastore.transaction.Transaction`, (getting)
or :class:`gcloud.datastore.connection.Connection' (setting)
:returns: the current transaction (getting) or self (setting).
"""
if transaction is self._EMPTY:
return self._current_transaction
else:
self._current_transaction = transaction
return self

def mutation(self):
"""Getter for mutation usable with current connection.

:rtype: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
:returns: the mutation instance associated with the current transaction
(if one exists) or or a new mutation instance.
"""
if self.transaction():
return self.transaction().mutation()
else:
Expand Down Expand Up @@ -278,6 +312,17 @@ def lookup(self, dataset_id, key_pbs):
return results

def commit(self, dataset_id, mutation_pb):
"""Commit dataset mutations in context of current transation (if any).

:type dataset_id: string
:param dataset_id: The dataset in which to perform the changes.

:type mutation_pb: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
:param mutation_pb: The protobuf for the mutations being saved.

:rtype: :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
:returns': the result protobuf for the mutation.
"""
request = datastore_pb.CommitRequest()

if self.transaction():
Expand Down Expand Up @@ -350,8 +395,11 @@ def delete_entities(self, dataset_id, key_pbs):
:param dataset_id: The dataset from which to delete the keys.

:type key_pbs: list of :class:`gcloud.datastore.datastore_v1_pb2.Key`
(or a single Key)
:param key_pbs: The key (or keys) to delete from the datastore.
:param key_pbs: The keys to delete from the datastore.

:rtype: boolean (if in a transaction) or else
:class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
:returns: True (if in a transaction) or else a mutation result protobuf.
"""
mutation = self.mutation()

Expand All @@ -365,4 +413,22 @@ def delete_entities(self, dataset_id, key_pbs):
return self.commit(dataset_id, mutation)

def delete_entity(self, dataset_id, key_pb):
"""Delete a single key from a dataset in the Cloud Datastore.

This method deals only with
:class:`gcloud.datastore.datastore_v1_pb2.Key` protobufs
and not with any of the other abstractions.
For example, it's used under the hood in the
:func:`gcloud.datastore.entity.Entity.delete` method.

:type dataset_id: string
:param dataset_id: The dataset from which to delete the key.

:type key_pb: :class:`gcloud.datastore.datastore_v1_pb2.Key`
:param key_pb: The key to delete from the datastore.

:rtype: boolean (if in a transaction) or else
:class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
:returns: True (if in a transaction) or else a mutation result protobuf.
"""
return self.delete_entities(dataset_id, [key_pb])
40 changes: 38 additions & 2 deletions gcloud/datastore/dataset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Wrapper for gcloud datastore datasets.
"""

class Dataset(object):
"""A dataset in the Cloud Datastore.

Expand Down Expand Up @@ -58,34 +61,67 @@ def id(self):
return self._id

def query(self, *args, **kwargs):
"""Create a query bound to this dataset.

:param args: positional arguments, passed through to the Query

:param kw: keyword arguments, passed through to the Query

:rtype: :class:`gcloud.datastore.query.Query`
:returns: a new Query instance, bound to this dataset.
"""
from gcloud.datastore.query import Query
kwargs['dataset'] = self
return Query(*args, **kwargs)

def entity(self, kind):
"""Create an entity bound to this dataset.

:type kind: string
:param kind: the "kind" of the new entity.

:rtype: :class:`gcloud.datastore.entity.Entity`
:returns: a new Entity instance, bound to this dataset.
"""
from gcloud.datastore.entity import Entity
return Entity(dataset=self, kind=kind)

def transaction(self, *args, **kwargs):
"""Create a transaction bound to this dataset.

:param args: positional arguments, passed through to the Transaction

:param kw: keyword arguments, passed through to the Transaction

:rtype: :class:`gcloud.datastore.transaction.Transaction`
:returns: a new Transaction instance, bound to this dataset.
"""
from gcloud.datastore.transaction import Transaction
kwargs['dataset'] = self
return Transaction(*args, **kwargs)

def get_entity(self, key):
"""Retrieves entity from the dataset, along with all of its attributes.
"""Retrieves entity from the dataset, along with its attributes.

:type key: :class:`gcloud.datastore.key.Key`
:param item_name: The name of the item to retrieve.

:rtype: :class:`gcloud.datastore.entity.Entity` or ``None``
:return: The requested entity, or ``None`` if there was no match found.

"""
entities = self.get_entities([key])
if entities:
return entities[0]

def get_entities(self, keys):
"""Retrieves entities from the dataset, along with their attributes.

:type key: list of :class:`gcloud.datastore.key.Key`
:param item_name: The name of the item to retrieve.

:rtype: list of :class:`gcloud.datastore.entity.Entity`
:return: The requested entities.
"""
# This import is here to avoid circular references.
from gcloud.datastore.entity import Entity

Expand Down
3 changes: 3 additions & 0 deletions gcloud/datastore/key.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Wrapper for gcloud datastore keys.

This comment was marked as spam.

"""

import copy
from itertools import izip

Expand Down
8 changes: 8 additions & 0 deletions gcloud/datastore/query.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Wrapper for gcloud datastore queries.
"""

import base64
import copy

Expand Down Expand Up @@ -60,6 +63,11 @@ def __init__(self, kind=None, dataset=None):
self._pb.kind.add().name = kind

def _clone(self):
"""Create a new Query, copying self.

:rtype: :class:`gcloud.datastore.query.Query`
:returns: a copy of 'self'.
"""
clone = copy.deepcopy(self)
clone._dataset = self._dataset # Shallow copy the dataset.
return clone
Expand Down
3 changes: 3 additions & 0 deletions gcloud/datastore/transaction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Wrapper for gcloud datastore transactions.
"""

from gcloud.datastore import datastore_v1_pb2 as datastore_pb
from gcloud.datastore.key import Key

Expand Down