Skip to content

Commit 6c7ee46

Browse files
authored
Merge pull request readthedocs#2911 from rtfd/lint-core
Finish core app linting
2 parents 47b62b2 + f168e33 commit 6c7ee46

37 files changed

+168
-99
lines changed

prospector-more.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ inherits: prospector
33
strictness: medium
44

55
ignore-paths:
6-
- core/
76
- donate/
87
- restapi/
98

readthedocs/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""App initialization."""
2+
13
default_app_config = 'readthedocs.core.apps.CoreAppConfig'

readthedocs/core/adapters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def send_mail(self, template_prefix, email, context):
3535
removed_keys = []
3636
for key in context.keys():
3737
try:
38-
_ = pickle.dumps(context[key])
38+
_ = pickle.dumps(context[key]) # noqa for F841
3939
except (pickle.PickleError, TypeError):
4040
removed_keys.append(key)
4141
del context[key]

readthedocs/core/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def queryset(self, request, queryset):
5353

5454

5555
class UserAdminExtra(UserAdmin):
56+
57+
"""Admin configuration for User."""
58+
5659
list_display = ('username', 'email', 'first_name',
5760
'last_name', 'is_staff', 'is_banned')
5861
list_filter = (UserProjectFilter,) + UserAdmin.list_filter

readthedocs/core/apps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""App configurations for core app."""
2+
13
from django.apps import AppConfig
24

35

readthedocs/core/backends.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Email backends for core app."""
2+
13
import smtplib
24

35
from django.core.mail.utils import DNS_NAME
@@ -15,6 +17,6 @@ def open(self):
1517
if self.username and self.password:
1618
self.connection.login(self.username, self.password)
1719
return True
18-
except:
20+
except Exception:
1921
if not self.fail_silently:
2022
raise

readthedocs/core/context_processors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
"""Template context processors for core app."""
2+
13
from django.conf import settings
24

35

46
def readthedocs_processor(request):
5-
7+
# pylint: disable=unused-argument
68
exports = {
79
'PUBLIC_DOMAIN': getattr(settings, 'PUBLIC_DOMAIN', None),
810
'PRODUCTION_DOMAIN': getattr(settings, 'PRODUCTION_DOMAIN', None),

readthedocs/core/forms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Forms for core app."""
2+
13
import logging
24

35
from haystack.forms import SearchForm
@@ -25,7 +27,7 @@ def __init__(self, *args, **kwargs):
2527
try:
2628
self.fields['first_name'].initial = self.instance.user.first_name
2729
self.fields['last_name'].initial = self.instance.user.last_name
28-
except:
30+
except AttributeError:
2931
pass
3032

3133
def save(self, *args, **kwargs):

readthedocs/core/management/commands/archive.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Rebuild documentation for all projects"""
2+
13
from glob import glob
24
import os
35
import logging
@@ -11,11 +13,7 @@
1113

1214
class Command(BaseCommand):
1315

14-
"""
15-
Custom management command to rebuild documentation for all projects.
16-
17-
Invoked via ``./manage.py update_repos``.
18-
"""
16+
help = __doc__
1917

2018
def handle(self, *args, **options):
2119
doc_index = {}

readthedocs/core/management/commands/clean_builds.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Clean up stable build paths per project version"""
2+
13
from datetime import datetime, timedelta
24
import logging
35
from optparse import make_option
@@ -12,7 +14,7 @@
1214

1315
class Command(BaseCommand):
1416

15-
help = ('Clean up stale build paths per project version')
17+
help = __doc__
1618

1719
option_list = BaseCommand.option_list + (
1820
make_option('--days',

readthedocs/core/management/commands/import_github.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Resync GitHub project for user"""
2+
13
from django.core.management.base import BaseCommand
24
from django.contrib.auth.models import User
35

@@ -6,6 +8,8 @@
68

79
class Command(BaseCommand):
810

11+
help = __doc__
12+
913
def handle(self, *args, **options):
1014
if len(args):
1115
for slug in args:

readthedocs/core/management/commands/import_github_language.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
Import a project's programming language from GitHub
3+
4+
This builds a basic management command that will set
5+
a projects language to the most used one in GitHub.
6+
7+
Requires a ``GITHUB_AUTH_TOKEN`` to be set in the environment,
8+
which should contain a proper GitHub Oauth Token for rate limiting.
9+
"""
10+
111
import os
212
import requests
313

@@ -15,17 +25,10 @@
1525

1626
class Command(BaseCommand):
1727

18-
"""
19-
Import a project's programming language from GitHub.
20-
21-
This builds a basic management command that will set
22-
a projects language to the most used one in GitHub.
23-
24-
Requires a ``GITHUB_AUTH_TOKEN`` to be set in the environment,
25-
which should contain a proper GitHub Oauth Token for rate limiting.
26-
"""
28+
help = __doc__
2729

2830
def handle(self, *args, **options):
31+
# pylint: disable=too-many-locals
2932
token = os.environ.get('GITHUB_AUTH_TOKEN')
3033
if not token:
3134
print 'Invalid GitHub token, exiting'

readthedocs/core/management/commands/pull.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
"""Trigger build for project slug"""
2+
13
import logging
24

35
from django.core.management.base import BaseCommand
4-
from django.conf import settings
56

67
from readthedocs.builds.constants import LATEST
78
from readthedocs.projects import tasks, utils
@@ -11,6 +12,9 @@
1112

1213

1314
class Command(BaseCommand):
15+
16+
help = __doc__
17+
1418
def handle(self, *args, **options):
1519
if len(args):
1620
for slug in args:

readthedocs/core/management/commands/reindex_elasticsearch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Reindex Elastic Search indexes"""
2+
13
import logging
24
from optparse import make_option
35

@@ -14,6 +16,7 @@
1416

1517
class Command(BaseCommand):
1618

19+
help = __doc__
1720
option_list = BaseCommand.option_list + (
1821
make_option('-p',
1922
dest='project',
@@ -32,20 +35,21 @@ def handle(self, *args, **options):
3235
if not queryset.exists():
3336
raise CommandError(
3437
'No project with slug: {slug}'.format(slug=project))
35-
log.info("Building all versions for %s" % project)
38+
log.info("Building all versions for %s", project)
3639
elif getattr(settings, 'INDEX_ONLY_LATEST', True):
3740
queryset = queryset.filter(slug=LATEST)
3841

3942
for version in queryset:
40-
log.info("Reindexing %s" % version)
43+
log.info("Reindexing %s", version)
4144
try:
4245
commit = version.project.vcs_repo(version.slug).commit
43-
except:
44-
# This will happen on prod
46+
except: # pylint: disable=bare-except
47+
# An exception can be thrown here in production, but it's not
48+
# documented what the exception here is
4549
commit = None
4650

4751
try:
4852
update_search(version.pk, commit,
4953
delete_non_commit_files=False)
5054
except Exception:
51-
log.error('Reindex failed for %s' % version, exc_info=True)
55+
log.error('Reindex failed for %s', version, exc_info=True)
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
"""Generate metadata for all projects"""
2+
13
import logging
2-
from optparse import make_option
34

45
from django.core.management.base import BaseCommand
5-
from django.conf import settings
66

77
from readthedocs.projects import tasks
88
from readthedocs.projects.models import Project
@@ -11,11 +11,14 @@
1111

1212

1313
class Command(BaseCommand):
14+
15+
help = __doc__
16+
1417
def handle(self, *args, **options):
1518
queryset = Project.objects.all()
1619
for p in queryset:
17-
log.info("Generating metadata for %s" % p)
20+
log.info("Generating metadata for %s", p)
1821
try:
1922
tasks.update_static_metadata(p.pk)
2023
except Exception:
21-
log.error('Build failed for %s' % p, exc_info=True)
24+
log.error('Build failed for %s', p, exc_info=True)

readthedocs/core/management/commands/symlink.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Update symlinks for projects"""
2+
13
import logging
24

35
from django.core.management.base import BaseCommand
@@ -11,6 +13,8 @@
1113

1214
class Command(BaseCommand):
1315

16+
help = __doc__
17+
1418
def add_arguments(self, parser):
1519
parser.add_argument('projects', nargs='+', type=str)
1620

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
Build documentation using the API and not hitting a database.
3+
4+
Usage::
5+
6+
./manage.py update_api <slug>
7+
"""
8+
19
import logging
210

311
from django.core.management.base import BaseCommand
@@ -10,13 +18,7 @@
1018

1119
class Command(BaseCommand):
1220

13-
"""
14-
Build documentation using the API and not hitting a database.
15-
16-
Usage::
17-
18-
./manage.py update_api <slug>
19-
"""
21+
help = __doc__
2022

2123
def add_arguments(self, parser):
2224
parser.add_argument('--docker', action='store_true', default=False)
@@ -27,5 +29,5 @@ def handle(self, *args, **options):
2729
for slug in options['projects']:
2830
project_data = api.project(slug).get()
2931
p = tasks.make_api_project(project_data)
30-
log.info("Building %s" % p)
32+
log.info("Building %s", p)
3133
tasks.update_docs.run(pk=p.pk, docker=docker)

readthedocs/core/management/commands/update_repos.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
Custom management command to rebuild documentation for all projects.
3+
4+
Invoked via ``./manage.py update_repos``.
5+
"""
6+
17
import logging
28
from optparse import make_option
39

@@ -12,12 +18,9 @@
1218

1319
class Command(BaseCommand):
1420

15-
"""
16-
Custom management command to rebuild documentation for all projects.
17-
18-
Invoked via ``./manage.py update_repos``.
19-
"""
21+
"""Management command for rebuilding documentation on projects"""
2022

23+
help = __doc__
2124
option_list = BaseCommand.option_list + (
2225
make_option('-r',
2326
action='store_true',
@@ -42,11 +45,11 @@ def handle(self, *args, **options):
4245
if len(args):
4346
for slug in args:
4447
if version and version != "all":
45-
log.info("Updating version %s for %s" % (version, slug))
48+
log.info("Updating version %s for %s", version, slug)
4649
for version in Version.objects.filter(project__slug=slug, slug=version):
4750
trigger_build(project=version.project, version=version)
4851
elif version == "all":
49-
log.info("Updating all versions for %s" % slug)
52+
log.info("Updating all versions for %s", slug)
5053
for version in Version.objects.filter(project__slug=slug,
5154
active=True,
5255
uploaded=False):
@@ -55,7 +58,7 @@ def handle(self, *args, **options):
5558
version_pk=version.pk)
5659
else:
5760
p = Project.all_objects.get(slug=slug)
58-
log.info("Building %s" % p)
61+
log.info("Building %s", p)
5962
trigger_build(project=p, force=force, record=record)
6063
else:
6164
if version == "all":
@@ -71,7 +74,3 @@ def handle(self, *args, **options):
7174
for project in Project.objects.all():
7275
tasks.update_docs.run(pk=project.pk, record=record,
7376
force=force)
74-
75-
@property
76-
def help(self):
77-
return Command.__doc__

readthedocs/core/management/commands/update_versions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Rebuild documentation for all projects"""
2+
13
from django.core.management.base import BaseCommand
24

35
from readthedocs.builds.models import Version
@@ -6,11 +8,7 @@
68

79
class Command(BaseCommand):
810

9-
"""
10-
Custom management command to rebuild documentation for all projects.
11-
12-
Invoked via ``./manage.py update_repos``.
13-
"""
11+
help = __doc__
1412

1513
def handle(self, *args, **options):
1614
for version in Version.objects.filter(active=True, built=False):

readthedocs/core/middleware.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Middleware for core app."""
2+
13
import logging
24

35
from django.utils.translation import ugettext_lazy as _
@@ -27,7 +29,15 @@
2729

2830
class SubdomainMiddleware(object):
2931

32+
"""Middleware to display docs for non-dashboard domains"""
33+
3034
def process_request(self, request):
35+
"""Process requests for unhandled domains
36+
37+
If the request is not for our ``PUBLIC_DOMAIN``, or if ``PUBLIC_DOMAIN``
38+
is not set and the request is for a subdomain on ``PRODUCTION_DOMAIN``,
39+
process the request as a request a documentation project.
40+
"""
3141
if not getattr(settings, 'USE_SUBDOMAIN', False):
3242
return None
3343

0 commit comments

Comments
 (0)