Skip to content

Commit 936ff32

Browse files
committed
Adding docstrings to new code in pylint fix.
1 parent af1d5d7 commit 936ff32

File tree

4 files changed

+84
-38
lines changed

4 files changed

+84
-38
lines changed

gcloud/storage/_helpers.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,37 @@
55

66

77
class _MetadataMixin(object):
8-
"""Needs class docstring."""
8+
"""Abstract mixin for cloud storage classes with associated metadata.
9+
10+
Expected to be subclasses by :class:`gcloud.storage.bucket.Bucket`
11+
and :class:`gcloud.storage.key.Key` and both of those classes
12+
will implemented the abstract parts:
13+
- LOAD_FULL_FIELDS
14+
- ACL_CLASS
15+
- ACL_KEYWORD
16+
- connection
17+
- path
18+
"""
919

1020
LOAD_FULL_FIELDS = None
11-
"""Class data attribute docstring."""
21+
"""Tuple of fields which pertain to metadata.
22+
23+
Expected to be set by subclasses. Fields in this tuple will cause
24+
`get_metadata()` to do a full reload of all metadata before
25+
returning.
26+
"""
1227

1328
ACL_CLASS = type(None)
14-
"""Class data attribute docstring."""
29+
"""Class which holds ACL data for a given type.
30+
31+
Expected to be set by subclasses.
32+
"""
1533

1634
ACL_KEYWORD = None
17-
"""Class data attribute docstring."""
35+
"""Keyword for ACL_CLASS constructor to pass an object in.
36+
37+
Expected to be set by subclasses.
38+
"""
1839

1940
def __init__(self):
2041
# These should be set by the superclass.
@@ -23,12 +44,12 @@ def __init__(self):
2344

2445
@property
2546
def connection(self):
26-
"""Needs property docstring."""
47+
"""Abstract getter for the connection to use."""
2748
raise NotImplementedError
2849

2950
@property
3051
def path(self):
31-
"""Needs property docstring."""
52+
"""Abstract getter for the object path."""
3253
raise NotImplementedError
3354

3455
def has_metadata(self, field=None):

gcloud/storage/bucket.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class Bucket(_MetadataMixin):
2121
"""
2222

2323
LOAD_FULL_FIELDS = ('acl', 'defaultObjectAcl')
24-
"""Class data attribute docstring."""
24+
"""Tuple of metadata fields pertaining to bucket ACLs."""
2525

2626
ACL_CLASS = BucketACL
27-
"""Class data attribute docstring."""
27+
"""Class which holds ACL data for buckets."""
2828

2929
ACL_KEYWORD = 'bucket'
30-
"""Class data attribute docstring."""
30+
"""Keyword for BucketACL constructor to pass a bucket in."""
3131

3232
def __init__(self, connection=None, name=None, metadata=None):
3333
super(Bucket, self).__init__()
@@ -66,7 +66,11 @@ def __contains__(self, key):
6666

6767
@property
6868
def connection(self):
69-
"""Needs property docstring."""
69+
"""Getter property for the connection to use with this Bucket.
70+
71+
:rtype: :class:`gcloud.storage.connection.Connection`
72+
:returns: The connection to use.
73+
"""
7074
return self._connection
7175

7276
@property

gcloud/storage/key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class Key(_MetadataMixin):
1414
"""A wrapper around Cloud Storage's concept of an ``Object``."""
1515

1616
LOAD_FULL_FIELDS = ('acl',)
17-
"""Class data attribute docstring."""
17+
"""Tuple of metadata fields pertaining to key ACLs."""
1818

1919
ACL_CLASS = ObjectACL
20-
"""Class data attribute docstring."""
20+
"""Class which holds ACL data for keys."""
2121

2222
ACL_KEYWORD = 'key'
23-
"""Class data attribute docstring."""
23+
"""Keyword for ObjectACL constructor to pass a key in."""
2424

2525
CHUNK_SIZE = 1024 * 1024 # 1 MB.
2626
"""The size of a chunk of data whenever iterating (1 MB).

run_pylint.py

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,81 @@
1-
"""Needs module docstring."""
1+
"""Custom script to run PyLint on gcloud codebase.
22
3+
This runs pylint as a script via subprocess in two different
4+
subprocesses. The first lints the production/library code
5+
using the default rc file (PRODUCTION_RC). The second lints the
6+
demo/test code using an rc file (TEST_RC) which allows more style
7+
violations (hence it has a reduced number of style checks).
8+
"""
39

410
import subprocess
511
import sys
612

713

8-
IGNORED = [
14+
IGNORED_FILES = [
915
'gcloud/datastore/datastore_v1_pb2.py',
1016
'docs/conf.py',
1117
'setup.py',
1218
]
19+
PRODUCTION_RC = 'pylintrc_default'
20+
TEST_RC = 'pylintrc_reduced'
1321

1422

1523
def valid_filename(filename):
16-
"""Needs method docstring."""
24+
"""Checks if a file is a Python file and is not ignored."""
1725
return (filename.endswith('.py') and
18-
filename not in IGNORED)
26+
filename not in IGNORED_FILES)
27+
28+
29+
def is_production_filename(filename):
30+
"""Checks if the file contains production code.
31+
32+
:rtype: `bool`
33+
:returns: Boolean indicating production status.
34+
"""
35+
return not ('demo' in filename or 'test' in filename)
1936

2037

2138
def get_python_files():
22-
"""Needs method docstring."""
39+
"""Gets a list of all Python files in the repository.
40+
41+
NOTE: This requires `git` to be installed and requires that this
42+
is run within the `git` repository.
43+
44+
:rtype: `tuple`
45+
:returns: A tuple containing two lists. The first list contains
46+
all production files and the next all test/demo files.
47+
"""
2348
all_files = subprocess.check_output(['git', 'ls-files'])
2449

2550
library_files = []
2651
non_library_files = []
2752
for filename in all_files.split('\n'):
2853
if valid_filename(filename):
29-
if 'demo' in filename or 'test' in filename:
30-
non_library_files.append(filename)
31-
else:
54+
if is_production_filename(filename):
3255
library_files.append(filename)
56+
else:
57+
non_library_files.append(filename)
3358

3459
return library_files, non_library_files
3560

3661

37-
def main():
38-
"""Needs method docstring."""
39-
library_files, non_library_files = get_python_files()
40-
# Use default RC file with the code from the library.
41-
pylint_library_code = (['pylint', '--rcfile=pylintrc_default'] +
42-
library_files)
43-
status_code = subprocess.call(pylint_library_code)
62+
def lint_fileset(filenames, rcfile, description):
63+
"""Lints a group of files using a given rcfile."""
64+
rc_flag = '--rcfile=%s' % (rcfile,)
65+
pylint_shell_command = ['pylint', rc_flag] + filenames
66+
status_code = subprocess.call(pylint_shell_command)
4467
if status_code != 0:
45-
error_message = ('Pylint failed on library code with '
46-
'status %d.' % (status_code,))
68+
error_message = ('Pylint failed on %s with '
69+
'status %d.' % (description, status_code))
4770
print >> sys.stderr, error_message
4871
sys.exit(status_code)
4972

50-
pylint_non_library_code = (['pylint', '--rcfile=pylintrc_reduced']
51-
+ non_library_files)
52-
status_code = subprocess.call(pylint_non_library_code)
53-
if status_code != 0:
54-
error_message = ('Pylint failed on test and demo code with '
55-
'status %d.' % (status_code,))
56-
print >> sys.stderr, error_message
57-
sys.exit(status_code)
73+
74+
def main():
75+
"""Script entry point. Lints both sets of files."""
76+
library_files, non_library_files = get_python_files()
77+
lint_fileset(library_files, PRODUCTION_RC, 'library code')
78+
lint_fileset(non_library_files, TEST_RC, 'test and demo code')
5879

5980

6081
if __name__ == '__main__':

0 commit comments

Comments
 (0)