Skip to content

Commit 8b7c279

Browse files
humitosagjohnson
authored andcommitted
Upgrade all packages using pur (#4318)
* Upgrade all packages using pur for reqs in `ls requirements`; do pur --skip django-tastypie,django,docker,elasticsearch,pyelasticsearch,commonmark,stripe,djangorestframework,mkdocs,django-allauth,django-filter,mercurial --requirement requirements/$reqs; done * Run lint with Python 3.6 * Downgrade gitpython to 2.1.10 * Linting error fixed * Upgrade common Branch: readthedocs/common#17 * Remove old note for testing * Add note for django-filter * no-else-return fixed in all the files Some block needed to be re-idented to fulfill this check. Basically, if you have a "if something: return another" the "else" clause is not needed since it will be the common case for the flow to continue if the condition is not met. * Only # noqa comment * Note about gitpython
1 parent ef6a059 commit 8b7c279

File tree

22 files changed

+143
-113
lines changed

22 files changed

+143
-113
lines changed

readthedocs/builds/models.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ def get_github_url(
286286

287287
if not docroot:
288288
return ''
289-
else:
290-
if docroot[0] != '/':
291-
docroot = '/{}'.format(docroot)
292-
if docroot[-1] != '/':
293-
docroot = '{}/'.format(docroot)
289+
290+
if docroot[0] != '/':
291+
docroot = '/{}'.format(docroot)
292+
if docroot[-1] != '/':
293+
docroot = '{}/'.format(docroot)
294294

295295
if action == 'view':
296296
action_string = 'blob'
@@ -320,11 +320,11 @@ def get_gitlab_url(
320320

321321
if not docroot:
322322
return ''
323-
else:
324-
if docroot[0] != '/':
325-
docroot = '/{}'.format(docroot)
326-
if docroot[-1] != '/':
327-
docroot = '{}/'.format(docroot)
323+
324+
if docroot[0] != '/':
325+
docroot = '/{}'.format(docroot)
326+
if docroot[-1] != '/':
327+
docroot = '{}/'.format(docroot)
328328

329329
if action == 'view':
330330
action_string = 'blob'

readthedocs/core/resolver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ def resolve_domain(self, project, private=None):
132132
domain = self._get_project_custom_domain(canonical_project)
133133
if domain:
134134
return domain.domain
135-
elif self._use_subdomain():
135+
136+
if self._use_subdomain():
136137
return self._get_project_subdomain(canonical_project)
138+
137139
return getattr(settings, 'PRODUCTION_DOMAIN')
138140

139141
def resolve(self, project, require_https=False, filename='', private=None,

readthedocs/core/views/hooks.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ def _build_version(project, slug, already_built=()):
5252
log.info("(Version build) Building %s:%s",
5353
project.slug, slug_version.slug)
5454
return LATEST
55-
elif project.versions.exclude(active=True).filter(slug=slug).exists():
55+
56+
if project.versions.exclude(active=True).filter(slug=slug).exists():
5657
log.info("(Version build) Not Building %s", slug)
5758
return None
58-
elif slug not in already_built:
59+
60+
if slug not in already_built:
5961
version = project.versions.get(slug=slug)
6062
trigger_build(project=project, version=version, force=True)
6163
log.info("(Version build) Building %s:%s",
6264
project.slug, version.slug)
6365
return slug
64-
else:
65-
log.info("(Version build) Not Building %s", slug)
66-
return None
66+
67+
log.info("(Version build) Not Building %s", slug)
68+
return None
6769

6870

6971
def build_branches(project, branch_list):
@@ -305,16 +307,19 @@ def bitbucket_build(request):
305307
branches,
306308
)
307309
log.debug('Bitbucket webhook payload:\n\n%s\n\n', data)
310+
308311
projects = get_project_from_url(search_url)
309312
if projects and branches:
310313
return _build_url(search_url, projects, branches)
311-
elif not branches:
314+
315+
if not branches:
312316
log.error(
313317
'Commit/branch not found url=%s branches=%s',
314318
search_url,
315319
branches,
316320
)
317321
return HttpResponseNotFound('Commit/branch not found')
322+
318323
log.info('Project match not found: url=%s', search_url)
319324
return HttpResponseNotFound('Project match not found')
320325
return HttpResponse('Method not allowed, POST is required', status=405)

readthedocs/core/views/serve.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,23 @@ def _serve_file(request, filename, basepath):
125125
if settings.DEBUG or getattr(settings, 'PYTHON_MEDIA', False):
126126
# Serve from Python
127127
return serve(request, filename, basepath)
128-
else:
129-
# Serve from Nginx
130-
content_type, encoding = mimetypes.guess_type(
131-
os.path.join(basepath, filename))
132-
content_type = content_type or 'application/octet-stream'
133-
response = HttpResponse(content_type=content_type)
134-
if encoding:
135-
response['Content-Encoding'] = encoding
136-
try:
137-
response['X-Accel-Redirect'] = os.path.join(
138-
basepath[len(settings.SITE_ROOT):],
139-
filename,
140-
)
141-
except UnicodeEncodeError:
142-
raise Http404
143-
144-
return response
128+
129+
# Serve from Nginx
130+
content_type, encoding = mimetypes.guess_type(
131+
os.path.join(basepath, filename))
132+
content_type = content_type or 'application/octet-stream'
133+
response = HttpResponse(content_type=content_type)
134+
if encoding:
135+
response['Content-Encoding'] = encoding
136+
try:
137+
response['X-Accel-Redirect'] = os.path.join(
138+
basepath[len(settings.SITE_ROOT):],
139+
filename,
140+
)
141+
except UnicodeEncodeError:
142+
raise Http404
143+
144+
return response
145145

146146

147147
@map_project_slug
@@ -200,8 +200,8 @@ def _serve_symlink_docs(request, project, privacy_level, filename=''):
200200
basepath = public_symlink.project_root
201201
if os.path.exists(os.path.join(basepath, filename)):
202202
return _serve_file(request, filename, basepath)
203-
else:
204-
files_tried.append(os.path.join(basepath, filename))
203+
204+
files_tried.append(os.path.join(basepath, filename))
205205

206206
if (settings.DEBUG or constants.PRIVATE in serve_docs) and privacy_level == constants.PRIVATE: # yapf: disable # noqa
207207
# Handle private
@@ -210,8 +210,8 @@ def _serve_symlink_docs(request, project, privacy_level, filename=''):
210210

211211
if os.path.exists(os.path.join(basepath, filename)):
212212
return _serve_file(request, filename, basepath)
213-
else:
214-
files_tried.append(os.path.join(basepath, filename))
213+
214+
files_tried.append(os.path.join(basepath, filename))
215215

216216
raise Http404(
217217
'File not found. Tried these files: %s' % ','.join(files_tried))

readthedocs/doc_builder/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def create_index(self, extension='md', **__):
104104
docs_dir, 'README.{ext}'.format(ext=extension))
105105
if os.path.exists(readme_filename):
106106
return 'README'
107-
else:
108-
index_file = open(index_filename, 'w+')
109-
index_text = """
107+
108+
index_file = open(index_filename, 'w+')
109+
index_text = """
110110
111111
Welcome to Read the Docs
112112
------------------------
@@ -122,8 +122,8 @@ def create_index(self, extension='md', **__):
122122
familiar with Read the Docs.
123123
"""
124124

125-
index_file.write(index_text.format(dir=docs_dir, ext=extension))
126-
index_file.close()
125+
index_file.write(index_text.format(dir=docs_dir, ext=extension))
126+
index_file.close()
127127
return 'index'
128128

129129
def run(self, *args, **kwargs):

readthedocs/doc_builder/environments.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ def container_id(self):
872872
"""Return id of container if it is valid."""
873873
if self.container_name:
874874
return self.container_name
875-
elif self.container:
875+
876+
if self.container:
876877
return self.container.get('Id')
877878

878879
def container_state(self):

readthedocs/gold/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ def clean(self):
9292
cleaned_data = super(GoldProjectForm, self).clean()
9393
if self.projects.count() < self.user.num_supported_projects:
9494
return cleaned_data
95-
else:
96-
self.add_error(None, 'You already have the max number of supported projects.')
95+
96+
self.add_error(None, 'You already have the max number of supported projects.')

readthedocs/notifications/notification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def get_template_names(self, backend_name, source_format=constants.HTML):
6969
source_format=source_format,
7070
))
7171
return names
72-
else:
73-
raise AttributeError()
72+
73+
raise AttributeError()
7474

7575
def render(self, backend_name, source_format=constants.HTML):
7676
return render_to_string(

readthedocs/oauth/services/bitbucket.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def create_repository(self, fields, privacy=None, organization=None):
111111
log.debug('Not importing %s because mismatched orgs',
112112
fields['name'])
113113
return None
114-
else:
115-
repo.organization = organization
114+
115+
repo.organization = organization
116116
repo.users.add(self.user)
117117
repo.name = fields['name']
118118
repo.description = fields['description']
@@ -141,9 +141,11 @@ def create_repository(self, fields, privacy=None, organization=None):
141141
repo.json = json.dumps(fields)
142142
repo.save()
143143
return repo
144-
else:
145-
log.debug('Not importing %s because mismatched type',
146-
fields['name'])
144+
145+
log.debug(
146+
'Not importing %s because mismatched type',
147+
fields['name'],
148+
)
147149

148150
def create_organization(self, fields):
149151
"""

readthedocs/oauth/services/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def create_repository(self, fields, privacy=None, organization=None):
9696
log.debug('Not importing %s because mismatched orgs',
9797
fields['name'])
9898
return None
99-
else:
100-
repo.organization = organization
99+
100+
repo.organization = organization
101101
repo.name = fields['name']
102102
repo.description = fields['description']
103103
repo.ssh_url = fields['ssh_url']

readthedocs/oauth/services/gitlab.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ def create_repository(self, fields, privacy=None, organization=None):
161161
fields['name'],
162162
)
163163
return None
164-
else:
165-
repo.organization = organization
166164

165+
repo.organization = organization
167166
repo.name = fields['name']
168167
repo.description = fields['description']
169168
repo.ssh_url = fields['ssh_url_to_repo']

readthedocs/projects/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class ProjectRelationshipBaseForm(forms.ModelForm):
268268

269269
class Meta(object):
270270
model = ProjectRelationship
271-
exclude = []
271+
fields = '__all__'
272272

273273
def __init__(self, *args, **kwargs):
274274
self.project = kwargs.pop('project')
@@ -634,7 +634,7 @@ class DomainForm(forms.ModelForm):
634634

635635
class Meta(object):
636636
model = Domain
637-
exclude = ['machine', 'cname', 'count']
637+
exclude = ['machine', 'cname', 'count'] # pylint: disable=modelform-uses-exclude
638638

639639
def __init__(self, *args, **kwargs):
640640
self.project = kwargs.pop('project', None)
@@ -674,7 +674,7 @@ class IntegrationForm(forms.ModelForm):
674674

675675
class Meta(object):
676676
model = Integration
677-
exclude = ['provider_data', 'exchanges']
677+
exclude = ['provider_data', 'exchanges'] # pylint: disable=modelform-uses-exclude
678678

679679
def __init__(self, *args, **kwargs):
680680
self.project = kwargs.pop('project', None)

readthedocs/projects/models.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ def full_json_path(self, version=LATEST):
535535
"""The path to the build json docs in the project."""
536536
if 'sphinx' in self.documentation_type:
537537
return os.path.join(self.conf_dir(version), '_build', 'json')
538-
elif 'mkdocs' in self.documentation_type:
538+
539+
if 'mkdocs' in self.documentation_type:
539540
return os.path.join(self.checkout_path(version), '_build', 'json')
540541

541542
def full_singlehtml_path(self, version=LATEST):
@@ -555,11 +556,13 @@ def conf_file(self, version=LATEST):
555556
if self.conf_py_file:
556557
conf_path = os.path.join(
557558
self.checkout_path(version), self.conf_py_file,)
559+
558560
if os.path.exists(conf_path):
559561
log.info('Inserting conf.py file path from model')
560562
return conf_path
561-
else:
562-
log.warning("Conf file specified on model doesn't exist")
563+
564+
log.warning("Conf file specified on model doesn't exist")
565+
563566
files = self.find('conf.py', version)
564567
if not files:
565568
files = self.full_find('conf.py', version)

readthedocs/projects/validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def __call__(self, value):
8585
elif self.re_git_user.search(value) or url.scheme in private_schemes:
8686
if allow_private_repos:
8787
return value
88-
else:
89-
# Throw a more helpful error message
90-
raise ValidationError('Manual cloning via SSH is not supported')
88+
89+
# Throw a more helpful error message
90+
raise ValidationError('Manual cloning via SSH is not supported')
9191

9292
# No more valid URLs without supported URL schemes
9393
raise ValidationError(_('Invalid scheme for URL'))

readthedocs/projects/version_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def prune_point(self, num_latest):
7474
try:
7575
self._state[major][minor] = sorted(
7676
set(self._state[major][minor]))[-num_latest:]
77-
except TypeError:
77+
except TypeError: # pylint: disable=try-except-raise
7878
# Raise these for now.
7979
raise
8080

readthedocs/projects/views/public.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,23 @@ def project_download_media(request, project_slug, type_, version_slug):
194194
settings.MEDIA_URL, type_, project_slug, version_slug,
195195
'%s.%s' % (project_slug, type_.replace('htmlzip', 'zip')))
196196
return HttpResponseRedirect(path)
197-
else:
198-
# Get relative media path
199-
path = (
200-
version.project.get_production_media_path(
201-
type_=type_, version_slug=version_slug)
202-
.replace(settings.PRODUCTION_ROOT, '/prod_artifacts'))
203-
content_type, encoding = mimetypes.guess_type(path)
204-
content_type = content_type or 'application/octet-stream'
205-
response = HttpResponse(content_type=content_type)
206-
if encoding:
207-
response['Content-Encoding'] = encoding
208-
response['X-Accel-Redirect'] = path
209-
# Include version in filename; this fixes a long-standing bug
210-
filename = '%s-%s.%s' % (
211-
project_slug, version_slug, path.split('.')[-1])
212-
response['Content-Disposition'] = 'filename=%s' % filename
213-
return response
197+
198+
# Get relative media path
199+
path = (
200+
version.project.get_production_media_path(
201+
type_=type_, version_slug=version_slug)
202+
.replace(settings.PRODUCTION_ROOT, '/prod_artifacts'))
203+
content_type, encoding = mimetypes.guess_type(path)
204+
content_type = content_type or 'application/octet-stream'
205+
response = HttpResponse(content_type=content_type)
206+
if encoding:
207+
response['Content-Encoding'] = encoding
208+
response['X-Accel-Redirect'] = path
209+
# Include version in filename; this fixes a long-standing bug
210+
filename = '%s-%s.%s' % (
211+
project_slug, version_slug, path.split('.')[-1])
212+
response['Content-Disposition'] = 'filename=%s' % filename
213+
return response
214214

215215

216216
def elastic_project_search(request, project_slug):

readthedocs/vcs_support/backends/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def parse_branches(self, data):
171171
delimiter = str(' ').encode('utf-8') if PY2 else str(' ')
172172
raw_branches = csv.reader(StringIO(data), delimiter=delimiter)
173173
for branch in raw_branches:
174-
branch = [f for f in branch if f != '' and f != '*']
174+
branch = [f for f in branch if f not in ('', '*')]
175175
# Handle empty branches
176176
if branch:
177177
branch = branch[0]

readthedocs/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# This application object is used by any WSGI server configured to use this
99
# file. This includes Django's development server, if the WSGI_APPLICATION
1010
# setting points here.
11-
from django.core.wsgi import get_wsgi_application # pylint: disable=wrong-import-position
11+
from django.core.wsgi import get_wsgi_application # noqa
1212
application = get_wsgi_application()
1313

1414
# Apply WSGI middleware here.

0 commit comments

Comments
 (0)