Skip to content

Commit 60714be

Browse files
committed
Lint search branch
1 parent 46c4f20 commit 60714be

File tree

13 files changed

+85
-83
lines changed

13 files changed

+85
-83
lines changed

common

readthedocs/projects/models.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import fnmatch
66
import logging
77
import os
8-
from six.moves import shlex_quote
98

10-
from builtins import object # pylint: disable=redefined-builtin
119
from django.conf import settings
1210
from django.contrib.auth.models import User
1311
from django.db import models
@@ -658,10 +656,7 @@ def full_dash_path(self, version=LATEST):
658656

659657
def full_json_path(self, version=LATEST):
660658
"""The path to the build json docs in the project."""
661-
json_path = os.path.join(
662-
self.conf_dir(version),
663-
'_build', 'json'
664-
)
659+
json_path = os.path.join(self.conf_dir(version), '_build', 'json')
665660
return json_path
666661

667662
def full_singlehtml_path(self, version=LATEST):
@@ -849,7 +844,8 @@ def get_latest_build(self, finished=True):
849844
def api_versions(self):
850845
from readthedocs.builds.models import APIVersion
851846
ret = []
852-
for version_data in api.project(self.pk).active_versions.get()['versions']:
847+
for version_data in api.project(self.pk
848+
).active_versions.get()['versions']:
853849
version = APIVersion(**version_data)
854850
ret.append(version)
855851
return sort_version_aware(ret)
@@ -1044,13 +1040,8 @@ def __init__(self, *args, **kwargs):
10441040
ad_free = (not kwargs.pop('show_advertising', True))
10451041
# These fields only exist on the API return, not on the model, so we'll
10461042
# remove them to avoid throwing exceptions due to unexpected fields
1047-
for key in [
1048-
'users',
1049-
'resource_uri',
1050-
'absolute_url',
1051-
'downloads',
1052-
'main_language_project',
1053-
'related_projects']:
1043+
for key in ['users', 'resource_uri', 'absolute_url', 'downloads',
1044+
'main_language_project', 'related_projects']:
10541045
try:
10551046
del kwargs[key]
10561047
except KeyError:
@@ -1134,9 +1125,9 @@ def json_file_path(self):
11341125
basename = os.path.splitext(self.path)[0]
11351126
file_path = basename + '.fjson'
11361127

1137-
full_json_path = self.project.get_production_media_path(type_='json',
1138-
version_slug=self.version.slug,
1139-
include_file=False)
1128+
full_json_path = self.project.get_production_media_path(
1129+
type_='json', version_slug=self.version.slug, include_file=False
1130+
)
11401131

11411132
file_path = os.path.join(full_json_path, file_path)
11421133
return file_path
@@ -1146,12 +1137,11 @@ def get_processed_json(self):
11461137
try:
11471138
return process_file(file_path)
11481139
except Exception:
1149-
log.warning('Unhandled exception during search processing file: %s' % file_path)
1140+
log.warning(
1141+
'Unhandled exception during search processing file: %s' % file_path
1142+
)
11501143
return {
1151-
'headers': [],
1152-
'content': '',
1153-
'path': file_path,
1154-
'title': '',
1144+
'headers': [], 'content': '', 'path': file_path, 'title': '',
11551145
'sections': []
11561146
}
11571147

@@ -1296,36 +1286,30 @@ def add_features(sender, **kwargs):
12961286
(USE_SETUPTOOLS_LATEST, _('Use latest version of setuptools')),
12971287
(ALLOW_DEPRECATED_WEBHOOKS, _('Allow deprecated webhook views')),
12981288
(PIP_ALWAYS_UPGRADE, _('Always run pip install --upgrade')),
1299-
(SKIP_SUBMODULES, _('Skip git submodule checkout')),
1300-
(
1289+
(SKIP_SUBMODULES, _('Skip git submodule checkout')), (
13011290
DONT_OVERWRITE_SPHINX_CONTEXT,
13021291
_(
13031292
'Do not overwrite context vars in conf.py with Read the Docs context',
13041293
),
1305-
),
1306-
(
1294+
), (
13071295
ALLOW_V2_CONFIG_FILE,
13081296
_(
13091297
'Allow to use the v2 of the configuration file',
13101298
),
1311-
),
1312-
(
1299+
), (
13131300
MKDOCS_THEME_RTD,
13141301
_('Use Read the Docs theme for MkDocs as default theme')
1315-
),
1316-
(
1302+
), (
13171303
DONT_SHALLOW_CLONE,
13181304
_(
13191305
'Do not shallow clone when cloning git repos',
13201306
),
1321-
),
1322-
(
1307+
), (
13231308
USE_TESTING_BUILD_IMAGE,
13241309
_(
13251310
'Use Docker image labelled as `testing` to build the docs',
13261311
),
1327-
),
1328-
(API_LARGE_DATA, _('Try alternative method of posting large data'))
1312+
), (API_LARGE_DATA, _('Try alternative method of posting large data'))
13291313
)
13301314

13311315
projects = models.ManyToManyField(

readthedocs/projects/signals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
files_changed = django.dispatch.Signal(providing_args=['project', 'files'])
1717

18-
bulk_post_create = django.dispatch.Signal(providing_args=["instance_list"])
18+
bulk_post_create = django.dispatch.Signal(providing_args=['instance_list'])
1919

20-
bulk_post_delete = django.dispatch.Signal(providing_args=["instance_list"])
20+
bulk_post_delete = django.dispatch.Signal(providing_args=['instance_list'])
2121

2222
# Used to force verify a domain (eg. for SSL cert issuance)
2323
domain_verify = django.dispatch.Signal(providing_args=['domain'])

readthedocs/projects/tasks.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,15 @@
6262
from readthedocs.restapi.client import api as api_v2
6363
from readthedocs.vcs_support import utils as vcs_support_utils
6464
from readthedocs.worker import app
65+
6566
from .constants import LOG_TEMPLATE
6667
from .exceptions import RepositoryError
67-
from .models import Domain, ImportedFile, Project
68-
from .models import HTMLFile
68+
from .models import Domain, HTMLFile, ImportedFile, Project
6969
from .signals import (
7070
after_build,
7171
after_vcs,
7272
before_build,
7373
before_vcs,
74-
files_changed,
7574
bulk_post_create,
7675
bulk_post_delete,
7776
domain_verify,
@@ -1153,8 +1152,9 @@ def _manage_imported_files(version, path, commit):
11531152
else:
11541153
model_class = ImportedFile
11551154

1156-
dirpath = os.path.join(root.replace(path, '').lstrip('/'),
1157-
filename.lstrip('/'))
1155+
dirpath = os.path.join(
1156+
root.replace(path, '').lstrip('/'), filename.lstrip('/')
1157+
)
11581158
full_path = os.path.join(root, filename)
11591159
md5 = hashlib.md5(open(full_path, 'rb').read()).hexdigest()
11601160
try:
@@ -1184,8 +1184,10 @@ def _manage_imported_files(version, path, commit):
11841184

11851185
# Delete the HTMLFile first from previous commit and
11861186
# send bulk_post_delete signal for bulk removing from Elasticsearch
1187-
delete_queryset = (HTMLFile.objects.filter(project=version.project, version=version)
1188-
.exclude(commit=commit))
1187+
delete_queryset = (
1188+
HTMLFile.objects.filter(project=version.project,
1189+
version=version).exclude(commit=commit)
1190+
)
11891191
# Keep the objects into memory to send it to signal
11901192
instance_list = list(delete_queryset)
11911193
# Safely delete from database
@@ -1194,8 +1196,11 @@ def _manage_imported_files(version, path, commit):
11941196
bulk_post_delete.send(sender=HTMLFile, instance_list=instance_list)
11951197

11961198
# Delete ImportedFiles from previous versions
1197-
(ImportedFile.objects.filter(project=version.project, version=version)
1198-
.exclude(commit=commit).delete())
1199+
(
1200+
ImportedFile.objects.filter(project=version.project,
1201+
version=version).exclude(commit=commit
1202+
).delete()
1203+
)
11991204
changed_files = [
12001205
resolve_path(
12011206
version.project,

readthedocs/projects/views/public.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from readthedocs.builds.constants import LATEST
2525
from readthedocs.builds.models import Version
2626
from readthedocs.builds.views import BuildTriggerMixin
27-
from readthedocs.projects.models import ImportedFile, Project
27+
from readthedocs.projects.models import Project
2828
from readthedocs.search.documents import PageDocument
2929
from readthedocs.search.views import LOG_TEMPLATE
3030

@@ -262,8 +262,10 @@ def elastic_project_search(request, project_slug):
262262

263263
if query:
264264
req = PageDocument.simple_search(query=query)
265-
filtered_query = (req.filter('term', project=project.slug)
266-
.filter('term', version=version_slug))
265+
filtered_query = (
266+
req.filter('term', project=project.slug)
267+
.filter('term', version=version_slug)
268+
)
267269
paginated_query = filtered_query[:50]
268270
results = paginated_query.execute()
269271

readthedocs/restapi/urls.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
from rest_framework import routers
88

99
from readthedocs.constants import pattern_opts
10-
from readthedocs.restapi.views import (core_views, footer_views, task_views, integrations)
10+
from readthedocs.restapi.views import (
11+
core_views,
12+
footer_views,
13+
integrations,
14+
task_views,
15+
)
16+
1117
from .views.model_views import (
1218
BuildCommandViewSet,
1319
BuildViewSet,
@@ -105,12 +111,10 @@
105111
),
106112
]
107113

108-
109114
urlpatterns += function_urls
110115
urlpatterns += task_urls
111116
urlpatterns += integration_urls
112117

113-
114118
if 'readthedocsext.donate' in settings.INSTALLED_APPS:
115119
# pylint: disable=import-error
116120
from readthedocsext.donate.restapi.urls import urlpatterns \

readthedocs/search/parse_json.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ def process_all_json_files(version, build_dir=True):
2727
html_files = []
2828
for root, _, files in os.walk(full_path):
2929
for filename in fnmatch.filter(files, '*.fjson'):
30-
if filename in [
31-
'search.fjson',
32-
'genindex.fjson',
33-
'py-modindex.fjson']:
30+
if filename in ['search.fjson', 'genindex.fjson',
31+
'py-modindex.fjson']:
3432
continue
3533
html_files.append(os.path.join(root, filename))
3634
page_list = []

readthedocs/search/signals.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from readthedocs.search.documents import PageDocument, ProjectDocument
1313
from readthedocs.search.tasks import index_objects_to_es
1414

15-
before_project_search = django.dispatch.Signal(providing_args=["body"])
16-
before_file_search = django.dispatch.Signal(providing_args=["body"])
17-
before_section_search = django.dispatch.Signal(providing_args=["body"])
15+
16+
before_project_search = django.dispatch.Signal(providing_args=['body'])
17+
before_file_search = django.dispatch.Signal(providing_args=['body'])
18+
before_section_search = django.dispatch.Signal(providing_args=['body'])
1819

1920

2021
@receiver(bulk_post_create, sender=HTMLFile)

readthedocs/search/tests/test_views.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
# -*- coding: utf-8 -*-
12

23
import pytest
34
from django.core.urlresolvers import reverse
45
from django_dynamic_fixture import G
5-
66
from pyquery import PyQuery as pq
77

8-
98
from readthedocs.builds.constants import LATEST
109
from readthedocs.builds.models import Version
11-
from readthedocs.projects.models import Project, HTMLFile
10+
from readthedocs.projects.models import HTMLFile, Project
1211
from readthedocs.search.tests.utils import get_search_query_from_project_file
1312

1413

@@ -34,7 +33,7 @@ def test_search_by_project_name(self, client, project):
3433
assert project.name.encode('utf-8') in result.text().encode('utf-8')
3534

3635
def test_search_project_show_languages(self, client, project):
37-
"""Test that searching project should show all available languages"""
36+
"""Test that searching project should show all available languages."""
3837
# Create a project in bn and add it as a translation
3938
G(Project, language='bn', name=project.name)
4039

@@ -49,7 +48,7 @@ def test_search_project_show_languages(self, client, project):
4948
assert 'bn' in content.text()
5049

5150
def test_search_project_filter_language(self, client, project):
52-
"""Test that searching project filtered according to language"""
51+
"""Test that searching project filtered according to language."""
5352
# Create a project in bn and add it as a translation
5453
translate = G(Project, language='bn', name=project.name)
5554
search_params = {'q': project.name, 'language': 'bn'}
@@ -94,7 +93,8 @@ def test_file_search(self, client, project, data_type, page_num):
9493

9594
@pytest.mark.parametrize('case', ['upper', 'lower', 'title'])
9695
def test_file_search_case_insensitive(self, client, project, case):
97-
"""Check File search is case insensitive
96+
"""
97+
Check File search is case insensitive.
9898
9999
It tests with uppercase, lowercase and camelcase
100100
"""
@@ -111,10 +111,11 @@ def test_file_search_case_insensitive(self, client, project, case):
111111
assert query_text in result.text()
112112

113113
def test_file_search_exact_match(self, client, project):
114-
"""Check quoted query match exact phrase
114+
"""
115+
Check quoted query match exact phrase.
115116
116-
Making a query with quoted text like ``"foo bar"`` should match
117-
exactly ``foo bar`` phrase.
117+
Making a query with quoted text like ``"foo bar"`` should match exactly
118+
``foo bar`` phrase.
118119
"""
119120

120121
# `Github` word is present both in `kuma` and `pipeline` files
@@ -128,7 +129,7 @@ def test_file_search_exact_match(self, client, project):
128129
assert len(result) == 1
129130

130131
def test_page_search_not_return_removed_page(self, client, project):
131-
"""Check removed page are not in the search index"""
132+
"""Check removed page are not in the search index."""
132133
query = get_search_query_from_project_file(project_slug=project.slug)
133134
# Make a query to check it returns result
134135
result, _ = self._get_search_result(url=self.url, client=client,
@@ -143,7 +144,8 @@ def test_page_search_not_return_removed_page(self, client, project):
143144
assert len(result) == 0
144145

145146
def test_file_search_show_projects(self, client, all_projects):
146-
"""Test that search result page shows list of projects while searching for files"""
147+
"""Test that search result page shows list of projects while searching
148+
for files."""
147149

148150
# `Github` word is present both in `kuma` and `pipeline` files
149151
# so search with this phrase

readthedocs/search/tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
from readthedocs.projects.models import HTMLFile
23

34

readthedocs/search/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import os
1010
import re
1111

12-
from builtins import next, range
1312
from django.shortcuts import get_object_or_404
1413
from pyquery import PyQuery
1514

1615
from readthedocs.projects.models import Project
1716

17+
1818
log = logging.getLogger(__name__)
1919

2020

@@ -338,7 +338,7 @@ def get_project_list_or_404(project_slug, user):
338338

339339

340340
def get_chunk(total, chunk_size):
341-
"""Yield successive `chunk_size` chunks"""
341+
"""Yield successive `chunk_size` chunks."""
342342
# Based on https://stackoverflow.com/a/312464
343343
# licensed under cc by-sa 3.0
344344
for i in range(0, total, chunk_size):

0 commit comments

Comments
 (0)