Skip to content

Commit e441115

Browse files
authored
Lint: run black against all our Python files (#11145)
1 parent d8a52ae commit e441115

36 files changed

+1875
-1891
lines changed

readthedocs/api/v2/utils.py

+26-40
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def sync_versions_to_db(project, versions, type):
3737
:returns: set of versions' slug added
3838
"""
3939
old_version_values = project.versions.filter(type=type).values_list(
40-
'verbose_name',
41-
'identifier',
40+
"verbose_name",
41+
"identifier",
4242
)
4343
old_versions = dict(old_version_values)
4444

@@ -48,8 +48,8 @@ def sync_versions_to_db(project, versions, type):
4848
has_user_stable = False
4949
has_user_latest = False
5050
for version in versions:
51-
version_id = version['identifier']
52-
version_name = version['verbose_name']
51+
version_id = version["identifier"]
52+
version_name = version["verbose_name"]
5353
if version_name == STABLE_VERBOSE_NAME:
5454
has_user_stable = True
5555
created_version, created = _set_or_create_version(
@@ -90,7 +90,7 @@ def sync_versions_to_db(project, versions, type):
9090
)
9191

9292
log.info(
93-
'Re-syncing versions: version updated.',
93+
"Re-syncing versions: version updated.",
9494
version_verbose_name=version_name,
9595
version_id=version_id,
9696
)
@@ -101,26 +101,22 @@ def sync_versions_to_db(project, versions, type):
101101
added.update(_create_versions(project, type, versions_to_create))
102102

103103
if not has_user_stable:
104-
stable_version = (
105-
project.versions.filter(slug=STABLE, type=type).first()
106-
)
104+
stable_version = project.versions.filter(slug=STABLE, type=type).first()
107105
if stable_version:
108106
# Put back the RTD's stable version
109107
stable_version.machine = True
110108
stable_version.save()
111109
if not has_user_latest:
112-
latest_version = (
113-
project.versions.filter(slug=LATEST, type=type).first()
114-
)
110+
latest_version = project.versions.filter(slug=LATEST, type=type).first()
115111
if latest_version:
116112
# Put back the RTD's latest version
117113
latest_version.machine = True
118114
latest_version.save()
119115
if added:
120116
log.info(
121-
'Re-syncing versions: versions added.',
117+
"Re-syncing versions: versions added.",
122118
count=len(added),
123-
versions=','.join(itertools.islice(added, 100)),
119+
versions=",".join(itertools.islice(added, 100)),
124120
)
125121
return added
126122

@@ -174,14 +170,8 @@ def _set_or_create_version(project, slug, version_id, verbose_name, type_):
174170
def _get_deleted_versions_qs(project, tags_data, branches_data):
175171
# We use verbose_name for tags
176172
# because several tags can point to the same identifier.
177-
versions_tags = [
178-
version['verbose_name']
179-
for version in tags_data
180-
]
181-
versions_branches = [
182-
version['identifier']
183-
for version in branches_data
184-
]
173+
versions_tags = [version["verbose_name"] for version in tags_data]
174+
versions_branches = [version["identifier"] for version in branches_data]
185175

186176
to_delete_qs = (
187177
project.versions(manager=INTERNAL)
@@ -206,32 +196,28 @@ def delete_versions_from_db(project, tags_data, branches_data):
206196
207197
:returns: The slug of the deleted versions from the database.
208198
"""
209-
to_delete_qs = (
210-
_get_deleted_versions_qs(
211-
project=project,
212-
tags_data=tags_data,
213-
branches_data=branches_data,
214-
)
215-
.exclude(active=True)
216-
)
199+
to_delete_qs = _get_deleted_versions_qs(
200+
project=project,
201+
tags_data=tags_data,
202+
branches_data=branches_data,
203+
).exclude(active=True)
217204
_, deleted = to_delete_qs.delete()
218-
versions_count = deleted.get('builds.Version', 0)
205+
versions_count = deleted.get("builds.Version", 0)
219206
log.info(
220-
'Re-syncing versions: versions deleted.', project_slug=project.slug, count=versions_count,
207+
"Re-syncing versions: versions deleted.",
208+
project_slug=project.slug,
209+
count=versions_count,
221210
)
222211

223212

224213
def get_deleted_active_versions(project, tags_data, branches_data):
225214
"""Return the slug of active versions that were deleted from the repository."""
226-
to_delete_qs = (
227-
_get_deleted_versions_qs(
228-
project=project,
229-
tags_data=tags_data,
230-
branches_data=branches_data,
231-
)
232-
.filter(active=True)
233-
)
234-
return set(to_delete_qs.values_list('slug', flat=True))
215+
to_delete_qs = _get_deleted_versions_qs(
216+
project=project,
217+
tags_data=tags_data,
218+
branches_data=branches_data,
219+
).filter(active=True)
220+
return set(to_delete_qs.values_list("slug", flat=True))
235221

236222

237223
def run_automation_rules(project, added_versions, deleted_active_versions):

readthedocs/api/v2/views/footer_views.py

+40-46
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ def get_version_compare_data(project, base_version=None, user=None):
3434
:param base_version: We assert whether or not the base_version is also the
3535
highest version in the resulting "is_highest" value.
3636
"""
37-
if (
38-
not project.show_version_warning or
39-
(base_version and base_version.is_external)
40-
):
41-
return {'is_highest': False}
37+
if not project.show_version_warning or (base_version and base_version.is_external):
38+
return {"is_highest": False}
4239

4340
versions_qs = Version.internal.public(project=project, user=user).filter(
4441
built=True, active=True
@@ -49,21 +46,21 @@ def get_version_compare_data(project, base_version=None, user=None):
4946
versions_qs = versions_qs.filter(type=TAG)
5047

5148
# Optimization
52-
versions_qs = versions_qs.select_related('project')
49+
versions_qs = versions_qs.select_related("project")
5350

5451
highest_version_obj, highest_version_comparable = highest_version(
5552
versions_qs,
5653
)
5754
ret_val = {
58-
'project': str(highest_version_obj),
59-
'version': str(highest_version_comparable),
60-
'is_highest': True,
55+
"project": str(highest_version_obj),
56+
"version": str(highest_version_comparable),
57+
"is_highest": True,
6158
}
6259
if highest_version_obj:
6360
# Never link to the dashboard,
6461
# users reading the docs may don't have access to the dashboard.
65-
ret_val['url'] = highest_version_obj.get_absolute_url()
66-
ret_val['slug'] = highest_version_obj.slug
62+
ret_val["url"] = highest_version_obj.get_absolute_url()
63+
ret_val["slug"] = highest_version_obj.slug
6764
if base_version and base_version.slug != LATEST:
6865
try:
6966
base_version_comparable = parse_version_failsafe(
@@ -72,13 +69,13 @@ def get_version_compare_data(project, base_version=None, user=None):
7269
if base_version_comparable:
7370
# This is only place where is_highest can get set. All error
7471
# cases will be set to True, for non- standard versions.
75-
ret_val['is_highest'] = (
72+
ret_val["is_highest"] = (
7673
base_version_comparable >= highest_version_comparable
7774
)
7875
else:
79-
ret_val['is_highest'] = True
76+
ret_val["is_highest"] = True
8077
except (Version.DoesNotExist, TypeError):
81-
ret_val['is_highest'] = True
78+
ret_val["is_highest"] = True
8279
return ret_val
8380

8481

@@ -105,24 +102,24 @@ class BaseFooterHTML(CDNCacheTagsMixin, APIView):
105102
are called many times, so a basic cache is implemented.
106103
"""
107104

108-
http_method_names = ['get']
105+
http_method_names = ["get"]
109106
permission_classes = [IsAuthorizedToViewVersion]
110107
renderer_classes = [JSONRenderer, JSONPRenderer]
111-
project_cache_tag = 'rtd-footer'
108+
project_cache_tag = "rtd-footer"
112109

113110
@lru_cache(maxsize=1)
114111
def _get_project(self):
115-
project_slug = self.request.GET.get('project', None)
112+
project_slug = self.request.GET.get("project", None)
116113
project = get_object_or_404(Project, slug=project_slug)
117114
return project
118115

119116
@lru_cache(maxsize=1)
120117
def _get_version(self):
121-
version_slug = self.request.GET.get('version', None)
118+
version_slug = self.request.GET.get("version", None)
122119

123120
# Hack in a fix for missing version slug deploy
124121
# that went out a while back
125-
if version_slug == '':
122+
if version_slug == "":
126123
version_slug = LATEST
127124

128125
project = self._get_project()
@@ -142,23 +139,23 @@ def _get_active_versions_sorted(self):
142139
return versions
143140

144141
def _get_context(self):
145-
theme = self.request.GET.get('theme', False)
146-
docroot = self.request.GET.get('docroot', '')
147-
source_suffix = self.request.GET.get('source_suffix', '.rst')
142+
theme = self.request.GET.get("theme", False)
143+
docroot = self.request.GET.get("docroot", "")
144+
source_suffix = self.request.GET.get("source_suffix", ".rst")
148145

149-
new_theme = (theme == 'sphinx_rtd_theme')
146+
new_theme = theme == "sphinx_rtd_theme"
150147

151148
project = self._get_project()
152149
main_project = project.main_language_project or project
153150
version = self._get_version()
154151

155-
page_slug = self.request.GET.get('page', '')
156-
path = ''
157-
if page_slug and page_slug != 'index':
152+
page_slug = self.request.GET.get("page", "")
153+
path = ""
154+
if page_slug and page_slug != "index":
158155
if version.documentation_type in {SPHINX_HTMLDIR, MKDOCS}:
159-
path = re.sub('/index$', '', page_slug) + '/'
156+
path = re.sub("/index$", "", page_slug) + "/"
160157
else:
161-
path = page_slug + '.html'
158+
path = page_slug + ".html"
162159

163160
context = {
164161
"project": project,
@@ -176,27 +173,27 @@ def _get_context(self):
176173
docroot,
177174
page_slug,
178175
source_suffix,
179-
'edit',
176+
"edit",
180177
),
181-
'github_view_url': version.get_github_url(
178+
"github_view_url": version.get_github_url(
182179
docroot,
183180
page_slug,
184181
source_suffix,
185-
'view',
182+
"view",
186183
),
187-
'gitlab_edit_url': version.get_gitlab_url(
184+
"gitlab_edit_url": version.get_gitlab_url(
188185
docroot,
189186
page_slug,
190187
source_suffix,
191-
'edit',
188+
"edit",
192189
),
193-
'gitlab_view_url': version.get_gitlab_url(
190+
"gitlab_view_url": version.get_gitlab_url(
194191
docroot,
195192
page_slug,
196193
source_suffix,
197-
'view',
194+
"view",
198195
),
199-
'bitbucket_url': version.get_bitbucket_url(
196+
"bitbucket_url": version.get_bitbucket_url(
200197
docroot,
201198
page_slug,
202199
source_suffix,
@@ -214,22 +211,19 @@ def get(self, request, format=None):
214211
)
215212

216213
context = self._get_context()
217-
html = template_loader.get_template('restapi/footer.html').render(
214+
html = template_loader.get_template("restapi/footer.html").render(
218215
context,
219216
request,
220217
)
221218

222-
show_version_warning = (
223-
project.show_version_warning and
224-
not version.is_external
225-
)
219+
show_version_warning = project.show_version_warning and not version.is_external
226220

227221
resp_data = {
228-
'html': html,
229-
'show_version_warning': show_version_warning,
230-
'version_active': version.active,
231-
'version_compare': version_compare_data,
232-
'version_supported': version.supported,
222+
"html": html,
223+
"show_version_warning": show_version_warning,
224+
"version_active": version.active,
225+
"version_compare": version_compare_data,
226+
"version_supported": version.supported,
233227
}
234228

235229
return Response(resp_data)

0 commit comments

Comments
 (0)