Skip to content

Commit 0c044b5

Browse files
committed
Merge tag '4.0.2' into rel
2 parents 82b04bb + cca13e0 commit 0c044b5

File tree

9 files changed

+62
-40
lines changed

9 files changed

+62
-40
lines changed

CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 4.0.2
2+
-------------
3+
4+
:Date: March 04, 2020
5+
6+
* `@ericholscher <https://github.com/ericholscher>`__: Don't call virtualenv with `--no-site-packages` (`#6738 <https://github.com/readthedocs/readthedocs.org/pull/6738>`__)
7+
* `@stsewd <https://github.com/stsewd>`__: Catch ConnectionError from request on api timing out (`#6735 <https://github.com/readthedocs/readthedocs.org/pull/6735>`__)
8+
* `@ericholscher <https://github.com/ericholscher>`__: Release 4.0.1 (`#6733 <https://github.com/readthedocs/readthedocs.org/pull/6733>`__)
9+
* `@humitos <https://github.com/humitos>`__: Improve Proxito 404 handler to render user-facing Maze when needed (`#6726 <https://github.com/readthedocs/readthedocs.org/pull/6726>`__)
10+
111
Version 4.0.1
212
-------------
313

readthedocs/doc_builder/backends/sphinx.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from django.conf import settings
1616
from django.template import loader as template_loader
1717
from django.template.loader import render_to_string
18-
from requests.exceptions import Timeout
18+
from requests.exceptions import ConnectionError
1919

2020
from readthedocs.api.v2.client import api
2121
from readthedocs.builds import utils as version_utils
@@ -111,6 +111,9 @@ def get_config_params(self):
111111
gitlab_version_is_editable = (self.version.type == 'branch')
112112
display_gitlab = gitlab_user is not None
113113

114+
versions = []
115+
downloads = []
116+
subproject_urls = []
114117
# Avoid hitting database and API if using Docker build environment
115118
if settings.DONT_HIT_API:
116119
if self.project.has_feature(Feature.ALL_VERSIONS_IN_HTML_CONTEXT):
@@ -120,9 +123,8 @@ def get_config_params(self):
120123
privacy_level=PUBLIC,
121124
)
122125
downloads = self.version.get_downloads(pretty=True)
126+
subproject_urls = self.project.get_subproject_urls()
123127
else:
124-
versions = []
125-
downloads = []
126128
try:
127129
versions = self.project.api_versions()
128130
if not self.project.has_feature(Feature.ALL_VERSIONS_IN_HTML_CONTEXT):
@@ -132,9 +134,10 @@ def get_config_params(self):
132134
if v.privacy_level == PUBLIC
133135
]
134136
downloads = api.version(self.version.pk).get()['downloads']
135-
except Timeout:
137+
subproject_urls = self.project.get_subproject_urls()
138+
except ConnectionError:
136139
log.exception(
137-
'Timeout while fetching versions and downloads for Sphinx context. '
140+
'Timeout while fetching versions/downloads/subproject_urls for Sphinx context. '
138141
'project: %s version: %s',
139142
self.project.slug, self.version.slug,
140143
)
@@ -152,6 +155,7 @@ def get_config_params(self):
152155
'commit': self.project.vcs_repo(self.version.slug).commit,
153156
'versions': versions,
154157
'downloads': downloads,
158+
'subproject_urls': subproject_urls,
155159

156160
# GitHub
157161
'github_user': github_user,

readthedocs/doc_builder/python_environments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def venv_path(self):
290290
return os.path.join(self.project.doc_path, 'envs', self.version.slug)
291291

292292
def setup_base(self):
293-
site_packages = '--no-site-packages'
293+
site_packages = ''
294294
if self.config.python.use_system_site_packages:
295295
site_packages = '--system-site-packages'
296296
env_path = self.venv_path()

readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ context = {
8484
'downloads': [ {% for key, val in downloads.items %}
8585
("{{ key }}", "{{ val }}"),{% endfor %}
8686
],
87-
'subprojects': [ {% for slug, url in project.get_subproject_urls %}
87+
'subprojects': [ {% for slug, url in subproject_urls %}
8888
("{{ slug }}", "{{ url }}"),{% endfor %}
8989
],
9090
'slug': '{{ project.slug }}',

readthedocs/proxito/tests/test_old_redirects.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import django_dynamic_fixture as fixture
1313
import pytest
14+
from django.http import Http404
1415
from django.urls import reverse
1516
from django.test.utils import override_settings
1617

@@ -201,11 +202,11 @@ def test_redirect_prefix_infinite(self):
201202
'http://project.dev.readthedocs.io/en/latest/redirect/',
202203
)
203204

204-
r = self.client.get(
205-
'/en/latest/redirect/',
206-
HTTP_HOST='project.dev.readthedocs.io',
207-
)
208-
self.assertEqual(r.status_code, 404)
205+
with self.assertRaises(Http404):
206+
r = self.client.get(
207+
'/en/latest/redirect/',
208+
HTTP_HOST='project.dev.readthedocs.io',
209+
)
209210

210211

211212
def test_redirect_root(self):
@@ -461,12 +462,12 @@ def test_redirect_html_root_index(self):
461462
)
462463

463464
with override_settings(PYTHON_MEDIA=True):
464-
# File does not exist in storage media
465-
r = self.client.get(
466-
'/en/latest/',
467-
HTTP_HOST='project.dev.readthedocs.io',
468-
)
469-
self.assertEqual(r.status_code, 404)
465+
with self.assertRaises(Http404):
466+
# File does not exist in storage media
467+
r = self.client.get(
468+
'/en/latest/',
469+
HTTP_HOST='project.dev.readthedocs.io',
470+
)
470471

471472
def test_redirect_html_index(self):
472473
fixture.get(
@@ -526,20 +527,12 @@ def test_not_found_page_without_trailing_slash(self):
526527
from_url='/',
527528
)
528529

529-
# Use ``proxito_404_handler`` URL here to emulate the internal redirect
530-
# that happens on NGINX (URL path will be
531-
# http://project.dev.readthedocs.io/_proxito_404_/en/latest/section/file-not-found
532-
# when the view receives it)
533-
r = self.client.get(
534-
reverse(
535-
'proxito_404_handler',
536-
kwargs={
537-
'proxito_path': '/en/latest/section/file-not-found',
538-
}),
539-
HTTP_HOST='project.dev.readthedocs.io',
540-
)
541-
# Avoid infinite redirect
542-
self.assertEqual(r.status_code, 404)
530+
with self.assertRaises(Http404):
531+
# Avoid infinite redirect
532+
r = self.client.get(
533+
'/en/latest/section/file-not-found',
534+
HTTP_HOST='project.dev.readthedocs.io',
535+
)
543536

544537

545538
# FIXME: these tests are valid, but the problem I'm facing is that the request

readthedocs/proxito/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
ServeRobotsTXT,
4343
ServeSitemapXML,
4444
)
45-
from readthedocs.proxito.views.utils import fast_404
45+
from readthedocs.proxito.views.utils import proxito_404_page_handler, fast_404
4646

4747
DOC_PATH_PREFIX = getattr(settings, 'DOC_PATH_PREFIX', '')
4848

@@ -144,5 +144,5 @@
144144
]
145145

146146
# Use Django default error handlers to make things simpler
147-
handler404 = fast_404
147+
handler404 = proxito_404_page_handler
148148
handler500 = defaults.server_error

readthedocs/proxito/views/serve.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,7 @@ def get(self, request, proxito_path, template_name='404.html'):
277277
resp.status_code = 404
278278
return resp
279279

280-
# Finally, return the default 404 page generated by Read the Docs
281-
resp = render(request, template_name)
282-
resp.status_code = 404
283-
return resp
280+
raise Http404('No custom 404 page found.')
284281

285282

286283
class ServeError404(SettingsOverrideObject):

readthedocs/proxito/views/utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33

44
from django.http import HttpResponse
5-
from django.shortcuts import get_object_or_404
5+
from django.shortcuts import get_object_or_404, render
66

77
from .decorators import map_project_slug, map_subproject_slug
88

@@ -19,6 +19,24 @@ def fast_404(request, *args, **kwargs):
1919
return HttpResponse('Not Found.', status=404)
2020

2121

22+
def proxito_404_page_handler(request, exception=None, template_name='404.html'):
23+
"""
24+
Decide what 404 page return depending if it's an internal NGINX redirect.
25+
26+
We want to return fast when the 404 is used as an internal NGINX redirect to
27+
reach our ``ServeError404`` view. However, if the 404 exception was risen
28+
inside ``ServeError404`` view, we want to render the default Read the Docs
29+
Maze page.
30+
"""
31+
32+
if request.resolver_match.url_name != 'proxito_404_handler':
33+
return fast_404(request, exception, template_name)
34+
35+
resp = render(request, template_name)
36+
resp.status_code = 404
37+
return resp
38+
39+
2240
@map_project_slug
2341
@map_subproject_slug
2442
def _get_project_data_from_request(

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = readthedocs
3-
version = 4.0.1
3+
version = 4.0.2
44
license = MIT
55
description = Read the Docs builds and hosts documentation
66
author = Read the Docs, Inc

0 commit comments

Comments
 (0)