Skip to content
Snippets Groups Projects
Select Git revision
  • 6aba68a497eb92074fe2d74dcf10bd5ef3893edd
  • main default protected
  • blm_dev_chan
  • release/1.4.0 protected
  • widgets_draw
  • return_of_melodic_demo
  • task_cleanup
  • mixer2
  • dx/fb-save-restore
  • dx/dldldld
  • fpletz/flake
  • dx/jacksense-headset-mic-only
  • release/1.3.0 protected
  • fil3s-limit-filesize
  • allow-reloading-sunmenu
  • wifi-json-error-handling
  • app_text_viewer
  • shoegaze-fps
  • media_has_video_has_audio
  • fil3s-media
  • more-accurate-battery
  • v1.4.0
  • v1.3.0
  • v1.2.0
  • v1.2.0+rc1
  • v1.1.1
  • v1.1.0
  • v1.1.0+rc1
  • v1.0.0
  • v1.0.0+rc6
  • v1.0.0+rc5
  • v1.0.0+rc4
  • v1.0.0+rc3
  • v1.0.0+rc2
  • v1.0.0+rc1
35 results

main.py

Blame
  • eager_only.py 1.67 KiB
    #
    # This is a Sphinx documentation tool extension which makes .only::
    # directives be eagerly processed early in the parsing stage. This
    # makes sure that content in .only:: blocks gets actually excluded
    # as a typical user expects, instead of bits of information in
    # these blocks leaking to documentation in various ways (e.g.,
    # indexes containing entries for functions which are actually in
    # .only:: blocks and thus excluded from documentation, etc.)
    # Note that with this extension, you may need to completely
    # rebuild a doctree when switching builders (i.e. completely
    # remove _build/doctree dir between generation of HTML vs PDF
    # documentation).
    #
    # This extension works by monkey-patching Sphinx core, so potentially
    # may not work with untested Sphinx versions. It tested to work with
    # 1.2.2 and 1.4.2
    #
    # Copyright (c) 2016 Paul Sokolovsky
    # Based on idea by Andrea Cassioli:
    # https://github.com/sphinx-doc/sphinx/issues/2150#issuecomment-171912290
    # Licensed under the terms of BSD license, see LICENSE file.
    #
    import sphinx
    from docutils.parsers.rst import directives
    
    
    class EagerOnly(sphinx.directives.other.Only):
    
        def run(self, *args):
            # Evaluate the condition eagerly, and if false return no nodes right away
            env = self.state.document.settings.env
            env.app.builder.tags.add('TRUE')
            #print(repr(self.arguments[0]))
            if not env.app.builder.tags.eval_condition(self.arguments[0]):
                return []
    
            # Otherwise, do the usual processing
            nodes = super(EagerOnly, self).run()
            if len(nodes) == 1:
                nodes[0]['expr'] = 'TRUE'
            return nodes
    
    
    def setup(app):
        directives.register_directive('only', EagerOnly)