Skip to content

Finish core app linting #2911

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

Merged
merged 5 commits into from
May 26, 2017
Merged
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 @@ -3,7 +3,6 @@ inherits: prospector
strictness: medium

ignore-paths:
- core/
- donate/
- restapi/
- search/
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
4 changes: 3 additions & 1 deletion 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:
if not self.fail_silently:
raise
4 changes: 3 additions & 1 deletion readthedocs/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions readthedocs/core/management/commands/archive.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Rebuild documentation for all projects"""

from glob import glob
import os
import logging
Expand All @@ -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 = {}
Expand Down
4 changes: 3 additions & 1 deletion readthedocs/core/management/commands/clean_builds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Clean up stable build paths per project version"""

from datetime import datetime, timedelta
import logging
from optparse import make_option
Expand All @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/core/management/commands/import_github.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Resync GitHub project for user"""

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

Expand All @@ -6,6 +8,8 @@

class Command(BaseCommand):

help = __doc__

def handle(self, *args, **options):
if len(args):
for slug in args:
Expand Down
21 changes: 12 additions & 9 deletions readthedocs/core/management/commands/import_github_language.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion readthedocs/core/management/commands/pull.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,9 @@


class Command(BaseCommand):

help = __doc__

def handle(self, *args, **options):
if len(args):
for slug in args:
Expand Down
14 changes: 9 additions & 5 deletions readthedocs/core/management/commands/reindex_elasticsearch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Reindex Elastic Search indexes"""

import logging
from optparse import make_option

Expand All @@ -14,6 +16,7 @@

class Command(BaseCommand):

help = __doc__
option_list = BaseCommand.option_list + (
make_option('-p',
dest='project',
Expand All @@ -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)
11 changes: 7 additions & 4 deletions readthedocs/core/management/commands/set_metadata.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
4 changes: 4 additions & 0 deletions readthedocs/core/management/commands/symlink.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Update symlinks for projects"""

import logging

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

class Command(BaseCommand):

help = __doc__

def add_arguments(self, parser):
parser.add_argument('projects', nargs='+', type=str)

Expand Down
18 changes: 10 additions & 8 deletions readthedocs/core/management/commands/update_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
Build documentation using the API and not hitting a database.

Usage::

./manage.py update_api <slug>
"""

import logging

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

class Command(BaseCommand):

"""
Build documentation using the API and not hitting a database.

Usage::

./manage.py update_api <slug>
"""
help = __doc__

def add_arguments(self, parser):
parser.add_argument('--docker', action='store_true', default=False)
Expand All @@ -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)
23 changes: 11 additions & 12 deletions readthedocs/core/management/commands/update_repos.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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',
Expand All @@ -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):
Expand All @@ -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":
Expand 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__
8 changes: 3 additions & 5 deletions readthedocs/core/management/commands/update_versions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Rebuild documentation for all projects"""

from django.core.management.base import BaseCommand

from readthedocs.builds.models import Version
Expand All @@ -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):
Expand Down
10 changes: 10 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 Expand Up @@ -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

Expand Down
Loading