Skip to content

Commit d4762d9

Browse files
fboxwalaagjohnson
authored andcommitted
pep257ifys core and api (#2245)
1 parent b5c8f87 commit d4762d9

21 files changed

+76
-63
lines changed

prospector.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ mccabe:
3434

3535
pep257:
3636
run: false
37+
disable:
38+
- D105
39+
- D211
40+
- D104
3741

3842
pyflakes:
3943
disable:

readthedocs/api/utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919

2020

2121
class SearchMixin(object):
22-
'''
22+
23+
"""
2324
Adds a search api to any ModelResource provided the model is indexed.
25+
2426
The search can be configured using the Meta class in each ModelResource.
2527
The search is limited to the model defined by the meta queryset. If the
2628
search is invalid, a 400 Bad Request will be raised.
2729
2830
e.g.
31+
2932
class Meta:
3033
# Return facet counts for each facetname
3134
search_facets = ['facetname1', 'facetname1']
@@ -35,7 +38,8 @@ class Meta:
3538
3639
# Highlight search terms in the text
3740
search_highlight = True
38-
'''
41+
"""
42+
3943
def get_search(self, request, **kwargs):
4044
self.method_check(request, allowed=['get'])
4145
self.is_authenticated(request)
@@ -49,11 +53,12 @@ def get_search(self, request, **kwargs):
4953
return self.create_response(request, object_list)
5054

5155
def _url_template(self, query, selected_facets):
52-
'''
56+
"""
5357
Construct a url template to assist with navigating the resources.
58+
5459
This looks a bit nasty but urllib.urlencode resulted in even
5560
nastier output...
56-
'''
61+
"""
5762
query_params = []
5863
for facet in selected_facets:
5964
query_params.append(('selected_facets', facet))
@@ -67,12 +72,13 @@ def _url_template(self, query, selected_facets):
6772

6873
def _search(self, request, model, facets=None, page_size=20,
6974
highlight=True):
70-
'''
75+
"""
7176
`facets`
77+
7278
A list of facets to include with the results
7379
`models`
7480
Limit the search to one or more models
75-
'''
81+
"""
7682
form = FacetedSearchForm(request.GET, facets=facets or [],
7783
models=(model,), load_all=True)
7884
if not form.is_valid():

readthedocs/core/forms.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,34 @@ def save(self, *args, **kwargs):
4242

4343
class FacetField(forms.MultipleChoiceField):
4444

45-
'''
46-
For filtering searches on a facet, with validation for the format
47-
of facet values.
48-
'''
45+
"""
46+
For filtering searches on a facet.
47+
48+
Has validation for the format of facet values.
49+
"""
4950

5051
def valid_value(self, value):
51-
'''
52+
"""
5253
Although this is a choice field, no choices need to be supplied.
54+
5355
Instead, we just validate that the value is in the correct format
5456
for facet filtering (facet_name:value)
55-
'''
57+
"""
5658
if ":" not in value:
5759
return False
5860
return True
5961

6062

6163
class FacetedSearchForm(SearchForm):
6264

63-
'''
65+
"""
6466
Supports fetching faceted results with a corresponding query.
6567
6668
`facets`
6769
A list of facet names for which to get facet counts
6870
`models`
6971
Limit the search to one or more models
70-
'''
72+
"""
7173

7274
selected_facets = FacetField(required=False)
7375

readthedocs/core/management/commands/archive.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111

1212
class Command(BaseCommand):
13-
"""Custom management command to rebuild documentation for all projects on
14-
the site. Invoked via ``./manage.py update_repos``.
13+
14+
"""
15+
Custom management command to rebuild documentation for all projects.
16+
17+
Invoked via ``./manage.py update_repos``.
1518
"""
1619

1720
def handle(self, *args, **options):

readthedocs/core/management/commands/clean_builds.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class Command(BaseCommand):
2727
)
2828

2929
def handle(self, *args, **options):
30-
'''
31-
Find stale builds and remove build paths
32-
'''
30+
"""Find stale builds and remove build paths"""
3331
max_date = datetime.now() - timedelta(days=options['days'])
3432
queryset = (Build.objects
3533
.values('project', 'version')

readthedocs/core/management/commands/reindex_elasticsearch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class Command(BaseCommand):
2222
)
2323

2424
def handle(self, *args, **options):
25-
'''
26-
Build/index all versions or a single project's version
27-
'''
25+
"""Build/index all versions or a single project's version"""
2826
project = options['project']
2927

3028
queryset = Version.objects.public()

readthedocs/core/management/commands/sync_builds.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010

1111
class Command(BaseCommand):
12-
"""Custom management command to rebuild documentation for all projects on
13-
the site. Invoked via ``./manage.py update_repos``.
12+
13+
"""
14+
Custom management command to rebuild documentation for all projects.
15+
16+
Invoked via ``./manage.py update_repos``.
1417
"""
1518

1619
option_list = BaseCommand.option_list + (

readthedocs/core/management/commands/update_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
class Command(BaseCommand):
12+
1213
"""
1314
Build documentation using the API and not hitting a database.
1415

readthedocs/core/management/commands/update_repos.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
class Command(BaseCommand):
1414

15-
"""Custom management command to rebuild documentation for all projects on
16-
the site. Invoked via ``./manage.py update_repos``.
15+
"""
16+
Custom management command to rebuild documentation for all projects.
17+
18+
Invoked via ``./manage.py update_repos``.
1719
"""
1820

1921
option_list = BaseCommand.option_list + (

readthedocs/core/management/commands/update_versions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66

77
class Command(BaseCommand):
8-
"""Custom management command to rebuild documentation for all projects on
9-
the site. Invoked via ``./manage.py update_repos``.
8+
9+
"""
10+
Custom management command to rebuild documentation for all projects.
11+
12+
Invoked via ``./manage.py update_repos``.
1013
"""
1114

1215
def handle(self, *args, **options):

readthedocs/core/middleware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class ProxyMiddleware(object):
178178

179179
"""
180180
Middleware that sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, if the
181+
181182
latter is set. This is useful if you're sitting behind a reverse proxy that
182183
causes each request's REMOTE_ADDR to be set to 127.0.0.1.
183184
Note that this does NOT validate HTTP_X_FORWARDED_FOR. If you're not behind
@@ -207,6 +208,7 @@ class FooterNoSessionMiddleware(SessionMiddleware):
207208
208209
This will reduce the size of our session table drastically.
209210
"""
211+
210212
IGNORE_URLS = ['/api/v2/footer_html', '/sustainability/view', '/sustainability/click']
211213

212214
def process_request(self, request):

readthedocs/core/mixins.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Common mixin classes for views
3-
"""
1+
"""Common mixin classes for views"""
42

53
from vanilla import ListView
64
from django.contrib.auth.decorators import login_required

readthedocs/core/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
class UserProfile (models.Model):
1616

17-
"""Additional information about a User.
18-
"""
17+
"""Additional information about a User."""
18+
1919
user = AutoOneToOneField('auth.User', verbose_name=_('User'),
2020
related_name='profile')
2121
whitelisted = models.BooleanField(_('Whitelisted'), default=False)

readthedocs/core/symlink.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070

7171
class Symlink(object):
72+
7273
"""Base class for symlinking of projects."""
7374

7475
def __init__(self, project):

readthedocs/core/templatetags/core_tags.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
@register.filter
1616
def gravatar(email, size=48):
17-
"""hacked from djangosnippets.org, but basically given an email address
17+
"""
18+
hacked from djangosnippets.org, but basically given an email address
19+
1820
render an img tag with the hashed up bits needed for leetness
1921
omgwtfstillreading
20-
2122
"""
2223
url = "http://www.gravatar.com/avatar.php?%s" % urllib.urlencode({
2324
'gravatar_id': hashlib.md5(email).hexdigest(),

readthedocs/core/utils/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717

1818
def run_on_app_servers(command):
19-
"""
20-
A helper to copy a single file across app servers
21-
"""
19+
"""A helper to copy a single file across app servers"""
2220
log.info("Running %s on app servers" % command)
2321
ret_val = 0
2422
if getattr(settings, "MULTIPLE_APP_SERVERS", None):

readthedocs/core/utils/tasks/public.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@
1414

1515

1616
class PublicTask(Task):
17+
1718
"""
1819
See oauth.tasks for usage example.
1920
2021
Subclasses need to define a ``run_public`` method.
2122
"""
23+
2224
public_name = 'unknown'
2325

2426
@classmethod
2527
def check_permission(cls, request, state, context):
26-
"""
27-
Override this method to define who can monitor this task.
28-
"""
28+
"""Override this method to define who can monitor this task."""
2929
return False
3030

3131
def get_task_data(self):
32-
"""
33-
Return a tuple with the state that should be set next and the results
34-
task.
35-
"""
32+
"""Return tuple with state to be set next and results task."""
3633
state = 'STARTED'
3734
info = {
3835
'task_name': self.name,
@@ -49,6 +46,7 @@ def update_progress_data(self):
4946
def set_permission_context(self, context):
5047
"""
5148
Set data that can be used by ``check_permission`` to authorize a
49+
5250
request for the this task. By default it will be the ``kwargs`` passed
5351
into the task.
5452
"""
@@ -58,6 +56,7 @@ def set_permission_context(self, context):
5856
def set_public_data(self, data):
5957
"""
6058
Set data that can be displayed in the frontend to authorized users.
59+
6160
This might include progress data about the task.
6261
"""
6362
self.request.update(public_data=data)
@@ -83,14 +82,14 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
8382
def permission_check(check):
8483
"""
8584
Class decorator for subclasses of PublicTask to sprinkle in re-usable
85+
8686
permission checks::
8787
8888
@permission_check(user_id_matches)
8989
class MyTask(PublicTask):
9090
def run_public(self, user_id):
9191
pass
9292
"""
93-
9493
def decorator(cls):
9594
cls.check_permission = staticmethod(check)
9695
return cls

readthedocs/core/utils/tasks/retrieve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def __init__(self, task_id, *args, **kwargs):
1414
def get_task_data(task_id):
1515
"""
1616
Will raise `TaskNotFound` if the task is in state ``PENDING`` or the task
17+
1718
meta data has no ``'task_name'`` key set.
1819
"""
19-
2020
result = AsyncResult(task_id)
2121
state, info = result.state, result.info
2222
if state == 'PENDING':

0 commit comments

Comments
 (0)