Skip to content

Commit 3747975

Browse files
committed
Merge pull request #1580 from rtfd/lint-project
Lint project code
2 parents 4a53579 + 3fcf523 commit 3747975

30 files changed

+677
-429
lines changed

prospector.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ uses:
88
- celery
99

1010
ignore-paths:
11-
- projects
1211
- docs
1312

1413
ignore-patterns:
1514
- /migrations/
1615

1716
pep8:
18-
full: true
19-
options:
20-
max-line-length: 100
21-
disable:
22-
- N806
17+
full: true
18+
options:
19+
max-line-length: 100
2320

2421
pylint:
25-
max-line-length: 100
22+
options:
23+
dummy-variables-rgx: '_$|__$|dummy'
24+
max-line-length: 100
2625
disable:
27-
- logging-format-interpolation
26+
- logging-format-interpolation
2827

2928
mccabe:
3029
run: false

readthedocs/builds/models.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
RelatedBuildManager)
1616
from readthedocs.projects.models import Project
1717
from readthedocs.projects.constants import (PRIVACY_CHOICES, REPO_TYPE_GIT,
18-
REPO_TYPE_HG)
18+
REPO_TYPE_HG, GITHUB_URL,
19+
GITHUB_REGEXS, BITBUCKET_URL,
20+
BITBUCKET_REGEXS)
1921

2022
from .constants import (BUILD_STATE, BUILD_TYPES, VERSION_TYPES,
2123
LATEST, NON_REPOSITORY_VERSIONS, STABLE,
@@ -228,14 +230,6 @@ def get_vcs_slug(self):
228230
return slug
229231

230232
def get_github_url(self, docroot, filename, source_suffix='.rst', action='view'):
231-
GITHUB_REGEXS = [
232-
re.compile('github.com/(.+)/(.+)(?:\.git){1}'),
233-
re.compile('github.com/(.+)/(.+)'),
234-
re.compile('github.com:(.+)/(.+).git'),
235-
]
236-
GITHUB_URL = ('https://github.com/{user}/{repo}/'
237-
'{action}/{version}{docroot}{path}{source_suffix}')
238-
239233
repo_url = self.project.repo
240234
if 'github' not in repo_url:
241235
return ''
@@ -273,20 +267,13 @@ def get_github_url(self, docroot, filename, source_suffix='.rst', action='view')
273267
)
274268

275269
def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
276-
BB_REGEXS = [
277-
re.compile('bitbucket.org/(.+)/(.+).git'),
278-
re.compile('bitbucket.org/(.+)/(.+)/'),
279-
re.compile('bitbucket.org/(.+)/(.+)'),
280-
]
281-
BB_URL = 'https://bitbucket.org/{user}/{repo}/src/{version}{docroot}{path}{source_suffix}'
282-
283270
repo_url = self.project.repo
284271
if 'bitbucket' not in repo_url:
285272
return ''
286273
if not docroot:
287274
return ''
288275

289-
for regex in BB_REGEXS:
276+
for regex in BITBUCKET_REGEXS:
290277
match = regex.search(repo_url)
291278
if match:
292279
user, repo = match.groups()
@@ -295,7 +282,7 @@ def get_bitbucket_url(self, docroot, filename, source_suffix='.rst'):
295282
return ''
296283
repo = repo.rstrip('/')
297284

298-
return BB_URL.format(
285+
return BITBUCKET_URL.format(
299286
user=user,
300287
repo=repo,
301288
version=self.remote_slug,

readthedocs/comments/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def create(self, request):
187187
project = Project.objects.get(slug=request.data['project'])
188188
comment = project.add_comment(version_slug=request.data['version'],
189189
page=request.data['document_page'],
190-
hash=request.data['node'],
190+
content_hash=request.data['node'],
191191
commit=request.data['commit'],
192192
user=request.user,
193193
text=request.data['text'])

readthedocs/doc_builder/backends/mkdocs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def build(self, **kwargs):
143143
checkout_path = self.project.checkout_path(self.version.slug)
144144
build_command = [
145145
'python',
146-
self.project.venv_bin(version=self.version.slug, bin='mkdocs'),
146+
self.project.venv_bin(version=self.version.slug, filename='mkdocs'),
147147
self.builder,
148148
'--clean',
149149
'--site-dir', self.build_dir,

readthedocs/doc_builder/backends/sphinx.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def build(self, **kwargs):
128128
project = self.project
129129
build_command = [
130130
'python',
131-
project.venv_bin(version=self.version.slug, bin='sphinx-build'),
131+
project.venv_bin(version=self.version.slug, filename='sphinx-build'),
132132
'-T'
133133
]
134134
if self._force:
@@ -249,7 +249,8 @@ def build(self, **kwargs):
249249
# Default to this so we can return it always.
250250
self.run(
251251
'python',
252-
self.project.venv_bin(version=self.version.slug, bin='sphinx-build'),
252+
self.project.venv_bin(version=self.version.slug,
253+
filename='sphinx-build'),
253254
'-b', 'latex',
254255
'-D', 'language={lang}'.format(lang=self.project.language),
255256
'-d', '_build/doctrees',

readthedocs/doc_builder/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, build_env, force=False):
3636
self._force = force
3737
self.target = self.project.artifact_path(
3838
version=self.version.slug,
39-
type=self.type
39+
type_=self.type
4040
)
4141

4242
def force(self, **kwargs):

readthedocs/projects/admin.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
1-
"""Django administration interface for `~projects.models.Project`
2-
and related models.
3-
"""
1+
"""Django administration interface for `projects.models`"""
42

53
from readthedocs.builds.models import Version
64
from django.contrib import admin
75
from readthedocs.redirects.models import Redirect
8-
from readthedocs.projects.models import (Project, ImportedFile, ProjectRelationship, EmailHook, WebHook)
6+
from readthedocs.projects.models import (Project, ImportedFile,
7+
ProjectRelationship, EmailHook,
8+
WebHook)
99
from guardian.admin import GuardedModelAdmin
1010

1111

1212
class ProjectRelationshipInline(admin.TabularInline):
13+
14+
"""Project inline relationship view for :py:cls:`ProjectAdmin`"""
15+
1316
model = ProjectRelationship
1417
fk_name = 'parent'
1518
raw_id_fields = ('child',)
1619

1720

1821
class VersionInline(admin.TabularInline):
22+
23+
"""Version inline relationship view for :py:cls:`ProjectAdmin`"""
24+
1925
model = Version
2026

2127

2228
class RedirectInline(admin.TabularInline):
29+
30+
"""Redirect inline relationship view for :py:cls:`ProjectAdmin`"""
31+
2332
model = Redirect
2433

2534

2635
class ProjectAdmin(GuardedModelAdmin):
36+
37+
"""Project model admin view"""
38+
2739
prepopulated_fields = {'slug': ('name',)}
2840
list_display = ('name', 'repo', 'repo_type', 'allow_comments', 'featured', 'theme')
29-
list_filter = ('repo_type', 'allow_comments', 'featured', 'privacy_level', 'documentation_type', 'programming_language')
41+
list_filter = ('repo_type', 'allow_comments', 'featured', 'privacy_level',
42+
'documentation_type', 'programming_language')
3043
list_editable = ('featured',)
3144
search_fields = ('slug', 'repo')
3245
inlines = [ProjectRelationshipInline, RedirectInline, VersionInline]
3346
raw_id_fields = ('users', 'main_language_project')
3447

3548

3649
class ImportedFileAdmin(admin.ModelAdmin):
50+
51+
"""Admin view for :py:cls:`ImportedFile`"""
52+
3753
list_display = ('path', 'name', 'version')
3854

3955

readthedocs/projects/backends/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
'''
1+
"""
22
Project views loaded by configuration settings
33
44
Use these views instead of calling the views directly, in order to allow for
55
settings override of the view class.
6-
'''
6+
"""
77

88
from django.utils.module_loading import import_by_path
99
from django.conf import settings

readthedocs/projects/constants.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
"""Default values and other various configuration for projects,
2-
including available theme names and repository types.
1+
"""Project constants
2+
3+
Default values and other various configuration for projects, including available
4+
theme names and repository types.
35
"""
46

57
import re
@@ -20,17 +22,17 @@
2022
('mkdocs', _('Mkdocs (Markdown)')),
2123
('sphinx_htmldir', _('Sphinx HtmlDir')),
2224
('sphinx_singlehtml', _('Sphinx Single Page HTML')),
23-
#('sphinx_websupport2', _('Sphinx Websupport')),
24-
#('rdoc', 'Rdoc'),
25+
# ('sphinx_websupport2', _('Sphinx Websupport')),
26+
# ('rdoc', 'Rdoc'),
2527
)
2628

2729
DEFAULT_THEME_CHOICES = (
2830
# Translators: This is a name of a Sphinx theme.
2931
(THEME_DEFAULT, _('Default')),
3032
# Translators: This is a name of a Sphinx theme.
3133
(THEME_SPHINX, _('Sphinx Docs')),
32-
#(THEME_SCROLLS, 'Scrolls'),
33-
#(THEME_AGOGO, 'Agogo'),
34+
# (THEME_SCROLLS, 'Scrolls'),
35+
# (THEME_AGOGO, 'Agogo'),
3436
# Translators: This is a name of a Sphinx theme.
3537
(THEME_TRADITIONAL, _('Traditional')),
3638
# Translators: This is a name of a Sphinx theme.
@@ -277,3 +279,18 @@
277279

278280
PROJECT_PK_REGEX = '(?:[-\w]+)'
279281
PROJECT_SLUG_REGEX = '(?:[-\w]+)'
282+
283+
GITHUB_REGEXS = [
284+
re.compile('github.com/(.+)/(.+)(?:\.git){1}'),
285+
re.compile('github.com/(.+)/(.+)'),
286+
re.compile('github.com:(.+)/(.+).git'),
287+
]
288+
BITBUCKET_REGEXS = [
289+
re.compile('bitbucket.org/(.+)/(.+).git'),
290+
re.compile('bitbucket.org/(.+)/(.+)/'),
291+
re.compile('bitbucket.org/(.+)/(.+)'),
292+
]
293+
GITHUB_URL = ('https://github.com/{user}/{repo}/'
294+
'{action}/{version}{docroot}{path}{source_suffix}')
295+
BITBUCKET_URL = ('https://bitbucket.org/{user}/{repo}/'
296+
'src/{version}{docroot}{path}{source_suffix}')

readthedocs/projects/exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Project exceptions"""
2+
3+
14
class ProjectImportError (Exception):
5+
26
"""Failure to import a project from a repository."""
7+
38
pass

readthedocs/projects/feeds.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
"""Project RSS feeds"""
2+
13
from django.contrib.syndication.views import Feed
24

35
from readthedocs.projects.models import Project
46

57

68
class LatestProjectsFeed(Feed):
9+
10+
"""RSS feed for projects that were recently updated"""
11+
712
title = "Recently updated documentation"
813
link = "http://readthedocs.org"
914
description = "Recently updated documentation on Read the Docs"
@@ -19,6 +24,9 @@ def item_description(self, item):
1924

2025

2126
class NewProjectsFeed(Feed):
27+
28+
"""RSS feed for newly created projects"""
29+
2230
title = "Newest documentation"
2331
link = "http://readthedocs.org"
2432
description = "Recently created documentation on Read the Docs"

readthedocs/projects/filters.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Project query filters"""
2+
13
from django.utils.translation import ugettext_lazy as _
24

35
import django_filters
@@ -13,26 +15,38 @@
1315

1416

1517
def sort_slug(queryset, query):
18+
"""Fuzzy filter for slug fields
19+
20+
Returns sorted queryset where slug approximates ``query``
21+
"""
1622
queryset = queryset.filter(slug__icontains=query)
1723
ret = []
18-
ret.extend([q.pk for q in queryset if q.slug == query])
19-
ret.extend([q.pk for q in queryset if q.slug.startswith(query) and q.pk not in ret])
20-
ret.extend([q.pk for q in queryset if q.slug.endswith(query) and q.pk not in ret])
21-
ret.extend([q.pk for q in queryset if q.pk not in ret])
24+
ret.extend([q.pk for q in queryset
25+
if q.slug == query])
26+
ret.extend([q.pk for q in queryset
27+
if q.slug.startswith(query) and q.pk not in ret])
28+
ret.extend([q.pk for q in queryset
29+
if q.slug.endswith(query) and q.pk not in ret])
30+
ret.extend([q.pk for q in queryset
31+
if q.pk not in ret])
2232

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

3141

3242
class ProjectFilter(django_filters.FilterSet):
43+
44+
"""Project filter for filter views"""
45+
3346
name = django_filters.CharFilter(label=_("Name"), name='name',
3447
lookup_type='icontains')
35-
slug = django_filters.CharFilter(label=_("Slug"), name='slug', action=sort_slug)
48+
slug = django_filters.CharFilter(label=_("Slug"), name='slug',
49+
action=sort_slug)
3650
pub_date = django_filters.DateRangeFilter(label=_("Created Date"),
3751
name="pub_date")
3852
repo = django_filters.CharFilter(label=_("Repository URL"), name='repo',

0 commit comments

Comments
 (0)