Skip to content

linting for builds app #2875

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 2 commits into from
May 22, 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 @@ -4,7 +4,6 @@ strictness: medium

ignore-paths:
- api/
- builds/
- cdn/
- comments/
- core/
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/builds/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Constants for the builds app."""

from django.utils.translation import ugettext_lazy as _

BUILD_STATE_TRIGGERED = 'triggered'
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/builds/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""FilterSets for the builds app."""

from django.utils.translation import ugettext_lazy as _

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

from django import forms

from readthedocs.builds.models import VersionAlias, Version
Expand Down
28 changes: 27 additions & 1 deletion readthedocs/builds/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Models for the builds app."""

import logging
import re
import os.path
Expand Down Expand Up @@ -32,6 +34,9 @@


class Version(models.Model):

"""Version of a ``Project``."""

project = models.ForeignKey(Project, verbose_name=_('Project'),
related_name='versions')
type = models.CharField(
Expand Down Expand Up @@ -154,7 +159,7 @@ def save(self, *args, **kwargs):

def delete(self, *args, **kwargs):
from readthedocs.projects import tasks
log.info('Removing files for version %s' % self.slug)
log.info('Removing files for version %s', self.slug)
tasks.clear_artifacts.delay(version_pk=self.pk)
broadcast(type='app', task=tasks.symlink_project, args=[self.project.pk])
super(Version, self).delete(*args, **kwargs)
Expand Down Expand Up @@ -220,6 +225,18 @@ def clean_build_path(self):
log.error('Build path cleanup failed', exc_info=True)

def get_github_url(self, docroot, filename, source_suffix='.rst', action='view'):
"""
Return a GitHub URL for a given filename.

`docroot`
Location of documentation in repository
`filename`
Name of file
`source_suffix`
File suffix of documentation format
`action`
`view` (default) or `edit`
"""
repo_url = self.project.repo
if 'github' not in repo_url:
return ''
Expand Down Expand Up @@ -283,6 +300,9 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):


class VersionAlias(models.Model):

"""Alias for a ``Version``."""

project = models.ForeignKey(Project, verbose_name=_('Project'),
related_name='aliases')
from_slug = models.CharField(_('From slug'), max_length=255, default='')
Expand All @@ -299,6 +319,9 @@ def __unicode__(self):


class Build(models.Model):

"""Build data."""

project = models.ForeignKey(Project, verbose_name=_('Project'),
related_name='builds')
version = models.ForeignKey(Version, verbose_name=_('Version'), null=True,
Expand Down Expand Up @@ -373,6 +396,9 @@ def failed(self):


class BuildCommandResult(BuildCommandResultMixin, models.Model):

"""Build command for a ``Build``."""

build = models.ForeignKey(Build, verbose_name=_('Build'),
related_name='commands')

Expand Down
6 changes: 3 additions & 3 deletions readthedocs/builds/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""URL configuration for builds app."""

from django.conf.urls import url

from .views import (
BuildList, BuildDetail, builds_redirect_detail, builds_redirect_list,
)
from .views import builds_redirect_detail, builds_redirect_list


urlpatterns = [
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/builds/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Utilities for the builds app."""

import re


Expand Down
10 changes: 7 additions & 3 deletions readthedocs/builds/version_slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, *args, **kwargs):
super(VersionSlugField, self).__init__(*args, **kwargs)

def get_queryset(self, model_cls, slug_field):
# pylint: disable=protected-access
for field, model in model_cls._meta.get_fields_with_model():
if model and field == slug_field:
return model._default_manager.all()
Expand Down Expand Up @@ -103,11 +104,14 @@ def uniquifying_suffix(self, iteration):
return '_{suffix}'.format(suffix=suffix)

def create_slug(self, model_instance):
"""Generate a unique slug for a model instance."""
# pylint: disable=protected-access

# get fields to populate from and slug field to set
slug_field = model_instance._meta.get_field(self.attname)

slug = self.slugify(getattr(model_instance, self._populate_from))
next = 0
count = 0

# strip slug depending on max_length attribute of the slug field
# and clean-up
Expand All @@ -134,13 +138,13 @@ def create_slug(self, model_instance):
# depending on the given slug, clean-up
while not slug or queryset.filter(**kwargs):
slug = original_slug
end = self.uniquifying_suffix(next)
end = self.uniquifying_suffix(count)
end_len = len(end)
if slug_len and len(slug) + end_len > slug_len:
slug = slug[:slug_len - end_len]
slug = slug + end
kwargs[self.attname] = slug
next += 1
count += 1

assert self.test_pattern.match(slug), (
'Invalid generated slug: {slug}'.format(slug=slug))
Expand Down
12 changes: 7 additions & 5 deletions readthedocs/builds/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Views for builds app."""

import logging

from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -35,14 +37,14 @@ class BuildList(BuildBase, ListView):
def get_context_data(self, **kwargs):
context = super(BuildList, self).get_context_data(**kwargs)

filter = BuildFilter(self.request.GET, queryset=self.get_queryset())
filterset = BuildFilter(self.request.GET, queryset=self.get_queryset())
active_builds = self.get_queryset().exclude(state="finished").values('id')

context['project'] = self.project
context['filter'] = filter
context['filter'] = filterset
context['active_builds'] = active_builds
context['versions'] = Version.objects.public(user=self.request.user, project=self.project)
context['build_qs'] = filter.qs
context['build_qs'] = filterset.qs

try:
redis = Redis.from_url(settings.BROKER_URL)
Expand All @@ -64,9 +66,9 @@ def get_context_data(self, **kwargs):

# Old build view redirects

def builds_redirect_list(request, project_slug):
def builds_redirect_list(request, project_slug): # pylint: disable=unused-argument
return HttpResponsePermanentRedirect(reverse('builds_project_list', args=[project_slug]))


def builds_redirect_detail(request, project_slug, pk):
def builds_redirect_detail(request, project_slug, pk): # pylint: disable=unused-argument
return HttpResponsePermanentRedirect(reverse('builds_detail', args=[project_slug, pk]))