Skip to content

Commit eadbc6a

Browse files
committed
Add docstrings to pacify pylint.
See #238 (comment).
1 parent 61232de commit eadbc6a

7 files changed

Lines changed: 128 additions & 4 deletions

File tree

gcloud/__init__.py

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

gcloud/connection.py

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

35
import httplib2
@@ -31,6 +33,10 @@ def __init__(self, credentials=None):
3133

3234
@property
3335
def credentials(self):
36+
"""
37+
:rtype: :class:`oauth2client.client.OAuth2Credentials`, or None
38+
:returns: The credentials object associated with this connection.
39+
"""
3440
return self._credentials
3541

3642
@property

gcloud/datastore/connection.py

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Connections to gcloud datastore API servers.
2+
"""
13
from gcloud import connection
24
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
35
from gcloud.datastore import _helpers
@@ -59,6 +61,22 @@ def _request(self, dataset_id, method, data):
5961
return content
6062

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

96114
def transaction(self, transaction=connection.Connection._EMPTY):
115+
"""Getter/setter for the connection's transaction object.
116+
117+
:type transaction: :class:`gcloud.datastore.transaction.Transaction`,
118+
(setting), or omitted (getting).
119+
:param transaction: The new transaction (if passed).
120+
121+
:rtype: :class:`gcloud.datastore.transaction.Transaction`, (getting)
122+
or :class:`gcloud.datastore.connection.Connection' (setting)
123+
:returns: the current transaction (getting) or self (setting).
124+
"""
97125
if transaction is self._EMPTY:
98126
return self._current_transaction
99127
else:
100128
self._current_transaction = transaction
101129
return self
102130

103131
def mutation(self):
132+
"""Getter for mutation usable with current connection.
133+
134+
:rtype: :class:`gcloud.datastore.datastore_v1_pb2.Mutation`.
135+
:returns: the mutation instance associated with the current transaction
136+
(if one exists) or or a new mutation instance.
137+
"""
104138
if self.transaction():
105139
return self.transaction().mutation()
106140
else:
@@ -278,6 +312,17 @@ def lookup(self, dataset_id, key_pbs):
278312
return results
279313

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

283328
if self.transaction():
@@ -350,8 +395,11 @@ def delete_entities(self, dataset_id, key_pbs):
350395
:param dataset_id: The dataset from which to delete the keys.
351396
352397
: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.
398+
:param key_pbs: The keys to delete from the datastore.
399+
400+
:rtype: boolean (if in a transaction) or else
401+
:class:`gcloud.datastore.datastore_v1_pb2.MutationResult`.
402+
:returns: True (if in a transaction) or else a mutation result protobuf.
355403
"""
356404
mutation = self.mutation()
357405

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

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

gcloud/datastore/dataset.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Wrapper for gcloud datastore datasets.
2+
"""
3+
14
class Dataset(object):
25
"""A dataset in the Cloud Datastore.
36
@@ -58,34 +61,67 @@ def id(self):
5861
return self._id
5962

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

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

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

74103
def get_entity(self, key):
75-
"""Retrieves entity from the dataset, along with all of its attributes.
104+
"""Retrieves entity from the dataset, along with its attributes.
76105
77106
:type key: :class:`gcloud.datastore.key.Key`
78107
:param item_name: The name of the item to retrieve.
79108
80109
:rtype: :class:`gcloud.datastore.entity.Entity` or ``None``
81110
:return: The requested entity, or ``None`` if there was no match found.
82-
83111
"""
84112
entities = self.get_entities([key])
85113
if entities:
86114
return entities[0]
87115

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

gcloud/datastore/key.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Wrapper for gcloud datastore keys.
2+
"""
3+
14
import copy
25
from itertools import izip
36

gcloud/datastore/query.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Wrapper for gcloud datastore queries.
2+
"""
3+
14
import base64
25
import copy
36

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

6265
def _clone(self):
66+
"""Create a new Query, copying self.
67+
68+
:rtype: :class:`gcloud.datastore.query.Query`
69+
:returns: a copy of 'self'.
70+
"""
6371
clone = copy.deepcopy(self)
6472
clone._dataset = self._dataset # Shallow copy the dataset.
6573
return clone

gcloud/datastore/transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Wrapper for gcloud datastore transactions.
2+
"""
3+
14
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
25
from gcloud.datastore.key import Key
36

0 commit comments

Comments
 (0)