Skip to content

[Code scan] Copy dark_rtd.css when it is registered with sphinx_rtd_theme #83

Description

@njzjz

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

Problem

When enable_deepmodeling = False and html_theme = "sphinx_rtd_theme", the extension still registers dark_rtd.css, but copy_custom_files() returns before copying package assets. The generated HTML can reference _static/dark_rtd.css even though the file is absent.

Code references:

def copy_custom_files(app):
if not app.config.enable_deepmodeling:
return
if app.builder.format == "html":
staticdir = os.path.join(app.builder.outdir, "_static")
cwd = Path(__file__).parent.absolute()
banner_css = cwd / "banner.css"
banner_js = cwd / "banner.js"
dark_css = cwd / "dark_rtd.css"
os.makedirs(staticdir, exist_ok=True)
staticdir = os.path.join(app.builder.outdir, "_static")
copy_asset_file(str(banner_css), staticdir)
copy_asset_file(str(banner_js), staticdir)
copy_asset_file(str(dark_css), staticdir)

def enable_dark_mode(app, config):
"""Enable dark mode if the theme is sphinx_rtd_theme."""
if config.html_theme == "sphinx_rtd_theme":
app.add_css_file("dark_rtd.css")

Reproduction

Use a minimal Sphinx project with:

extensions = ["deepmodeling_sphinx"]
html_theme = "sphinx_rtd_theme"
enable_deepmodeling = False

The generated page includes _static/dark_rtd.css, but _static/dark_rtd.css is not copied to the output directory.

Impact

Projects that disable DeepModeling-specific banner styling can still emit a broken stylesheet reference when using the RTD theme.

Suggested fix

Either skip app.add_css_file("dark_rtd.css") when enable_deepmodeling is false, or copy dark_rtd.css independently from the banner assets.

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