-
Notifications
You must be signed in to change notification settings - Fork 207
Minor documentation about overwriting css files #845
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
Conversation
Just to clarify this is only needed for the case when you want to over-write existing .css files? |
@lucyleeow My intuition is that that is correct. One needs to register a css file for it to be taken into account by sphinx. What I have seen is that if I have the following "_static" directory tree in the source: _static:
- gallery.css
- whatever.txt Then we have the following results given each case: 1html_static_path = ['_static'] Doesn't overwrite gallery.css but copies other files (like one i just named "whatever.txt") . So it seems that some files dont need registration as css does. 2html_static_path = ['_static']
def setup(app):
app.add_css_file('gallery.css') Same as above, copies whatever.txt but does not overwrite gallery.css . Although my intuition is that it SHOULD overwrite the css, it just doesn't ever do. 3html_static_path = ['_static']
def setup(app):
app.connect('builder-inited', lambda app: app.config.html_static_path.append('_static'))
app.add_css_file('gallery.css') Copies whatever.txt and overwrites gallery.css . 4def setup(app):
app.connect('builder-inited', lambda app: app.config.html_static_path.append('_static'))
app.add_css_file('gallery.css') Not doing html_static_path = ['_static'] at the beginning also copies whatever.txt and overwrites the gallery.css . This is expected since after all the lambda function does the append. It seems to me that something happens between the the config initialization and the builder initialization which erases html_static_path or maybe they are not even the same object in those two stages. |
Sorry for the delay, I didn't realise it was only required to overwrite existing files. I'm in 2 minds about it...WDYT @larsoner ? |
Have checked and can confirm #845 (comment) is all correct. I am inclined to add this to the documentation or at least amend our documentation as the following line is a bit misleading:
@larsoner can you confirm if the above is true, and thus sphinx just doesn't seem to copy files over if they already exist? |
I'm not sure whether or not it's true, I would confirm via trial and error using our |
Sorry for the delay. From some digging, it seems that the sphinx gallery files are copied over AFTER paths listed in the user's project We append the sphinx gallery static path to sphinx-gallery/sphinx_gallery/gen_gallery.py Line 127 in b176e22
Before this line is run I think Sphinx copies the static files here, looping through the def copy_html_static_files(self, context: Dict) -> None:
def onerror(filename: str, error: Exception) -> None:
logger.warning(__('Failed to copy a file in html_static_file: %s: %r'),
filename, error)
excluded = Matcher(self.config.exclude_patterns + ["**/.*"])
for entry in self.config.html_static_path:
copy_asset(path.join(self.confdir, entry),
path.join(self.outdir, '_static'),
excluded, context=context, renderer=self.templates, onerror=onerror) What the code below does is append
def setup(app):
app.connect('builder-inited', lambda app: app.config.html_static_path.append('_static')) Note that the Further, setting html_static_path = ['_static']
def setup(app):
app.connect('builder-inited', lambda app: app.config.html_static_path.append('_static')) will mean that I think the 'trick' in the solution above is the 'builder-inited' part because while the So it seems that the code above is a bit hacky (?) and maybe we are at fault because there may be a way to append SG's static path earlier - Sphinx
I guess we have 2 options:
WDYT @larsoner ? |
For now if possible let's just tell people not to use our names. Another low effort solution is to make our names more unique for example by adding _sg at the end of the filename before the extension |
Thanks @larsoner Will make those changes in a new PR, probably this weekend. In the mean time I think I will close this PR, it's nice that a solution is documented and searchable, but I think we won't include it in our documentation. (Hope this is okay with everyone, let me know if not) Also I had a quick look and it seems like themes may be added by the config |
Also thanks for your work figuring this out @yjmantilla ! |
@lucyleeow Here is the PR related to #399 . I mentioned that the css file had to be registered through the add_css_file() method.
I also included the recipe from @maartenbreddels , problem with including this is that:
app.html_static_path.append(path_to_my_files);app.add_css_file('gallery.css');
does not work. I have the same problem as @choldgraf .My understanding is that it should work and seems to be the expected behavior since after all it seems what sphinx-gallery does by itself:
https://github.com/sphinx-gallery/sphinx-gallery/blob/master/sphinx_gallery/gen_gallery.py#L350-L355
I'm yet too much of a sphinx newbie to understand this.
The problem with not including the recipe in the documentation is that is a headache for something seemingly simple. Another option is to link the issue rather than including the recipe directly on the documentation.