sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.37k stars 2.08k forks source link

app.add_css_file fails when file is coming from another disk #11860

Closed 12rambau closed 2 months ago

12rambau commented 7 months ago

Describe the bug

I know it's an edge case but I think I find a bug in the add_css_file method. I build a sphinx extention (https://github.com/sphinx-contrib/icon) to create an icon role adding inline fontawesome icons in the text content for various builder. To work I need to add the fontawesome css and js to the build for html and the fonts for latex.

I want to test my extention in a CI pipeline run on github actions. This action creates temporary build folder and perform sanity checks on the outputs using the "sphinx.testing.fixtures".

In this context in a linux environment everything lives in a home/ disk and everything runs as expected. For the Windows build on the other hand the tests are all failing as Sphinx does not resolve the path to css file correctly.

I try to run app.add_css_file(str(css_file)) with css_file being D:\a\icon\icon\sphinxcontrib\icon\node_modules\@fortawesome\fontawesome-free\css\all.min.css but when the html builder tries to resolve the links, he looks for C:/Users/runneradmin/AppData/Local/Temp/pytest-of-runneradmin/pytest-0/fa6-alias-icon/_build/html/_static/D:/a/icon/icon/sphinxcontrib/icon/node_modules/@fortawesome/fontawesome-free/css/all.min.css which of course does not exist. It seems that the changes of disk between the source of the css file and the build destination is not managed for windows machines. Do you have any idea where it could be coming from ?

How to Reproduce

It's such an edge case it's barely possible to reproduce. I cannot even make it on my local machine (as everything is run and build under C://

You can have a look to the test suit code which is very simple (https://github.com/sphinx-doc/sphinx/blob/ea9c61fb38453e8a4798bcb4c5c9ab2972af03ba/sphinx/builders/html/__init__.py#L321)

@pytest.mark.sphinx("html", testroot="fa6-icon")
def test_fa6_icon_html(app, status, warning, file_regression):
    """Build an icon role in HTML."""
    app.builder.build_all()

    html = (app.outdir / "index.html").read_text(encoding="utf8")
    html = BeautifulSoup(html, "html.parser")

    folder = html.select("i.fa-solid")[0].prettify(formatter=fmt)
    file_regression.check(folder, basename="folder_icon", extension=".html")

    pencil = html.select("i.fa-regular")[0].prettify(formatter=fmt)
    file_regression.check(pencil, basename="pencil_icon", extension=".html")

    github = html.select("i.fa-brands")[0].prettify(formatter=fmt)
    file_regression.check(github, basename="github_icon", extension=".html")

In the following build I printed the path that is send to add_css_file: https://github.com/sphinx-contrib/icon/actions/runs/7444814020/job/20251917950

D:\a\icon\icon\sphinxcontrib\icon\node_modules\@fortawesome\fontawesome-free\css\all.min.css

and in this one you will see the call that is made in layout to a non existing file:

C:/Users/runneradmin/AppData/Local/Temp/pytest-of-runneradmin/pytest-0/fa6-alias-icon/_build/html/_static/D:/a/icon/icon/sphinxcontrib/icon/node_modules/@fortawesome/fontawesome-free/css/all.min.css

Environment Information

Platform:              win32; (Windows-10-10.0.20348-SP0)
Python version:        3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.2
Pygments version:      2.17.2

Sphinx extensions

`["sphinxcontrib.icon"]`

Additional context

No response

12rambau commented 2 months ago

superceeded by https://github.com/sphinx-doc/sphinx/issues/12399