-
-
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
improve only directive #2150
Comments
See also #1911 |
I'm new to sphinx and the main reason I decided it would work for our project was the existence of the But now I see that it throws lots of errors because of not excluding the contents of false Very frustrated at this point and trying to see how to work around this strange limitation. |
I do agree! Funny it is not a very popular issue... |
It is a popular issue, but there have been no pull requests so far. It's also tricky to implement this without a major overhaul.
I think most people generally frown upon using The good news last: It should be possible rewriting the |
I think that, despite it is true that in many cases an extension will do, it is somehow elegant and more portable to rely on standard rst directive and roles. The use of conditionals, and therefore Would you share your patch? |
As I said, 80% done. I'm gonna submit it once it's done, but I cannot make any guarantees right now. (Might be a couple of weeks.) Also, as I said, if you're facing yourself with a situation where you have to use |
Hi,
then I defined a new directive to make sure I am not messing with the standard only. |
andrea, that's a very nice addition, but as I'm new to sphinx, I don't really understand how you hook that into your sphinx. I've read up on how to write a module and how to add directives, but it still doesn't work. How did you do it? |
@andreacassioli : Thanks for making noise and please don't drop the cause, it should be pronounced well that implementation of only:: in Sphinx is SEVERELY BROKEN. I spent a night yesterday unbreaking it for our usecase (which is getting non-existing (i.e. filtered out) stuff also out of genindex and search index). When doing my work, I tried to preserve compatibility with existing usecases of only:: usage, such as generating different content types (i.e. using different builders) on the same cached doctree. Note that from my PoV, that's rather useless usecase, and I have thought that it would be easier to apply only:: processing eagerly (i.e. in a way most people would intuitively expect it to be). I see that you code above does just that. I'm going to test your solution now against mine, as it offers possibility to be added as a sphinx extension (mine requires patching sphinx core, monkey-patching it via extension would be too cumbersome). |
Well, now I remember why I went my way: to make it warning-clean, e.g. avoid stuff like:
(wipy is referenced in only:: chunk). |
Also bunch of:
|
Well, the latter is a result of my monkey-patching implementation. |
Ok, so I put up couple of monkey-patches to unbreak Sphinx' to do the right thing, in the shape of "extensions", so they can be easily used by the users: https://github.com/pfalcon/sphinx_sane_only . Maintainers: please fix the illogical behavior upstream. |
Hi @pfalcon , thanks for the extensive replies! Yes my use case is exactly that of avoiding annoying warning and sometimes errors related to missing files. I also think it is a waist of time compiling code that should not. I see your implementation is very neat!I didn't think to inherit from the original Only class....my monkey patching was wrong as it did not preserver section depth and lead to a bit of a mess. It was OK for my purposes at that time, but then I got into trouble. I do hope your implementation will be integrated upstream. Maybe a PR will be accepted and that will fix the issue at higher level with no need of extension. |
The extension has strong restriction to order of building. |
Yes, that's noted in README. So, I personally don't think it's suitable for mainline - well, not for merging to the core for sure, maybe it would fit sphinx.ext . As I mentioned above, I initially went a different way to resolve the issue - that was not creating index and search index entries immediately, instead store them in the node properties, then have an extra pass after process_only_nodes() to push accumulated data from live nodes into indexes. Obvious drawback of such solution is that it works for indexes (my usecase), but won't work with gazillion of other things people may use only:: with. So, seeing @andreacassioli's solution, I switched to it (as I mentioned, I had an idea that applying only:: filtering early in the parsing is better idea, I just wasn't sure how to do it properly, e.g. if builder is already set up to evaluate only:: expressions early in the parsing stages). |
Ok, so in attempt to make it at least formally mergeable into mainline, I switched names used in a project to not be driven by the frustration with this issue. New repo is https://github.com/pfalcon/sphinx_selective_exclude . It still would be better if this was fixed properly in the core, but if for example nothing changes on that front in next half-year, then maybe including such an extension as a workaround might make sense. |
Thanks @pfalcon and @tk0miya . I think an extension is already a big step forward. The caching issue is critical of course, but I think that a good and sound conditional is important as well. For my purposes, I do not mind loosing caching, as I actually always rebuild all docs. But I see the point. My question is: is there any way to mark a directive to be |
I have posted issues regarding the only directive and always get the reply that what is to me an issue 'it is a specification`.
I do understand that
only
is a bit peculiar, but still it's behavior is very annoying and limiting. Take thi as example: I want to have a caption for a literalinclude that differs depending on the target:Clearly, since I want to link to the block, I need the same name. The result is that using :numref: the link will be recognized as duplicate, and therefore not displayed.
The issue is that nodes in only are processed anyway. No matter on the condition. That is very annoying and in a sense misleading. I think that
1- it should be more clearly described in the docs
2- there should be a way to force the
only
condition to be evaluatedbefore
it's content is parsed, in order to remove it from the very beginning.I know in some cases I can workaround, but it would require fiddling with extensions, which is not very handy and maintainable. Why cannot a proper conditional be introduced?
See also #1717, #1488 and #2143 (comment)
The text was updated successfully, but these errors were encountered: