diff --git a/prospector-more.yml b/prospector-more.yml index de7af7b5c5c..e4a0898ea6a 100644 --- a/prospector-more.yml +++ b/prospector-more.yml @@ -3,7 +3,6 @@ inherits: prospector strictness: medium ignore-paths: - - core/ - donate/ - restapi/ - search/ diff --git a/readthedocs/core/__init__.py b/readthedocs/core/__init__.py index 081e5c19f4d..ed1c53debf0 100644 --- a/readthedocs/core/__init__.py +++ b/readthedocs/core/__init__.py @@ -1 +1,3 @@ +"""App initialization.""" + default_app_config = 'readthedocs.core.apps.CoreAppConfig' diff --git a/readthedocs/core/adapters.py b/readthedocs/core/adapters.py index c54990ad2e8..76f00a9fea7 100644 --- a/readthedocs/core/adapters.py +++ b/readthedocs/core/adapters.py @@ -35,7 +35,7 @@ def send_mail(self, template_prefix, email, context): removed_keys = [] for key in context.keys(): try: - _ = pickle.dumps(context[key]) + _ = pickle.dumps(context[key]) # noqa for F841 except (pickle.PickleError, TypeError): removed_keys.append(key) del context[key] diff --git a/readthedocs/core/admin.py b/readthedocs/core/admin.py index 29feb2dd661..9ec5edcd36f 100644 --- a/readthedocs/core/admin.py +++ b/readthedocs/core/admin.py @@ -53,6 +53,9 @@ def queryset(self, request, queryset): class UserAdminExtra(UserAdmin): + + """Admin configuration for User.""" + list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff', 'is_banned') list_filter = (UserProjectFilter,) + UserAdmin.list_filter diff --git a/readthedocs/core/apps.py b/readthedocs/core/apps.py index d5c7c6b0e5b..d422684ba03 100644 --- a/readthedocs/core/apps.py +++ b/readthedocs/core/apps.py @@ -1,3 +1,5 @@ +"""App configurations for core app.""" + from django.apps import AppConfig diff --git a/readthedocs/core/backends.py b/readthedocs/core/backends.py index f896fb8281f..a9428d66fa7 100644 --- a/readthedocs/core/backends.py +++ b/readthedocs/core/backends.py @@ -1,3 +1,5 @@ +"""Email backends for core app.""" + import smtplib from django.core.mail.utils import DNS_NAME @@ -15,6 +17,6 @@ def open(self): if self.username and self.password: self.connection.login(self.username, self.password) return True - except: + except Exception: if not self.fail_silently: raise diff --git a/readthedocs/core/context_processors.py b/readthedocs/core/context_processors.py index 2494edb784c..0ff6d8faa81 100644 --- a/readthedocs/core/context_processors.py +++ b/readthedocs/core/context_processors.py @@ -1,8 +1,10 @@ +"""Template context processors for core app.""" + from django.conf import settings def readthedocs_processor(request): - + # pylint: disable=unused-argument exports = { 'PUBLIC_DOMAIN': getattr(settings, 'PUBLIC_DOMAIN', None), 'PRODUCTION_DOMAIN': getattr(settings, 'PRODUCTION_DOMAIN', None), diff --git a/readthedocs/core/forms.py b/readthedocs/core/forms.py index 70acdcfc086..2d96a09788a 100644 --- a/readthedocs/core/forms.py +++ b/readthedocs/core/forms.py @@ -1,3 +1,5 @@ +"""Forms for core app.""" + import logging from haystack.forms import SearchForm @@ -25,7 +27,7 @@ def __init__(self, *args, **kwargs): try: self.fields['first_name'].initial = self.instance.user.first_name self.fields['last_name'].initial = self.instance.user.last_name - except: + except AttributeError: pass def save(self, *args, **kwargs): diff --git a/readthedocs/core/management/commands/archive.py b/readthedocs/core/management/commands/archive.py index 855044b4727..3a4c8ff1686 100644 --- a/readthedocs/core/management/commands/archive.py +++ b/readthedocs/core/management/commands/archive.py @@ -1,3 +1,5 @@ +"""Rebuild documentation for all projects""" + from glob import glob import os import logging @@ -11,11 +13,7 @@ class Command(BaseCommand): - """ - Custom management command to rebuild documentation for all projects. - - Invoked via ``./manage.py update_repos``. - """ + help = __doc__ def handle(self, *args, **options): doc_index = {} diff --git a/readthedocs/core/management/commands/clean_builds.py b/readthedocs/core/management/commands/clean_builds.py index 89164c2a225..a4bb8f0d512 100644 --- a/readthedocs/core/management/commands/clean_builds.py +++ b/readthedocs/core/management/commands/clean_builds.py @@ -1,3 +1,5 @@ +"""Clean up stable build paths per project version""" + from datetime import datetime, timedelta import logging from optparse import make_option @@ -12,7 +14,7 @@ class Command(BaseCommand): - help = ('Clean up stale build paths per project version') + help = __doc__ option_list = BaseCommand.option_list + ( make_option('--days', diff --git a/readthedocs/core/management/commands/import_github.py b/readthedocs/core/management/commands/import_github.py index 214ef03067d..45bb028e968 100644 --- a/readthedocs/core/management/commands/import_github.py +++ b/readthedocs/core/management/commands/import_github.py @@ -1,3 +1,5 @@ +"""Resync GitHub project for user""" + from django.core.management.base import BaseCommand from django.contrib.auth.models import User @@ -6,6 +8,8 @@ class Command(BaseCommand): + help = __doc__ + def handle(self, *args, **options): if len(args): for slug in args: diff --git a/readthedocs/core/management/commands/import_github_language.py b/readthedocs/core/management/commands/import_github_language.py index d1540f008db..aa6e33ced8a 100644 --- a/readthedocs/core/management/commands/import_github_language.py +++ b/readthedocs/core/management/commands/import_github_language.py @@ -1,3 +1,13 @@ +""" +Import a project's programming language from GitHub + +This builds a basic management command that will set +a projects language to the most used one in GitHub. + +Requires a ``GITHUB_AUTH_TOKEN`` to be set in the environment, +which should contain a proper GitHub Oauth Token for rate limiting. +""" + import os import requests @@ -15,17 +25,10 @@ class Command(BaseCommand): - """ - Import a project's programming language from GitHub. - - This builds a basic management command that will set - a projects language to the most used one in GitHub. - - Requires a ``GITHUB_AUTH_TOKEN`` to be set in the environment, - which should contain a proper GitHub Oauth Token for rate limiting. - """ + help = __doc__ def handle(self, *args, **options): + # pylint: disable=too-many-locals token = os.environ.get('GITHUB_AUTH_TOKEN') if not token: print 'Invalid GitHub token, exiting' diff --git a/readthedocs/core/management/commands/pull.py b/readthedocs/core/management/commands/pull.py index cc563e406e1..391ddb8a2d6 100644 --- a/readthedocs/core/management/commands/pull.py +++ b/readthedocs/core/management/commands/pull.py @@ -1,7 +1,8 @@ +"""Trigger build for project slug""" + import logging from django.core.management.base import BaseCommand -from django.conf import settings from readthedocs.builds.constants import LATEST from readthedocs.projects import tasks, utils @@ -11,6 +12,9 @@ class Command(BaseCommand): + + help = __doc__ + def handle(self, *args, **options): if len(args): for slug in args: diff --git a/readthedocs/core/management/commands/reindex_elasticsearch.py b/readthedocs/core/management/commands/reindex_elasticsearch.py index d7b8176e376..839ac4854d6 100644 --- a/readthedocs/core/management/commands/reindex_elasticsearch.py +++ b/readthedocs/core/management/commands/reindex_elasticsearch.py @@ -1,3 +1,5 @@ +"""Reindex Elastic Search indexes""" + import logging from optparse import make_option @@ -14,6 +16,7 @@ class Command(BaseCommand): + help = __doc__ option_list = BaseCommand.option_list + ( make_option('-p', dest='project', @@ -32,20 +35,21 @@ def handle(self, *args, **options): if not queryset.exists(): raise CommandError( 'No project with slug: {slug}'.format(slug=project)) - log.info("Building all versions for %s" % project) + log.info("Building all versions for %s", project) elif getattr(settings, 'INDEX_ONLY_LATEST', True): queryset = queryset.filter(slug=LATEST) for version in queryset: - log.info("Reindexing %s" % version) + log.info("Reindexing %s", version) try: commit = version.project.vcs_repo(version.slug).commit - except: - # This will happen on prod + except: # pylint: disable=bare-except + # An exception can be thrown here in production, but it's not + # documented what the exception here is commit = None try: update_search(version.pk, commit, delete_non_commit_files=False) except Exception: - log.error('Reindex failed for %s' % version, exc_info=True) + log.error('Reindex failed for %s', version, exc_info=True) diff --git a/readthedocs/core/management/commands/set_metadata.py b/readthedocs/core/management/commands/set_metadata.py index 3bd6f0e9033..5ef8e6f07fb 100644 --- a/readthedocs/core/management/commands/set_metadata.py +++ b/readthedocs/core/management/commands/set_metadata.py @@ -1,8 +1,8 @@ +"""Generate metadata for all projects""" + import logging -from optparse import make_option from django.core.management.base import BaseCommand -from django.conf import settings from readthedocs.projects import tasks from readthedocs.projects.models import Project @@ -11,11 +11,14 @@ class Command(BaseCommand): + + help = __doc__ + def handle(self, *args, **options): queryset = Project.objects.all() for p in queryset: - log.info("Generating metadata for %s" % p) + log.info("Generating metadata for %s", p) try: tasks.update_static_metadata(p.pk) except Exception: - log.error('Build failed for %s' % p, exc_info=True) + log.error('Build failed for %s', p, exc_info=True) diff --git a/readthedocs/core/management/commands/symlink.py b/readthedocs/core/management/commands/symlink.py index 8dd96099081..4c2f92cbf96 100644 --- a/readthedocs/core/management/commands/symlink.py +++ b/readthedocs/core/management/commands/symlink.py @@ -1,3 +1,5 @@ +"""Update symlinks for projects""" + import logging from django.core.management.base import BaseCommand @@ -11,6 +13,8 @@ class Command(BaseCommand): + help = __doc__ + def add_arguments(self, parser): parser.add_argument('projects', nargs='+', type=str) diff --git a/readthedocs/core/management/commands/update_api.py b/readthedocs/core/management/commands/update_api.py index 8a3100b2389..195615b5deb 100644 --- a/readthedocs/core/management/commands/update_api.py +++ b/readthedocs/core/management/commands/update_api.py @@ -1,3 +1,11 @@ +""" +Build documentation using the API and not hitting a database. + +Usage:: + + ./manage.py update_api +""" + import logging from django.core.management.base import BaseCommand @@ -10,13 +18,7 @@ class Command(BaseCommand): - """ - Build documentation using the API and not hitting a database. - - Usage:: - - ./manage.py update_api - """ + help = __doc__ def add_arguments(self, parser): parser.add_argument('--docker', action='store_true', default=False) @@ -27,5 +29,5 @@ def handle(self, *args, **options): for slug in options['projects']: project_data = api.project(slug).get() p = tasks.make_api_project(project_data) - log.info("Building %s" % p) + log.info("Building %s", p) tasks.update_docs.run(pk=p.pk, docker=docker) diff --git a/readthedocs/core/management/commands/update_repos.py b/readthedocs/core/management/commands/update_repos.py index 394958a59af..5492f70c04b 100644 --- a/readthedocs/core/management/commands/update_repos.py +++ b/readthedocs/core/management/commands/update_repos.py @@ -1,3 +1,9 @@ +""" +Custom management command to rebuild documentation for all projects. + +Invoked via ``./manage.py update_repos``. +""" + import logging from optparse import make_option @@ -12,12 +18,9 @@ class Command(BaseCommand): - """ - Custom management command to rebuild documentation for all projects. - - Invoked via ``./manage.py update_repos``. - """ + """Management command for rebuilding documentation on projects""" + help = __doc__ option_list = BaseCommand.option_list + ( make_option('-r', action='store_true', @@ -42,11 +45,11 @@ def handle(self, *args, **options): if len(args): for slug in args: if version and version != "all": - log.info("Updating version %s for %s" % (version, slug)) + log.info("Updating version %s for %s", version, slug) for version in Version.objects.filter(project__slug=slug, slug=version): trigger_build(project=version.project, version=version) elif version == "all": - log.info("Updating all versions for %s" % slug) + log.info("Updating all versions for %s", slug) for version in Version.objects.filter(project__slug=slug, active=True, uploaded=False): @@ -55,7 +58,7 @@ def handle(self, *args, **options): version_pk=version.pk) else: p = Project.all_objects.get(slug=slug) - log.info("Building %s" % p) + log.info("Building %s", p) trigger_build(project=p, force=force, record=record) else: if version == "all": @@ -71,7 +74,3 @@ def handle(self, *args, **options): for project in Project.objects.all(): tasks.update_docs.run(pk=project.pk, record=record, force=force) - - @property - def help(self): - return Command.__doc__ diff --git a/readthedocs/core/management/commands/update_versions.py b/readthedocs/core/management/commands/update_versions.py index 0ae1a6f0424..f04be5db218 100644 --- a/readthedocs/core/management/commands/update_versions.py +++ b/readthedocs/core/management/commands/update_versions.py @@ -1,3 +1,5 @@ +"""Rebuild documentation for all projects""" + from django.core.management.base import BaseCommand from readthedocs.builds.models import Version @@ -6,11 +8,7 @@ class Command(BaseCommand): - """ - Custom management command to rebuild documentation for all projects. - - Invoked via ``./manage.py update_repos``. - """ + help = __doc__ def handle(self, *args, **options): for version in Version.objects.filter(active=True, built=False): diff --git a/readthedocs/core/middleware.py b/readthedocs/core/middleware.py index 7cf32bfdaf4..ff8a67d8b7d 100644 --- a/readthedocs/core/middleware.py +++ b/readthedocs/core/middleware.py @@ -1,3 +1,5 @@ +"""Middleware for core app.""" + import logging from django.utils.translation import ugettext_lazy as _ @@ -27,7 +29,15 @@ class SubdomainMiddleware(object): + """Middleware to display docs for non-dashboard domains""" + def process_request(self, request): + """Process requests for unhandled domains + + If the request is not for our ``PUBLIC_DOMAIN``, or if ``PUBLIC_DOMAIN`` + is not set and the request is for a subdomain on ``PRODUCTION_DOMAIN``, + process the request as a request a documentation project. + """ if not getattr(settings, 'USE_SUBDOMAIN', False): return None diff --git a/readthedocs/core/models.py b/readthedocs/core/models.py index 5ef8aefb8b6..d633823a89e 100644 --- a/readthedocs/core/models.py +++ b/readthedocs/core/models.py @@ -1,3 +1,5 @@ +"""Models for the core app.""" + import logging from django.db import models diff --git a/readthedocs/core/resolver.py b/readthedocs/core/resolver.py index 99ee6092c24..66cbb85e4be 100644 --- a/readthedocs/core/resolver.py +++ b/readthedocs/core/resolver.py @@ -55,6 +55,7 @@ def base_resolve_path(self, project_slug, filename, version_slug=None, """Resolve a with nothing smart, just filling in the blanks""" # Only support `/docs/project' URLs outside our normal environment. Normally # the path should always have a subdomain or CNAME domain + # pylint: disable=unused-argument if subdomain or cname or (self._use_subdomain()): url = u'/' else: @@ -120,6 +121,7 @@ def resolve_path(self, project, filename='', version_slug=None, ) def resolve_domain(self, project, private=None): + # pylint: disable=unused-argument canonical_project = self._get_canonical_project(project) domain = canonical_project.domains.filter(canonical=True).first() if domain: diff --git a/readthedocs/core/signals.py b/readthedocs/core/signals.py index 5ff5a472deb..aab87d50dba 100644 --- a/readthedocs/core/signals.py +++ b/readthedocs/core/signals.py @@ -1,3 +1,5 @@ +"""Signal handling for core app.""" + import logging from urlparse import urlparse @@ -16,7 +18,7 @@ webhook_bitbucket = Signal(providing_args=['project', 'data', 'event']) -def decide_if_cors(sender, request, **kwargs): +def decide_if_cors(sender, request, **kwargs): # pylint: disable=unused-argument """ Decide whether a request should be given CORS access. diff --git a/readthedocs/core/templatetags/core_tags.py b/readthedocs/core/templatetags/core_tags.py index 57de3d3d4fa..51261504a48 100644 --- a/readthedocs/core/templatetags/core_tags.py +++ b/readthedocs/core/templatetags/core_tags.py @@ -1,3 +1,5 @@ +"""Template tags for core app.""" + import urllib import hashlib @@ -60,15 +62,14 @@ def restructuredtext(value, short=False): out = out.split("\n")[0] except IndexError: pass - finally: - return mark_safe(out) + return mark_safe(out) @register.filter def get_project(slug): try: return Project.objects.get(slug=slug) - except: + except Project.DoesNotExist: return None @@ -76,7 +77,7 @@ def get_project(slug): def get_version(slug): try: return Project.objects.get(slug=slug) - except: + except Project.DoesNotExist: return None diff --git a/readthedocs/core/urls/__init__.py b/readthedocs/core/urls/__init__.py index d4876159924..d4024e96f00 100644 --- a/readthedocs/core/urls/__init__.py +++ b/readthedocs/core/urls/__init__.py @@ -1,3 +1,5 @@ +"""URL configuration for core app.""" + from django.conf.urls import url from readthedocs.constants import pattern_opts diff --git a/readthedocs/core/urls/single_version.py b/readthedocs/core/urls/single_version.py index d904db91de5..136a3461bd4 100644 --- a/readthedocs/core/urls/single_version.py +++ b/readthedocs/core/urls/single_version.py @@ -1,3 +1,5 @@ +"""URL configuration for a single version.""" + from operator import add from django.conf.urls import url diff --git a/readthedocs/core/urls/subdomain.py b/readthedocs/core/urls/subdomain.py index f3532c6d01a..eb27a471042 100644 --- a/readthedocs/core/urls/subdomain.py +++ b/readthedocs/core/urls/subdomain.py @@ -1,3 +1,5 @@ +"""URL configurations for subdomains.""" + from operator import add from django.conf.urls import url, patterns diff --git a/readthedocs/core/utils/__init__.py b/readthedocs/core/utils/__init__.py index 3f4a3d17ce1..ae34fd032e3 100644 --- a/readthedocs/core/utils/__init__.py +++ b/readthedocs/core/utils/__init__.py @@ -1,3 +1,5 @@ +"""Common utilty functions""" + import errno import getpass import logging @@ -23,7 +25,7 @@ def run_on_app_servers(command): """A helper to copy a single file across app servers""" - log.info("Running %s on app servers" % command) + log.info("Running %s on app servers", command) ret_val = 0 if getattr(settings, "MULTIPLE_APP_SERVERS", None): for server in settings.MULTIPLE_APP_SERVERS: @@ -36,7 +38,7 @@ def run_on_app_servers(command): return ret -def broadcast(type, task, args): +def broadcast(type, task, args): # pylint: disable=redefined-builtin assert type in ['web', 'app', 'build'] default_queue = getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery') if type in ['web', 'app']: @@ -52,13 +54,10 @@ def broadcast(type, task, args): def clean_url(url): parsed = urlparse(url) - if parsed.scheme: - scheme, netloc = parsed.scheme, parsed.netloc - elif parsed.netloc: - scheme, netloc = "http", parsed.netloc + if parsed.scheme or parsed.netloc: + return parsed.netloc else: - scheme, netloc = "http", parsed.path - return netloc + return parsed.path def cname_to_slug(host): @@ -126,7 +125,7 @@ def trigger_build(project, version=None, record=True, force=False, basic=False): def send_email(recipient, subject, template, template_html, context=None, - request=None): + request=None): # pylint: disable=unused-argument """Alter context passed in and call email send task .. seealso:: diff --git a/readthedocs/core/utils/extend.py b/readthedocs/core/utils/extend.py index 9e25d0ce180..5707f5aed5b 100644 --- a/readthedocs/core/utils/extend.py +++ b/readthedocs/core/utils/extend.py @@ -21,6 +21,7 @@ def get_override_class(proxy_class, default_class=None): proxy_class.__name__ ]) class_path = getattr(settings, 'CLASS_OVERRIDES', {}).get(class_id) + # pylint: disable=protected-access if class_path is None and proxy_class._override_setting is not None: class_path = getattr(settings, proxy_class._override_setting, None) if class_path is not None: diff --git a/readthedocs/core/utils/tasks/__init__.py b/readthedocs/core/utils/tasks/__init__.py index 766f899f1cc..3b6b13331b7 100644 --- a/readthedocs/core/utils/tasks/__init__.py +++ b/readthedocs/core/utils/tasks/__init__.py @@ -1,7 +1,9 @@ -from .permission_checks import user_id_matches -from .public import PublicTask -from .public import TaskNoPermission -from .public import permission_check -from .public import get_public_task_data -from .retrieve import TaskNotFound -from .retrieve import get_task_data +"""Common task exports""" + +from .permission_checks import user_id_matches # noqa for unused import +from .public import PublicTask # noqa +from .public import TaskNoPermission # noqa +from .public import permission_check # noqa +from .public import get_public_task_data # noqa +from .retrieve import TaskNotFound # noqa +from .retrieve import get_task_data # noqa diff --git a/readthedocs/core/utils/tasks/permission_checks.py b/readthedocs/core/utils/tasks/permission_checks.py index 91ac5d1372c..ce2a2dffd2d 100644 --- a/readthedocs/core/utils/tasks/permission_checks.py +++ b/readthedocs/core/utils/tasks/permission_checks.py @@ -1,7 +1,9 @@ +"""Permission checks for tasks""" + __all__ = ('user_id_matches',) -def user_id_matches(request, state, context): +def user_id_matches(request, state, context): # pylint: disable=unused-argument user_id = context.get('user_id', None) if user_id is not None and request.user.is_authenticated(): if request.user.id == user_id: diff --git a/readthedocs/core/utils/tasks/public.py b/readthedocs/core/utils/tasks/public.py index f9fcd0e5e21..91fba3fbab2 100644 --- a/readthedocs/core/utils/tasks/public.py +++ b/readthedocs/core/utils/tasks/public.py @@ -1,3 +1,5 @@ +"""Celery tasks with publicly viewable status""" + from celery import Task, states from django.conf import settings @@ -26,6 +28,7 @@ class PublicTask(Task): @classmethod def check_permission(cls, request, state, context): """Override this method to define who can monitor this task.""" + # pylint: disable=unused-argument return False def get_task_data(self): @@ -67,7 +70,7 @@ def run(self, *args, **kwargs): result = self.run_public(*args, **kwargs) if result is not None: self.set_public_data(result) - state, info = self.get_task_data() + _, info = self.get_task_data() return info def after_return(self, status, retval, task_id, args, kwargs, einfo): diff --git a/readthedocs/core/utils/tasks/retrieve.py b/readthedocs/core/utils/tasks/retrieve.py index ee1fb362abc..9fdb33efdfc 100644 --- a/readthedocs/core/utils/tasks/retrieve.py +++ b/readthedocs/core/utils/tasks/retrieve.py @@ -1,3 +1,5 @@ +"""Utilities for retrieving task data.""" + from djcelery import celery as celery_app from celery.result import AsyncResult diff --git a/readthedocs/core/validators.py b/readthedocs/core/validators.py index 70d5c84b001..7b4c904f39c 100644 --- a/readthedocs/core/validators.py +++ b/readthedocs/core/validators.py @@ -1,3 +1,5 @@ +"""Validators for core app.""" + # From https://github.com/django/django/pull/3477/files import re diff --git a/readthedocs/core/views/__init__.py b/readthedocs/core/views/__init__.py index 60664549d7c..8cf4ea3d7ff 100644 --- a/readthedocs/core/views/__init__.py +++ b/readthedocs/core/views/__init__.py @@ -68,7 +68,7 @@ def get_context_data(self, **kwargs): return context -def random_page(request, project_slug=None): +def random_page(request, project_slug=None): # pylint: disable=unused-argument imported_file = ImportedFile.objects.order_by('?') if project_slug: imported_file = imported_file.filter(project__slug=project_slug) @@ -100,11 +100,11 @@ def wipe_version(request, project_slug, version_slug): context_instance=RequestContext(request)) -def divide_by_zero(request): +def divide_by_zero(request): # pylint: disable=unused-argument return 1 / 0 -def server_error_500(request, exception, template_name='500.html'): +def server_error_500(request, exception, template_name='500.html'): # pylint: disable=unused-argument # noqa """A simple 500 handler so we get media""" r = render_to_response(template_name, context_instance=RequestContext(request)) @@ -112,7 +112,7 @@ def server_error_500(request, exception, template_name='500.html'): return r -def server_error_404(request, exception, template_name='404.html'): +def server_error_404(request, exception, template_name='404.html'): # pylint: disable=unused-argument # noqa """A simple 404 handler so we get media""" response = get_redirect_response(request, path=request.get_full_path()) if response: diff --git a/readthedocs/core/views/hooks.py b/readthedocs/core/views/hooks.py index 8a2538cad63..4baf9ff2588 100644 --- a/readthedocs/core/views/hooks.py +++ b/readthedocs/core/views/hooks.py @@ -1,3 +1,5 @@ +"""Views pertaining to builds.""" + import json import re @@ -36,26 +38,26 @@ def _build_version(project, slug, already_built=()): # active latest_version = project.versions.get(slug=LATEST) trigger_build(project=project, version=latest_version, force=True) - log.info(("(Version build) Building %s:%s" - % (project.slug, latest_version.slug))) + log.info("(Version build) Building %s:%s", + project.slug, latest_version.slug) if project.versions.exclude(active=False).filter(slug=slug).exists(): # Handle the case where we want to build the custom branch too slug_version = project.versions.get(slug=slug) trigger_build(project=project, version=slug_version, force=True) - log.info(("(Version build) Building %s:%s" - % (project.slug, slug_version.slug))) + log.info("(Version build) Building %s:%s", + project.slug, slug_version.slug) return LATEST elif project.versions.exclude(active=True).filter(slug=slug).exists(): - log.info(("(Version build) Not Building %s" % slug)) + log.info("(Version build) Not Building %s", slug) return None elif slug not in already_built: version = project.versions.get(slug=slug) trigger_build(project=project, version=version, force=True) - log.info(("(Version build) Building %s:%s" - % (project.slug, version.slug))) + log.info("(Version build) Building %s:%s", + project.slug, version.slug) return slug else: - log.info(("(Version build) Not Building %s" % slug)) + log.info("(Version build) Not Building %s", slug) return None @@ -72,8 +74,8 @@ def build_branches(project, branch_list): to_build = set() not_building = set() for version in versions: - log.info(("(Branch Build) Processing %s:%s" - % (project.slug, version.slug))) + log.info("(Branch Build) Processing %s:%s", + project.slug, version.slug) ret = _build_version(project, version.slug, already_built=to_build) if ret: to_build.add(ret) @@ -311,14 +313,14 @@ def generic_build(request, project_id_or_slug=None): project = Project.objects.get(slug=project_id_or_slug) except (Project.DoesNotExist, ValueError): log.error( - "(Incoming Generic Build) Repo not found: %s" % ( - project_id_or_slug)) + "(Incoming Generic Build) Repo not found: %s", + project_id_or_slug) return HttpResponseNotFound( 'Repo not found: %s' % project_id_or_slug) if request.method == 'POST': slug = request.POST.get('version_slug', project.default_version) log.info( - "(Incoming Generic Build) %s [%s]" % (project.slug, slug)) + "(Incoming Generic Build) %s [%s]", project.slug, slug) _build_version(project, slug) else: return HttpResponse("You must POST to this resource.") diff --git a/readthedocs/core/views/serve.py b/readthedocs/core/views/serve.py index 09f663015c7..6f0663c25f8 100644 --- a/readthedocs/core/views/serve.py +++ b/readthedocs/core/views/serve.py @@ -95,14 +95,14 @@ def inner_view(request, project=None, project_slug=None, *args, **kwargs): @map_project_slug @map_subproject_slug -def redirect_project_slug(request, project, subproject): +def redirect_project_slug(request, project, subproject): # pylint: disable=unused-argument """Handle / -> /en/latest/ directs on subdomains""" return HttpResponseRedirect(resolve(subproject or project)) @map_project_slug @map_subproject_slug -def redirect_page_with_filename(request, project, subproject, filename): +def redirect_page_with_filename(request, project, subproject, filename): # pylint: disable=unused-argument # noqa """Redirect /page/file.html to /en/latest/file.html.""" return HttpResponseRedirect(resolve(subproject or project, filename=filename)) @@ -170,7 +170,7 @@ def serve_docs(request, project, subproject, @map_project_slug def _serve_symlink_docs(request, project, privacy_level, filename=''): - + """Serve a file by symlink, or a 404 if not found.""" # Handle indexes if filename == '' or filename[-1] == '/': filename += 'index.html' @@ -179,7 +179,7 @@ def _serve_symlink_docs(request, project, privacy_level, filename=''): if filename[0] == '/': filename = filename[1:] - log.info('Serving %s for %s' % (filename, project)) + log.info('Serving %s for %s', filename, project) files_tried = []