Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: correctly remove Search.init on Sphinx >= 5.0 #100

Merged
merged 4 commits into from Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion .circleci/config.yml
Expand Up @@ -8,7 +8,7 @@ commands:
type: string
sphinx-version:
type: string
default: "21,22,23,24,30,31,32,33,34,latest"
default: "21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,latest"
steps:
- checkout
- run: pip install --user tox
Expand Down Expand Up @@ -48,6 +48,14 @@ jobs:
- run-tox:
version: py39

py310:
docker:
- image: 'cimg/python:3.10'
steps:
- run-tox:
version: py310
sphinx-version: 42,43,44,latest

lint:
docker:
- image: 'cimg/python:3.9'
Expand All @@ -61,6 +69,7 @@ workflows:
tests:
jobs:
- lint
- py310
- py39
- py38
- py37
Expand Down
17 changes: 14 additions & 3 deletions readthedocs_ext/readthedocs.py
Expand Up @@ -237,7 +237,15 @@ def generate_json_artifacts(app, pagename, templatename, context, doctree):


def remove_search_init(app, exception):
"""Remove Sphinx's Search.init() so it can be initialized by Read the Docs."""
"""
Remove Sphinx's Search.init() so it can be initialized by Read the Docs.

RTD needs to call ``Search.init()`` after overriding some of its methods.
We remove the ``Search.init()`` call from Sphinx to avoid calling it twice.

- https://github.com/sphinx-doc/sphinx/blob/799385f5558a888d1a143bf703d06b66d6717fe4/sphinx/themes/basic/static/searchtools.js#L527-L529 # noqa
- https://github.com/sphinx-doc/sphinx/blob/3b01fbe2adf3077cad5c2cf345c6d000d429d7ac/sphinx/themes/basic/static/searchtools.js#L507 # noqa
"""
if exception:
return

Expand All @@ -249,9 +257,12 @@ def remove_search_init(app, exception):
replacement_text = '/* Search initialization removed for Read the Docs */'
replacement_regex = re.compile(
r'''
^\$\(document\).ready\(function\s*\(\)\s*{(?:\n|\r\n?)
^(\$\(document\).ready\(function\s*\(\)\s*{(?:\n|\r\n?)
\s*Search.init\(\);(?:\n|\r\n?)
\}\);
\}\);)
|
# Sphinx >=5.0 calls Search.init this way.
(_ready\(Search.init\);)
''',
Comment on lines +260 to 266
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stsewd it seems you missed this comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the docstring ad92c76

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I missed that :)

(re.MULTILINE | re.VERBOSE)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/pr-example/conf.py
Expand Up @@ -14,7 +14,7 @@
author = 'readthedocs'
version = '0.1'
release = '0.1'
language = None
language = 'en'
exclude_patterns = ['_build']
todo_include_todos = False
html_theme = 'alabaster'
Expand Down
2 changes: 1 addition & 1 deletion tests/pyexample-json/conf.py
Expand Up @@ -15,7 +15,7 @@
author = u'readthedocs'
version = '0.1'
release = '0.1'
language = None
language = 'en'
exclude_patterns = ['_build']
pygments_style = 'sphinx'
todo_include_todos = False
Expand Down
2 changes: 1 addition & 1 deletion tests/pyexample/conf.py
Expand Up @@ -15,7 +15,7 @@
author = u'readthedocs'
version = '0.1'
release = '0.1'
language = None
language = 'en'
exclude_patterns = ['_build']
pygments_style = 'sphinx'
todo_include_todos = False
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
@@ -1,7 +1,8 @@
[tox]
envlist =
py{27,36}-sphinx{15,16,17,18}
py{36,37,38,39}-sphinx{21,22,23,24,30,31,32,33,34,latest}
py{36,37,38,39}-sphinx{21,22,23,24,30,31,32,33,34,35,40,41,42,43,44,latest}
py310-sphinx-{42,43,44,latest}
lint

[testenv]
Expand All @@ -24,7 +25,14 @@ deps =
sphinx32: Sphinx<3.3
sphinx33: Sphinx<3.4
sphinx34: Sphinx<3.5
sphinx35: Sphinx<3.6
sphinx40: Sphinx<4.1
sphinx41: Sphinx<4.2
sphinx42: Sphinx<4.3
sphinx43: Sphinx<4.4
sphinx44: Sphinx<4.5
sphinxlatest: Sphinx
sphinxmaster: git+https://github.com/sphinx-doc/sphinx.git@master
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not running sphinxmaster on circle since it could fail, but it's useful for testing future changes locally.

commands =
py.test {posargs}

Expand Down