MRG, MAINT: Split CSS and add control#599
Conversation
|
cc @mgeier see if this would help with what you're trying to do |
Codecov Report
@@ Coverage Diff @@
## master #599 +/- ##
==========================================
- Coverage 97.59% 97.52% -0.07%
==========================================
Files 29 29
Lines 3030 3068 +38
==========================================
+ Hits 2957 2992 +35
- Misses 73 76 +3
Continue to review full report at Codecov.
|
|
Thanks, this is definitely a step in the right direction! It works for my use case when I use this config: extensions = [
'sphinx_gallery.gen_gallery',
]
sphinx_gallery_conf = {
'css': ['gallery'],
'examples_dirs': [],
}However, this does still quite a few things that I don't need. An arguably less complicated way (that also works for me with this PR) would be this: import sphinx_gallery
html_static_path = [sphinx_gallery.glr_path_static()]
html_css_files = ['gallery.css']I think it would be great if we could reduce this even more. extensions = [
'sphinx_gallery.load_style',
]This could be implemented with a reasonably simple sub-module from . import glr_path_static, __version__
def config_inited(app, config):
path = glr_path_static()
if path not in config.html_static_path:
config.html_static_path.append(path)
app.add_css_file('gallery.css')
def setup(app):
app.require_sphinx('1.8')
app.connect('config-inited', config_inited)
return {
'parallel_read_safe': True,
'version': __version__,
}This can of course also be done in a follow-up PR. |
This could be simpler in some cases for people who just want to load the default set of SG styles (or whatever set we make
Even in the case where you want to load SG style(s), we'd still want a way to say which styles to load. To configure that, you'll need to set something in @lucyleeow I'll mark this as MRG and we can get it in. Even if we do eventually want to go a new-sub-extension route at some point, we should do it in another PR since this one already adds stuff that should be useful for folks (and does useful refactoring). |
| for css in gallery_conf['css']: | ||
| if css not in _KNOWN_CSS: | ||
| raise ValueError('Unknown css %r, must be one of %r' | ||
| % (css, known_css)) |
There was a problem hiding this comment.
I guess this should be _KNOWN_CSS.
BTW, those exceptions don't look very nice. If you would use sphinx.errors.ExtensionError, the traceback would be omitted and it would displayed as an "Extension error".
There was a problem hiding this comment.
I'll make a separate issue for that since we have lots of errors in the codebase, we should probably fix them all at once
Yes please! I don't want to delay this PR (apart from my comment above). Once this PR is merged, I will create a new PR with my suggested changes.
Sorry, I haven't been clear.
This would be indeed bad.
This would also be quite bad.
Sure, if you want that, we can do that, see my not-yet-PR 2d65445.
Yes, and that's great! To be more exact, we will have saved people from having to write this: sphinx_gallery_conf = {
'css': ['gallery'],
'examples_dirs': [],
}... and from loading And on top of that, we would have avoided to run quite a huge amount of unneeded code including setting up several unneeded Sphinx hooks (which might not be harmful, but anyway).
Well, yes, that would be the price you as maintainers would have to pay for a great user experience! A taste of the additional code can be seen at 2d65445, but this can probably be reduced by some refactoring (which we can discuss at a later point).
That's of course your (the project maintainers') decision. |
Implements ideas from #317 (comment).
If we decide to go this route (which seems like a useful refactoring) then I can add config instructions.