Skip to content

linting core app #2887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion prospector-more.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ignore-paths:
- api/
- cdn/
- comments/
- core/
- doc_builder/
- donate/
- notifications/
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""App initialization."""

default_app_config = 'readthedocs.core.apps.CoreAppConfig'
2 changes: 1 addition & 1 deletion readthedocs/core/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""App configurations for core app."""

from django.apps import AppConfig


Expand Down
6 changes: 4 additions & 2 deletions readthedocs/core/backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Email backends for core app."""

import smtplib

from django.core.mail.utils import DNS_NAME
Expand All @@ -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 as e:
if not self.fail_silently:
raise
raise e
2 changes: 2 additions & 0 deletions readthedocs/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Template context processors for core app."""

from django.conf import settings


Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Forms for core app."""

import logging

from haystack.forms import SearchForm
Expand Down
1 change: 1 addition & 0 deletions readthedocs/core/management/commands/clean_builds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from datetime import datetime, timedelta
import logging
from optparse import make_option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Command(BaseCommand):
"""

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'
Expand Down
1 change: 0 additions & 1 deletion readthedocs/core/management/commands/pull.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/core/management/commands/reindex_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ 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:
Expand All @@ -48,4 +48,4 @@ def handle(self, *args, **options):
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)
6 changes: 2 additions & 4 deletions readthedocs/core/management/commands/set_metadata.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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
Expand All @@ -14,8 +12,8 @@ class Command(BaseCommand):
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)
2 changes: 1 addition & 1 deletion readthedocs/core/management/commands/update_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,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)
6 changes: 3 additions & 3 deletions readthedocs/core/management/commands/update_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,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):
Expand All @@ -55,7 +55,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":
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Middleware for core app."""

import logging

from django.utils.translation import ugettext_lazy as _
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Models for the core app."""

import logging

from django.db import models
Expand Down
4 changes: 3 additions & 1 deletion readthedocs/core/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Signal handling for core app."""

import logging
from urlparse import urlparse

Expand All @@ -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.

Expand Down
6 changes: 4 additions & 2 deletions readthedocs/core/templatetags/core_tags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Template tags for core app."""

import urllib
import hashlib

Expand Down Expand Up @@ -68,15 +70,15 @@ def restructuredtext(value, short=False):
def get_project(slug):
try:
return Project.objects.get(slug=slug)
except:
except Project.DoesNotExist:
return None


@register.filter
def get_version(slug):
try:
return Project.objects.get(slug=slug)
except:
except Project.DoesNotExist:
return None


Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/urls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""URL configuration for core app."""

from django.conf.urls import url

from django_filters import views as django_filters_views
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/urls/single_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""URL configuration for a single version."""

from operator import add

from django.conf.urls import url
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/urls/subdomain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""URL configurations for subdomains."""

from operator import add

from django.conf.urls import url, patterns
Expand Down
12 changes: 6 additions & 6 deletions readthedocs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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:
Expand All @@ -36,7 +36,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']:
Expand All @@ -53,11 +53,11 @@ def broadcast(type, task, args):
def clean_url(url):
parsed = urlparse(url)
if parsed.scheme:
scheme, netloc = parsed.scheme, parsed.netloc
_, netloc = parsed.scheme, parsed.netloc # noqa for F841
elif parsed.netloc:
scheme, netloc = "http", parsed.netloc
_, netloc = "http", parsed.netloc # noqa for F841
else:
scheme, netloc = "http", parsed.path
_, netloc = "http", parsed.path # noqa for F841
return netloc


Expand Down Expand Up @@ -126,7 +126,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::
Expand Down
1 change: 1 addition & 0 deletions readthedocs/core/utils/extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions readthedocs/core/utils/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
from .permission_checks import user_id_matches # noqa
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
2 changes: 1 addition & 1 deletion readthedocs/core/utils/tasks/permission_checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__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:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/utils/tasks/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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):
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/utils/tasks/retrieve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Utilities for retrieving task data."""

from djcelery import celery as celery_app
from celery.result import AsyncResult

Expand Down
2 changes: 2 additions & 0 deletions readthedocs/core/validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Validators for core app."""

# From https://github.com/django/django/pull/3477/files
import re

Expand Down
8 changes: 4 additions & 4 deletions readthedocs/core/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -100,19 +100,19 @@ 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))
r.status_code = 500
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:
Expand Down
Loading