Skip to content

Lint project code #1580

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 1 commit into from
Aug 26, 2015
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
15 changes: 7 additions & 8 deletions prospector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ uses:
- celery

ignore-paths:
- projects
- docs

ignore-patterns:
- /migrations/

pep8:
full: true
options:
max-line-length: 100
disable:
- N806
full: true
options:
max-line-length: 100

pylint:
max-line-length: 100
options:
dummy-variables-rgx: '_$|__$|dummy'
max-line-length: 100
disable:
- logging-format-interpolation
- logging-format-interpolation

mccabe:
run: false
Expand Down
23 changes: 5 additions & 18 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
RelatedBuildManager)
from readthedocs.projects.models import Project
from readthedocs.projects.constants import (PRIVACY_CHOICES, REPO_TYPE_GIT,
REPO_TYPE_HG)
REPO_TYPE_HG, GITHUB_URL,
GITHUB_REGEXS, BITBUCKET_URL,
BITBUCKET_REGEXS)

from .constants import (BUILD_STATE, BUILD_TYPES, VERSION_TYPES,
LATEST, NON_REPOSITORY_VERSIONS, STABLE,
Expand Down Expand Up @@ -228,14 +230,6 @@ def get_vcs_slug(self):
return slug

def get_github_url(self, docroot, filename, source_suffix='.rst', action='view'):
GITHUB_REGEXS = [
re.compile('github.com/(.+)/(.+)(?:\.git){1}'),
re.compile('github.com/(.+)/(.+)'),
re.compile('github.com:(.+)/(.+).git'),
]
GITHUB_URL = ('https://github.com/{user}/{repo}/'
'{action}/{version}{docroot}{path}{source_suffix}')

repo_url = self.project.repo
if 'github' not in repo_url:
return ''
Expand Down Expand Up @@ -273,20 +267,13 @@ def get_github_url(self, docroot, filename, source_suffix='.rst', action='view')
)

def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
BB_REGEXS = [
re.compile('bitbucket.org/(.+)/(.+).git'),
re.compile('bitbucket.org/(.+)/(.+)/'),
re.compile('bitbucket.org/(.+)/(.+)'),
]
BB_URL = 'https://bitbucket.org/{user}/{repo}/src/{version}{docroot}{path}{source_suffix}'

repo_url = self.project.repo
if 'bitbucket' not in repo_url:
return ''
if not docroot:
return ''

for regex in BB_REGEXS:
for regex in BITBUCKET_REGEXS:
match = regex.search(repo_url)
if match:
user, repo = match.groups()
Expand All @@ -295,7 +282,7 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
return ''
repo = repo.rstrip('/')

return BB_URL.format(
return BITBUCKET_URL.format(
user=user,
repo=repo,
version=self.remote_slug,
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create(self, request):
project = Project.objects.get(slug=request.data['project'])
comment = project.add_comment(version_slug=request.data['version'],
page=request.data['document_page'],
hash=request.data['node'],
content_hash=request.data['node'],
commit=request.data['commit'],
user=request.user,
text=request.data['text'])
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def build(self, **kwargs):
checkout_path = self.project.checkout_path(self.version.slug)
build_command = [
'python',
self.project.venv_bin(version=self.version.slug, bin='mkdocs'),
self.project.venv_bin(version=self.version.slug, filename='mkdocs'),
self.builder,
'--clean',
'--site-dir', self.build_dir,
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def build(self, **kwargs):
project = self.project
build_command = [
'python',
project.venv_bin(version=self.version.slug, bin='sphinx-build'),
project.venv_bin(version=self.version.slug, filename='sphinx-build'),
'-T'
]
if self._force:
Expand Down Expand Up @@ -249,7 +249,8 @@ def build(self, **kwargs):
# Default to this so we can return it always.
self.run(
'python',
self.project.venv_bin(version=self.version.slug, bin='sphinx-build'),
self.project.venv_bin(version=self.version.slug,
filename='sphinx-build'),
'-b', 'latex',
'-D', 'language={lang}'.format(lang=self.project.language),
'-d', '_build/doctrees',
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, build_env, force=False):
self._force = force
self.target = self.project.artifact_path(
version=self.version.slug,
type=self.type
type_=self.type
)

def force(self, **kwargs):
Expand Down
26 changes: 21 additions & 5 deletions readthedocs/projects/admin.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
"""Django administration interface for `~projects.models.Project`
and related models.
"""
"""Django administration interface for `projects.models`"""

from readthedocs.builds.models import Version
from django.contrib import admin
from readthedocs.redirects.models import Redirect
from readthedocs.projects.models import (Project, ImportedFile, ProjectRelationship, EmailHook, WebHook)
from readthedocs.projects.models import (Project, ImportedFile,
ProjectRelationship, EmailHook,
WebHook)
from guardian.admin import GuardedModelAdmin


class ProjectRelationshipInline(admin.TabularInline):

"""Project inline relationship view for :py:cls:`ProjectAdmin`"""

model = ProjectRelationship
fk_name = 'parent'
raw_id_fields = ('child',)


class VersionInline(admin.TabularInline):

"""Version inline relationship view for :py:cls:`ProjectAdmin`"""

model = Version


class RedirectInline(admin.TabularInline):

"""Redirect inline relationship view for :py:cls:`ProjectAdmin`"""

model = Redirect


class ProjectAdmin(GuardedModelAdmin):

"""Project model admin view"""

prepopulated_fields = {'slug': ('name',)}
list_display = ('name', 'repo', 'repo_type', 'allow_comments', 'featured', 'theme')
list_filter = ('repo_type', 'allow_comments', 'featured', 'privacy_level', 'documentation_type', 'programming_language')
list_filter = ('repo_type', 'allow_comments', 'featured', 'privacy_level',
'documentation_type', 'programming_language')
list_editable = ('featured',)
search_fields = ('slug', 'repo')
inlines = [ProjectRelationshipInline, RedirectInline, VersionInline]
raw_id_fields = ('users', 'main_language_project')


class ImportedFileAdmin(admin.ModelAdmin):

"""Admin view for :py:cls:`ImportedFile`"""

list_display = ('path', 'name', 'version')


Expand Down
4 changes: 2 additions & 2 deletions readthedocs/projects/backends/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'''
"""
Project views loaded by configuration settings

Use these views instead of calling the views directly, in order to allow for
settings override of the view class.
'''
"""

from django.utils.module_loading import import_by_path
from django.conf import settings
Expand Down
29 changes: 23 additions & 6 deletions readthedocs/projects/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Default values and other various configuration for projects,
including available theme names and repository types.
"""Project constants

Default values and other various configuration for projects, including available
theme names and repository types.
"""

import re
Expand All @@ -20,17 +22,17 @@
('mkdocs', _('Mkdocs (Markdown)')),
('sphinx_htmldir', _('Sphinx HtmlDir')),
('sphinx_singlehtml', _('Sphinx Single Page HTML')),
#('sphinx_websupport2', _('Sphinx Websupport')),
#('rdoc', 'Rdoc'),
# ('sphinx_websupport2', _('Sphinx Websupport')),
# ('rdoc', 'Rdoc'),
)

DEFAULT_THEME_CHOICES = (
# Translators: This is a name of a Sphinx theme.
(THEME_DEFAULT, _('Default')),
# Translators: This is a name of a Sphinx theme.
(THEME_SPHINX, _('Sphinx Docs')),
#(THEME_SCROLLS, 'Scrolls'),
#(THEME_AGOGO, 'Agogo'),
# (THEME_SCROLLS, 'Scrolls'),
# (THEME_AGOGO, 'Agogo'),
# Translators: This is a name of a Sphinx theme.
(THEME_TRADITIONAL, _('Traditional')),
# Translators: This is a name of a Sphinx theme.
Expand Down Expand Up @@ -277,3 +279,18 @@

PROJECT_PK_REGEX = '(?:[-\w]+)'
PROJECT_SLUG_REGEX = '(?:[-\w]+)'

GITHUB_REGEXS = [
re.compile('github.com/(.+)/(.+)(?:\.git){1}'),
re.compile('github.com/(.+)/(.+)'),
re.compile('github.com:(.+)/(.+).git'),
]
BITBUCKET_REGEXS = [
re.compile('bitbucket.org/(.+)/(.+).git'),
re.compile('bitbucket.org/(.+)/(.+)/'),
re.compile('bitbucket.org/(.+)/(.+)'),
]
GITHUB_URL = ('https://github.com/{user}/{repo}/'
'{action}/{version}{docroot}{path}{source_suffix}')
BITBUCKET_URL = ('https://bitbucket.org/{user}/{repo}/'
'src/{version}{docroot}{path}{source_suffix}')
5 changes: 5 additions & 0 deletions readthedocs/projects/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""Project exceptions"""


class ProjectImportError (Exception):

"""Failure to import a project from a repository."""

pass
8 changes: 8 additions & 0 deletions readthedocs/projects/feeds.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""Project RSS feeds"""

from django.contrib.syndication.views import Feed

from readthedocs.projects.models import Project


class LatestProjectsFeed(Feed):

"""RSS feed for projects that were recently updated"""

title = "Recently updated documentation"
link = "http://readthedocs.org"
description = "Recently updated documentation on Read the Docs"
Expand All @@ -19,6 +24,9 @@ def item_description(self, item):


class NewProjectsFeed(Feed):

"""RSS feed for newly created projects"""

title = "Newest documentation"
link = "http://readthedocs.org"
description = "Recently created documentation on Read the Docs"
Expand Down
28 changes: 21 additions & 7 deletions readthedocs/projects/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Project query filters"""

from django.utils.translation import ugettext_lazy as _

import django_filters
Expand All @@ -13,26 +15,38 @@


def sort_slug(queryset, query):
"""Fuzzy filter for slug fields

Returns sorted queryset where slug approximates ``query``
"""
queryset = queryset.filter(slug__icontains=query)
ret = []
ret.extend([q.pk for q in queryset if q.slug == query])
ret.extend([q.pk for q in queryset if q.slug.startswith(query) and q.pk not in ret])
ret.extend([q.pk for q in queryset if q.slug.endswith(query) and q.pk not in ret])
ret.extend([q.pk for q in queryset if q.pk not in ret])
ret.extend([q.pk for q in queryset
if q.slug == query])
ret.extend([q.pk for q in queryset
if q.slug.startswith(query) and q.pk not in ret])
ret.extend([q.pk for q in queryset
if q.slug.endswith(query) and q.pk not in ret])
ret.extend([q.pk for q in queryset
if q.pk not in ret])

# Create a QS preserving ordering
# http://blog.mathieu-leplatre.info/django-create-a-queryset-from-a-list-preserving-order.html
clauses = ' '.join(['WHEN projects_project.id=%s THEN %s' % (pk, i) for i, pk in enumerate(ret)])
clauses = ' '.join(['WHEN projects_project.id=%s THEN %s' % (pk, i)
for i, pk in enumerate(ret)])
ordering = 'CASE %s END' % clauses
ret_queryset = Project.objects.filter(pk__in=ret).extra(
select={'ordering': ordering}, order_by=('ordering',))
return ret_queryset


class ProjectFilter(django_filters.FilterSet):

"""Project filter for filter views"""

name = django_filters.CharFilter(label=_("Name"), name='name',
lookup_type='icontains')
slug = django_filters.CharFilter(label=_("Slug"), name='slug', action=sort_slug)
slug = django_filters.CharFilter(label=_("Slug"), name='slug',
action=sort_slug)
pub_date = django_filters.DateRangeFilter(label=_("Created Date"),
name="pub_date")
repo = django_filters.CharFilter(label=_("Repository URL"), name='repo',
Expand Down
Loading