Skip to content

[Code scan] Preserve user html_baseurl outside Read the Docs #84

Description

@njzjz

This issue is a result of a Codex global code scan of deepmodeling/deepmodeling_sphinx at commit 156679f.

Problem

rtd_config() is connected for every Sphinx build and assigns config.html_baseurl from READTHEDOCS_CANONICAL_URL with an empty-string default. Outside Read the Docs, this silently overwrites any html_baseurl configured by the project.

Code references:

def rtd_config(app, config):
"""Set RTD configurations.
See https://about.readthedocs.com/blog/2024/07/addons-by-default/
"""
config.html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "")
# Tell Jinja2 templates the build is running on Read the Docs
if os.environ.get("READTHEDOCS", "") == "True":
if "html_context" not in config:
config.html_context = {}
config.html_context["READTHEDOCS"] = True

app.connect("config-inited", rtd_config)
app.connect("config-inited", sphinx_book_theme)

Impact

Local builds and non-RTD CI builds can lose their configured canonical base URL. This can break canonical links, sitemap generation, and any downstream extension that relies on html_baseurl.

Suggested fix

Only assign html_baseurl when READTHEDOCS_CANONICAL_URL is present, or guard the assignment so it only runs under READTHEDOCS=True. Existing project configuration should be preserved otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions