Skip to content

add_css_file return wrong URI when dealing with local files on windows platform #12399

Open
@12rambau

Description

@12rambau

Describe the bug

I'm copying some css and js files from my local lib. Everything works fine with my Linux build but it fails when trying to make it run on windows platform.

How to Reproduce

the failing test are part of the sphinx-contrib/icon repository. The latest build can be found here: https://github.com/sphinx-contrib/icon/actions/runs/9315532969/job/25641896049?pr=33

In short my lib is adding few css and js to the app like this:

def setup(app: Sphinx) -> Dict[str, Any]:
    """Add icon node to the sphinx builder."""
    # load the icon node/role
    app.add_node(icon_node, **_NODE_VISITORS)  # type: ignore
    app.add_role("icon", Icon())

    # load the font
    font_handler = Fontawesome()

    # install html related files
    app.add_css_file(str(font_handler.css_file.resolve()))
    app.add_js_file(str(font_handler.js_file.resolve()))

    # install latex files
    app.add_latex_package("fontspec")
    app.connect("config-inited", font_handler.add_latex_font)
    app.connect("config-inited", font_handler.enforce_xelatex)
    app.connect("builder-inited", font_handler.add_latex_font_files)

    return {
        "version": __version__,
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }

And the error I get when the build runs on windows is the following:

 OSError: [Errno 22] Invalid argument: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\pytest-of-runneradmin\\pytest-0\\fa6-icon\\_build\\html\\_static\\D:\\a\\icon\\icon\\sphinxcontrib\\icon\\node_modules\\@fortawesome\\fontawesome-free\\css\\all.min.css'

My guess is that add_css_file is not catching windows based absolute path the D: should not be here.

Environment Information

I don't own a windows machine myself so the report i'm sending is the one from a linux based codespace. I think it won't be relevant:

Platform:              linux; (Linux-6.5.0-1021-azure-x86_64-with-glibc2.31)
Python version:        3.10.13 (main, May 14 2024, 22:40:16) [GCC 9.4.0])
Python implementation: CPython
Sphinx version:        7.3.7
Docutils version:      0.21.2
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

[sphinxcontrib.icon]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions