Skip to content

Commit 11c8765

Browse files
committed
Merge pull request #240 from tseaver/docstrings-datastore
Add gcloud.* and gcloud.datastore.* docstrings to pacify pylint.
2 parents 61232de + 56458c2 commit 11c8765

File tree

7 files changed

+121
-4
lines changed

7 files changed

+121
-4
lines changed

gcloud/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
"""GCloud API access in idiomatic Python."""
12
__version__ = '0.02.2'

gcloud/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
""" Shared implementation of connections to API servers."""
12
from pkg_resources import get_distribution
23

34
import httplib2
@@ -31,6 +32,10 @@ def __init__(self, credentials=None):
3132

3233
@property
3334
def credentials(self):
35+
"""
36+
:rtype: :class:`oauth2client.client.OAuth2Credentials`, or None
37+
:returns: The credentials object associated with this connection.
38+
"""
3439
return self._credentials
3540

3641
@property

gcloud/datastore/connection.py

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Connections to gcloud datastore API servers."""
12
from gcloud import connection
23
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
34
from gcloud.datastore import _helpers
@@ -59,6 +60,22 @@ def _request(self, dataset_id, method, data):
5960
return content
6061

6162
def _rpc(self, dataset_id, method, request_pb, response_pb_cls):
63+
""" Make a protobuf RPC request.
64+
65+
:type dataset_id: string
66+
:param dataset_id: The ID of the dataset to connect to. This is
67+
usually your project name in the cloud console.
68+
69+
:type method: string
70+
:param method: The name of the method to invoke.
71+
72+
:type request_pb: :class:`google.protobuf.message.Message` instance
73+
:param method: the protobuf instance representing the request.
74+
75+
:type response_pb_cls: a :class:`google.protobuf.message.Message'
76+
subclass.
77+
:param method: The class used to unmarshall the response protobuf.
78+
"""
6279
response = self._request(dataset_id=dataset_id, method=method,
6380
data=request_pb.SerializeToString())
6481
return response_pb_cls.FromString(response)
@@ -94,13 +111,29 @@ def build_api_url(cls, dataset_id, method, base_url=None,
94111
dataset_id=dataset_id, method=method)
95112

96113
def transaction(self, transaction=connection.Connection._EMPTY):
114+
"""Getter/setter for the connection's transaction object.
115+
116+
:type transaction: :class:`gcloud.datastore.transaction.Transaction`,
117+
(setting), or omitted (getting).
118+
:param transaction: The new transaction (if passed).
119+
120+
:rtype: :class:`gcloud.datastore.transaction.Transaction`, (getting)
121+
or :class:`gcloud.datastore.connection.Connection' (setting)
122+
:returns: the current transaction (getting) or self (setting).
123+
"""
97124
if transaction is self._EMPTY:
98125
return self._current_transaction
99126
else:
100127
self._current_transaction = transaction
101128
return self
102129

103130
def mutation(self):
131+
"""Getter for mutation usable with current connection.
132+
133+
:rtype: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
134+
:returns: the mutation instance associated with the current transaction
135+
(if one exists) or or a new mutation instance.
136+
"""
104137
if self.transaction():
105138
return self.transaction().mutation()
106139
else:
@@ -278,6 +311,17 @@ def lookup(self, dataset_id, key_pbs):
278311
return results
279312

280313
def commit(self, dataset_id, mutation_pb):
314+
"""Commit dataset mutations in context of current transation (if any).
315+
316+
:type dataset_id: string
317+
:param dataset_id: The dataset in which to perform the changes.
318+
319+
:type mutation_pb: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
320+
:param mutation_pb: The protobuf for the mutations being saved.
321+
322+
:rtype: :class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
323+
:returns': the result protobuf for the mutation.
324+
"""
281325
request = datastore_pb.CommitRequest()
282326

283327
if self.transaction():
@@ -350,8 +394,11 @@ def delete_entities(self, dataset_id, key_pbs):
350394
:param dataset_id: The dataset from which to delete the keys.
351395
352396
:type key_pbs: list of :class:`gcloud.datastore.datastore_v1_pb2.Key`
353-
(or a single Key)
354-
:param key_pbs: The key (or keys) to delete from the datastore.
397+
:param key_pbs: The keys to delete from the datastore.
398+
399+
:rtype: boolean (if in a transaction) or else
400+
:class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
401+
:returns: True (if in a transaction) or else a mutation result protobuf.
355402
"""
356403
mutation = self.mutation()
357404

@@ -365,4 +412,22 @@ def delete_entities(self, dataset_id, key_pbs):
365412
return self.commit(dataset_id, mutation)
366413

367414
def delete_entity(self, dataset_id, key_pb):
415+
"""Delete a single key from a dataset in the Cloud Datastore.
416+
417+
This method deals only with
418+
:class:`gcloud.datastore.datastore_v1_pb2.Key` protobufs
419+
and not with any of the other abstractions.
420+
For example, it's used under the hood in the
421+
:func:`gcloud.datastore.entity.Entity.delete` method.
422+
423+
:type dataset_id: string
424+
:param dataset_id: The dataset from which to delete the key.
425+
426+
:type key_pb: :class:`gcloud.datastore.datastore_v1_pb2.Key`
427+
:param key_pb: The key to delete from the datastore.
428+
429+
:rtype: boolean (if in a transaction) or else
430+
:class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
431+
:returns: True (if in a transaction) or else a mutation result protobuf.
432+
"""
368433
return self.delete_entities(dataset_id, [key_pb])

gcloud/datastore/dataset.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create / interact with gcloud datastore datasets."""
2+
13
class Dataset(object):
24
"""A dataset in the Cloud Datastore.
35
@@ -58,34 +60,67 @@ def id(self):
5860
return self._id
5961

6062
def query(self, *args, **kwargs):
63+
"""Create a query bound to this dataset.
64+
65+
:param args: positional arguments, passed through to the Query
66+
67+
:param kw: keyword arguments, passed through to the Query
68+
69+
:rtype: :class:`gcloud.datastore.query.Query`
70+
:returns: a new Query instance, bound to this dataset.
71+
"""
6172
from gcloud.datastore.query import Query
6273
kwargs['dataset'] = self
6374
return Query(*args, **kwargs)
6475

6576
def entity(self, kind):
77+
"""Create an entity bound to this dataset.
78+
79+
:type kind: string
80+
:param kind: the "kind" of the new entity.
81+
82+
:rtype: :class:`gcloud.datastore.entity.Entity`
83+
:returns: a new Entity instance, bound to this dataset.
84+
"""
6685
from gcloud.datastore.entity import Entity
6786
return Entity(dataset=self, kind=kind)
6887

6988
def transaction(self, *args, **kwargs):
89+
"""Create a transaction bound to this dataset.
90+
91+
:param args: positional arguments, passed through to the Transaction
92+
93+
:param kw: keyword arguments, passed through to the Transaction
94+
95+
:rtype: :class:`gcloud.datastore.transaction.Transaction`
96+
:returns: a new Transaction instance, bound to this dataset.
97+
"""
7098
from gcloud.datastore.transaction import Transaction
7199
kwargs['dataset'] = self
72100
return Transaction(*args, **kwargs)
73101

74102
def get_entity(self, key):
75-
"""Retrieves entity from the dataset, along with all of its attributes.
103+
"""Retrieves entity from the dataset, along with its attributes.
76104
77105
:type key: :class:`gcloud.datastore.key.Key`
78106
:param item_name: The name of the item to retrieve.
79107
80108
:rtype: :class:`gcloud.datastore.entity.Entity` or ``None``
81109
:return: The requested entity, or ``None`` if there was no match found.
82-
83110
"""
84111
entities = self.get_entities([key])
85112
if entities:
86113
return entities[0]
87114

88115
def get_entities(self, keys):
116+
"""Retrieves entities from the dataset, along with their attributes.
117+
118+
:type key: list of :class:`gcloud.datastore.key.Key`
119+
:param item_name: The name of the item to retrieve.
120+
121+
:rtype: list of :class:`gcloud.datastore.entity.Entity`
122+
:return: The requested entities.
123+
"""
89124
# This import is here to avoid circular references.
90125
from gcloud.datastore.entity import Entity
91126

gcloud/datastore/key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create / interact with gcloud datastore keys."""
2+
13
import copy
24
from itertools import izip
35

gcloud/datastore/query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create / interact with gcloud datastore queries."""
2+
13
import base64
24
import copy
35

@@ -60,6 +62,11 @@ def __init__(self, kind=None, dataset=None):
6062
self._pb.kind.add().name = kind
6163

6264
def _clone(self):
65+
"""Create a new Query, copying self.
66+
67+
:rtype: :class:`gcloud.datastore.query.Query`
68+
:returns: a copy of 'self'.
69+
"""
6370
clone = copy.deepcopy(self)
6471
clone._dataset = self._dataset # Shallow copy the dataset.
6572
return clone

gcloud/datastore/transaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create / interact with gcloud datastore transactions."""
2+
13
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
24
from gcloud.datastore.key import Key
35

0 commit comments

Comments
 (0)