Skip to content

Commit 19cc822

Browse files
authored
do not create 404 page for embedded (e.g. ePub) (readthedocs#231)
* do not create 404 page for embedded (e.g. ePub) * add defusedxml as deps
1 parent cbbdc8e commit 19cc822

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

notfound/extension.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def html_collect_pages(app):
3131
:param app: Sphinx Application
3232
:type app: sphinx.application.Sphinx
3333
"""
34-
if app.config.notfound_pagename in app.env.titles:
35-
# There is already a ``404.rst`` file rendered.
36-
# Skip generating our default one.
34+
if app.builder.embedded or app.config.notfound_pagename in app.env.titles:
35+
# Building embedded (e.g. htmlhelp or ePub) or there is already a ``404.rst``
36+
# file rendered. Skip generating our default one.
3737
return []
3838

3939
return [(

tests/test_urls.py

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def test_404_page_created(app, status, warning):
4646
path = app.outdir / '404.html'
4747
assert path.exists()
4848

49+
@pytest.mark.sphinx('epub', srcdir=srcdir)
50+
def test_404_page_not_created(app, status, warning):
51+
assert app.builder.embedded
52+
app.build()
53+
path = app.outdir / '404.html'
54+
assert not path.exists()
4955

5056
@pytest.mark.sphinx(srcdir=srcdir)
5157
def test_default_settings(app, status, warning):

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ envlist =
1010
deps =
1111
pytest
1212
pdbpp
13+
defusedxml
1314
.
1415
sphinx5: sphinx<6.0
1516
sphinx6: sphinx<7.0

0 commit comments

Comments
 (0)