Skip to content

Commit 8834ff9

Browse files
committed
Run pre-commit and linting
1 parent 5e855c9 commit 8834ff9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+279
-362
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
language: python
22
python:
3-
- 2.7
43
- 3.6
54
env:
65
- ES_VERSION=6.2.4 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
76
matrix:
87
include:
8+
- python: 3.6
9+
env: TOXENV=py36 ES_VERSION=1.3.9 ES_DOWNLOAD_URL=https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
910
- python: 3.6
1011
env: TOXENV=docs
1112
- python: 3.6
@@ -45,6 +46,6 @@ notifications:
4546

4647
branches:
4748
only:
48-
- master
49+
- master
4950
- rel # Community release branch
5051
- relcorp # Corporate release branch

common

docs/conf.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77

88
import sphinx_rtd_theme
9-
from recommonmark.parser import CommonMarkParser
109

1110
sys.path.insert(0, os.path.abspath('..'))
1211
sys.path.append(os.path.dirname(__file__))
@@ -29,13 +28,11 @@
2928
'doc_extensions',
3029
'sphinx_tabs.tabs',
3130
'sphinx-prompt',
31+
'recommonmark',
3232
]
3333
templates_path = ['_templates']
3434

3535
source_suffix = ['.rst', '.md']
36-
source_parsers = {
37-
'.md': CommonMarkParser,
38-
}
3936

4037
master_doc = 'index'
4138
project = u'Read the Docs'

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ We deploy readthedocs.org from the `rel` branch in our GitHub repository. You ca
233233

234234

235235
How can I avoid search results having a deprecated version of my docs?
236-
---------------------------------------------------------------------
236+
----------------------------------------------------------------------
237237

238238
If readers search something related to your docs in Google, it will probably return the most relevant version of your documentation.
239239
It may happen that this version is already deprecated and you want to stop Google indexing it as a result,

readthedocs/builds/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,8 @@ def save(self, *args, **kwargs): # noqa
602602
"""
603603
if self.pk is None or self._config_changed:
604604
previous = self.previous
605-
if (
606-
previous is not None and self._config and
607-
self._config == previous.config
608-
):
605+
if (previous is not None and self._config and
606+
self._config == previous.config):
609607
previous_pk = previous._config.get(self.CONFIG_KEY, previous.pk)
610608
self._config = {self.CONFIG_KEY: previous_pk}
611609
super().save(*args, **kwargs)

readthedocs/builds/views.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import textwrap
7+
from urllib.parse import urlparse
78

89
from django.contrib import messages
910
from django.contrib.auth.decorators import login_required
@@ -17,12 +18,11 @@
1718
from django.utils.decorators import method_decorator
1819
from django.views.generic import DetailView, ListView
1920
from requests.utils import quote
20-
from urllib.parse import urlparse
2121

22-
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
2322
from readthedocs.builds.models import Build, Version
2423
from readthedocs.core.permissions import AdminPermission
2524
from readthedocs.core.utils import trigger_build
25+
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
2626
from readthedocs.projects.models import Project
2727

2828

@@ -110,7 +110,8 @@ def get_context_data(self, **kwargs):
110110
context['project'] = self.project
111111

112112
build = self.get_object()
113-
if build.error != BuildEnvironmentError.GENERIC_WITH_BUILD_ID.format(build_id=build.pk):
113+
if build.error != BuildEnvironmentError.GENERIC_WITH_BUILD_ID.format(
114+
build_id=build.pk):
114115
# Do not suggest to open an issue if the error is not generic
115116
return context
116117

readthedocs/config/config.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# pylint: disable=too-many-lines
23

34
"""Build configuration for rtd."""
@@ -63,13 +64,14 @@
6364
INVALID_KEYS_COMBINATION = 'invalid-keys-combination'
6465
INVALID_KEY = 'invalid-key'
6566

66-
DOCKER_DEFAULT_IMAGE = getattr(settings, 'DOCKER_DEFAULT_IMAGE', 'readthedocs/build')
67+
DOCKER_DEFAULT_IMAGE = getattr(
68+
settings, 'DOCKER_DEFAULT_IMAGE', 'readthedocs/build'
69+
)
6770
DOCKER_DEFAULT_VERSION = getattr(settings, 'DOCKER_DEFAULT_VERSION', '2.0')
6871
# These map to corresponding settings in the .org,
6972
# so they haven't been renamed.
7073
DOCKER_IMAGE = getattr(
71-
settings,
72-
'DOCKER_IMAGE',
74+
settings, 'DOCKER_IMAGE',
7375
'{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
7476
)
7577
DOCKER_IMAGE_SETTINGS = getattr(settings, 'DOCKER_IMAGE_SETTINGS', {})
@@ -240,9 +242,7 @@ def python_full_version(self):
240242
# Get the highest version of the major series version if user only
241243
# gave us a version of '2', or '3'
242244
ver = max(
243-
v
244-
for v in self.get_valid_python_versions()
245-
if v < ver + 1
245+
v for v in self.get_valid_python_versions() if v < ver + 1
246246
)
247247
return ver
248248

@@ -467,9 +467,7 @@ def validate_requirements_file(self):
467467
if not requirements_file:
468468
return None
469469
with self.catch_validation_error('requirements_file'):
470-
requirements_file = validate_file(
471-
requirements_file, self.base_path
472-
)
470+
requirements_file = validate_file(requirements_file, self.base_path)
473471
return requirements_file
474472

475473
def validate_formats(self):
@@ -744,24 +742,21 @@ def validate_python_install(self, index):
744742
requirements_key = key + '.requirements'
745743
with self.catch_validation_error(requirements_key):
746744
requirements = validate_file(
747-
self.pop_config(requirements_key),
748-
self.base_path
745+
self.pop_config(requirements_key), self.base_path
749746
)
750747
python_install['requirements'] = requirements
751748
elif 'path' in raw_install:
752749
path_key = key + '.path'
753750
with self.catch_validation_error(path_key):
754751
path = validate_directory(
755-
self.pop_config(path_key),
756-
self.base_path
752+
self.pop_config(path_key), self.base_path
757753
)
758754
python_install['path'] = path
759755

760756
method_key = key + '.method'
761757
with self.catch_validation_error(method_key):
762758
method = validate_choice(
763-
self.pop_config(method_key, PIP),
764-
self.valid_install_method
759+
self.pop_config(method_key, PIP), self.valid_install_method
765760
)
766761
python_install['method'] = method
767762

@@ -1026,13 +1021,9 @@ def python(self):
10261021
python = self._config['python']
10271022
for install in python['install']:
10281023
if 'requirements' in install:
1029-
python_install.append(
1030-
PythonInstallRequirements(**install)
1031-
)
1024+
python_install.append(PythonInstallRequirements(**install))
10321025
elif 'path' in install:
1033-
python_install.append(
1034-
PythonInstall(**install)
1035-
)
1026+
python_install.append(PythonInstall(**install))
10361027
return Python(
10371028
version=python['version'],
10381029
install=python_install,

readthedocs/config/models.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ def __init__(self, **kwargs):
2222
setattr(self, name, kwargs[name])
2323

2424
def as_dict(self):
25-
return {
26-
name: to_dict(getattr(self, name))
27-
for name in self.__slots__
28-
}
25+
return {name: to_dict(getattr(self, name)) for name in self.__slots__}
2926

3027

3128
class Build(Base):
@@ -45,7 +42,11 @@ class PythonInstallRequirements(Base):
4542

4643
class PythonInstall(Base):
4744

48-
__slots__ = ('path', 'method', 'extra_requirements',)
45+
__slots__ = (
46+
'path',
47+
'method',
48+
'extra_requirements',
49+
)
4950

5051

5152
class Conda(Base):

readthedocs/config/utils.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""Shared functions for the config module."""
23

34

@@ -6,22 +7,13 @@ def to_dict(value):
67
if hasattr(value, 'as_dict'):
78
return value.as_dict()
89
if isinstance(value, list):
9-
return [
10-
to_dict(v)
11-
for v in value
12-
]
10+
return [to_dict(v) for v in value]
1311
if isinstance(value, dict):
14-
return {
15-
k: to_dict(v)
16-
for k, v in value.items()
17-
}
12+
return {k: to_dict(v) for k, v in value.items()}
1813
return value
1914

2015

2116
def list_to_dict(list_):
2217
"""Transform a list to a dictionary with its indices as keys."""
23-
dict_ = {
24-
str(i): element
25-
for i, element in enumerate(list_)
26-
}
18+
dict_ = {str(i): element for i, element in enumerate(list_)}
2719
return dict_

readthedocs/core/management/commands/import_github.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@ class Command(BaseCommand):
1515
def handle(self, *args, **options):
1616
if args:
1717
for slug in args:
18-
for service in GitHubService.for_user(
19-
User.objects.get(
20-
username=slug,
21-
),
22-
):
18+
for service in GitHubService.for_user(User.objects.get(username=slug,),):
2319
service.sync()

readthedocs/core/management/commands/import_github_language.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def handle(self, *args, **options):
3737
print('Invalid GitHub token, exiting')
3838
return
3939

40-
for project in Project.objects.filter(programming_language__in=['none', '', 'words']).filter(repo__contains='github'): # noqa
40+
for project in Project.objects.filter(
41+
programming_language__in=['none', '', 'words']
42+
).filter(repo__contains='github'): # noqa
4143
user = repo = ''
4244
repo_url = project.repo
4345
for regex in GITHUB_REGEXS:

readthedocs/core/middleware.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def process_request(self, request):
6868
subdomain = domain_parts[0]
6969
is_www = subdomain.lower() == 'www'
7070
if not is_www and ( # Support ports during local dev
71-
public_domain in host or public_domain in full_host
72-
):
71+
public_domain in host or public_domain in full_host):
7372
if not Project.objects.filter(slug=subdomain).exists():
7473
raise Http404(_('Project not found'))
7574
request.subdomain = True
@@ -78,10 +77,8 @@ def process_request(self, request):
7877
return None
7978

8079
# Serve CNAMEs
81-
if (
82-
public_domain not in host and production_domain not in host and
83-
'localhost' not in host and 'testserver' not in host
84-
):
80+
if (public_domain not in host and production_domain not in host and
81+
'localhost' not in host and 'testserver' not in host):
8582
request.cname = True
8683
domains = Domain.objects.filter(domain=host)
8784
if domains.count():
@@ -97,10 +94,8 @@ def process_request(self, request):
9794
),
9895
)
9996
break
100-
if (
101-
not hasattr(request, 'domain_object') and
102-
'HTTP_X_RTD_SLUG' in request.META
103-
):
97+
if (not hasattr(request, 'domain_object') and
98+
'HTTP_X_RTD_SLUG' in request.META):
10499
request.slug = request.META['HTTP_X_RTD_SLUG'].lower()
105100
request.urlconf = SUBDOMAIN_URLCONF
106101
request.rtdheader = True
@@ -253,25 +248,23 @@ class FooterNoSessionMiddleware(SessionMiddleware):
253248
"""
254249

255250
IGNORE_URLS = [
256-
'/api/v2/footer_html', '/sustainability/view', '/sustainability/click',
251+
'/api/v2/footer_html',
252+
'/sustainability/view',
253+
'/sustainability/click',
257254
]
258255

259256
def process_request(self, request):
260257
for url in self.IGNORE_URLS:
261-
if (
262-
request.path_info.startswith(url) and
263-
settings.SESSION_COOKIE_NAME not in request.COOKIES
264-
):
258+
if (request.path_info.startswith(url) and
259+
settings.SESSION_COOKIE_NAME not in request.COOKIES):
265260
# Hack request.session otherwise the Authentication middleware complains.
266261
request.session = {}
267262
return
268263
super().process_request(request)
269264

270265
def process_response(self, request, response):
271266
for url in self.IGNORE_URLS:
272-
if (
273-
request.path_info.startswith(url) and
274-
settings.SESSION_COOKIE_NAME not in request.COOKIES
275-
):
267+
if (request.path_info.startswith(url) and
268+
settings.SESSION_COOKIE_NAME not in request.COOKIES):
276269
return response
277270
return super().process_response(request, response)

readthedocs/core/symlink.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def symlink_cnames(self, domain=None):
152152
if domain:
153153
domains = [domain]
154154
else:
155-
domains = Domain.objects.filter(project=self.project).values_list('domain', flat=True)
155+
domains = Domain.objects.filter(project=self.project
156+
).values_list('domain', flat=True)
156157
for dom in domains:
157158
log_msg = 'Symlinking CNAME: {} -> {}'.format(
158159
dom,
@@ -191,11 +192,8 @@ def remove_symlink_cname(self, domain):
191192
"""
192193
log_msg = 'Removing symlink for CNAME {}'.format(domain)
193194
log.info(
194-
constants.LOG_TEMPLATE.format(
195-
project=self.project.slug,
196-
version='',
197-
msg=log_msg
198-
),
195+
constants.LOG_TEMPLATE
196+
.format(project=self.project.slug, version='', msg=log_msg),
199197
)
200198
symlink = os.path.join(self.CNAME_ROOT, domain)
201199
safe_unlink(symlink)

readthedocs/core/views/hooks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def github_build(request): # noqa: D205
205205
else:
206206
data = json.loads(request.body)
207207
http_url = data['repository']['url']
208-
http_search_url = http_url.replace('http://', '').replace('https://', '')
208+
http_search_url = http_url.replace('http://',
209+
'').replace('https://', '')
209210
ssh_url = data['repository']['ssh_url']
210211
ssh_search_url = ssh_url.replace('git@', '').replace('.git', '')
211212
branches = [data['ref'].replace('refs/heads/', '')]
@@ -300,7 +301,9 @@ def bitbucket_build(request):
300301
else:
301302
data = json.loads(request.body)
302303

303-
version = 2 if request.META.get('HTTP_USER_AGENT') == 'Bitbucket-Webhooks/2.0' else 1 # yapf: disabled # noqa
304+
version = 2 if request.META.get(
305+
'HTTP_USER_AGENT'
306+
) == 'Bitbucket-Webhooks/2.0' else 1 # yapf: disabled # noqa
304307
if version == 1:
305308
branches = [
306309
commit.get('branch', '') for commit in data['commits']

0 commit comments

Comments
 (0)