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
Changing source_suffix in an extension's setup() function? #2162
Comments
…fix and source_parsers from extension
OK, I had a closer look at https://github.com/sphinx-doc/sphinx/blob/master/sphinx/application.py and found an ugly solution. I still don't understand every detail, so I still hope for a better and less ugly solution! The problem seems to be that in My hackish solution is to manipulate class NotebookParser(...):
...
def setup(app):
source_suffix = app.config._raw_config.get('source_suffix', ['.rst'])
if isinstance(source_suffix, sphinx.config.string_types):
source_suffix = [source_suffix]
if '.ipynb' not in source_suffix:
source_suffix.append('.ipynb')
app.config._raw_config['source_suffix'] = source_suffix
source_parsers = app.config._raw_config.get('source_parsers', {})
if '.ipynb' not in source_parsers and 'ipynb' not in source_parsers:
source_parsers['.ipynb'] = NotebookParser
app.config._raw_config['source_parsers'] = source_parsers A less ugly solution would be highly appreciated! |
…fix and source_parsers from extension
The issue is that extensions (i.e. their We could switch to a two-stage model, initializing all built-in values before, and only doing the newly added ones afterwards. |
I think two stage model is too much solution in this case. Now, both |
@birkenfeld: Thanks for the explanations, now I get it, this totally makes sense! I don't know how much effort a two-stage thing would be, but it would be definitely easier to understand for the user (= me). OTOH, I'm also fine with @tk0miya's PR #2209, which works perfectly for my current case. |
FWIW, I found a different use for a more general solution: My extension also changes Not a biggie, though. |
The source parsers are components for docutils and Sphinx. Of course, setting up config variables by extentions is important, too. But, these are separated issue, I think.
The |
Fix #2162: Add Sphinx.add_source_parser() to add source_suffix and source_parsers from extension
Now, I merged #2209. And then, The extensions are able to add source_parsers using Thanks, |
Thanks a lot! What about the two-stage model that @birkenfeld brought up? |
@mgeier Oh, I missed it. |
done: #2255 |
I'm writing an extension which provides a custom source parser for
*.ipynb
files.I'm trying to append
'.ipynb'
toapp.config.source_suffix
within my extension'ssetup()
function, to make it easier for my users. This way, they don't have to specifysource_suffix
explicitly in theirconf.py
.This worked perfectly until I tried to actually specify
source_suffix
inconf.py
. As soon assource_suffix
is defined there, my appending'.ipynb'
ceases to work, and my*.ipynb
files are not found raising a warning like this:If I remove the assignment to
source_suffix
fromconf.py
, it works again.Any idea what's going wrong here?
Is there anything I can do to make this work?
The text was updated successfully, but these errors were encountered: