-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Regression: CSS file added by extension cannot be overridden by users anymore #12096
Comments
Hi @mgeier - I've begun investigating this - can you confirm that what you see is that the relevant CSS files are copied into the build's If so: I think that may provide some hints about what kind of test coverage we'd want to add (ideally something that passes if tested against ae20669, fails currently, and then we can resolve with a fix) |
Thanks for looking into this, @jayaddison!
I think I didn't describe it clearly enough, let me try again: I guess this has something to do with the added checksum, the actual link looks like this: <link rel="stylesheet" type="text/css" href="../_static/nbsphinx-gallery.css?v=c0254da5" /> I don't really know how this checksum stuff works, but it somehow seems to inhibit the overwriting with the user-specified CSS file. |
Let me try to make a more minimal reproducer: Extension
import os
import sphinx
def html_collect_pages(app):
sphinx.util.fileutil.copy_asset(
os.path.join(os.path.dirname(__file__), 'myext_static', 'myext.css'),
os.path.join(app.builder.outdir, '_static'))
return []
def setup(app):
app.connect('html-collect-pages', html_collect_pages)
app.add_css_file('myext.css')
h1 { color: red; } User's Project
h1 { color: green; }
extensions = ['myext']
html_static_path = ['user_static']
Hello
===== Expected BehaviorThe title is green, because the user overrides the extension's CSS file. Actual BehaviorStarting with ae20669, the title is red. The user's CSS override is ignored. |
I'm still learning it, but my reading of ae20669 was that one potentially-relevant change is to the event timing (order of operations). Previously static assets were copied at build-finish and since the change they are copied at an early preparation phase. From the minimal repro you provided (thank you!) I'm wondering whether this has caused the |
I'm taking a break for a while but my next step would be to add your minimal repro as a test case in our |
None of this is urgent, so please take your time! But I think you are on the right track: this change in def builder_inited(app):
sphinx.util.fileutil.copy_asset(
os.path.join(os.path.dirname(__file__), 'myext_static', 'myext.css'),
os.path.join(app.builder.outdir, '_static'))
def setup(app):
app.connect('builder-inited', builder_inited)
app.add_css_file('myext.css') However, I think this is too early for my extension to know which CSS files should be copied. |
This may or may not be related: with the sphinx.git $ pip install pytest==8.1.1
sphinx.git $ pip install pytest-randomly==3.15.0
sphinx.git $ pytest --randomly-seed=0 tests/test_theming.py
...
=========================== short test summary info ============================
FAILED tests/test_theming.py::test_dark_style - assert '<link rel="stylesheet" type="text/css" href="_static/pygments.css?v...
========================= 1 failed, 5 passed in 0.64s ========================== |
I would like to know: how can we make it work without breaking 7.2.6? I know that the introduction of checksums had a downstream impact that we did not expect so I would like to reduce as much as possible the risk. |
This may be related: when I override
That causes
I can see convert_overrides() sets
|
@picnixz wrote:
I don't think that the checksums themselves are the problem here, since it does work perfectly fine when I call it in the @jayaddison wrote above (#12096 (comment)) that the timing when assets are copied has also been changed, which might have caused the regression. |
This is indeed a timing issue.
This moved copying assets to after A |
The underlying issue is that as the asset copying has been moved earlier, the extension silently overwrites the files at a now-later step. Perhaps a remedial step would be to add an Would this work for your use-case @mgeier? (as a quick fix you could change your hook to A |
I think it would be best if this could be solved within Sphinx itself. In my case (in However, I think it is quite confusing to extension authors that the But is there a logical argument to why I have the feeling that it should be allowed to be called in any callback (with the same behavior), even in the very last one.
I don't understand how that would help. An extension should never overwrite a file provided by the site author, right? |
#12612 makes this problem more obvious, but does not fully resolve it. We should make overwriting explicit in Sphinx 8. A |
@AA-Turner Thanks for changing the behavior (#12647) and making wrong usage more obvious (#12612)!
For the record, I have moved it into |
Describe the bug
In my concrete case, the CSS file is added with
add_css_file()
in my
nbsphinx
extension: https://github.com/spatialaudio/nbsphinx/blob/53be5e632f0c9483ba65ba6690da9b137f9c1120/src/nbsphinx/__init__.py#L1655How to Reproduce
Check out https://github.com/spatialaudio/nbsphinx/ and add this to
doc/conf.py
:Create a file
my-static-path/nbsphinx-gallery.css
with some CSS overrides, like e.g. in https://github.com/Substra/substra-documentation/blob/d2785aa82d46686d82ab66d2c24f95af86d28ce6/docs/source/static/nbsphinx-gallery.css.Run Sphinx.
Look at one of the thumbnail galleries.
Environment Information
Sphinx extensions
Additional context
This was originally reported here: spatialaudio/nbsphinx#778
I have bisected it, and the culprit is ae20669, which is part of #11415.
The text was updated successfully, but these errors were encountered: