Given a Sphinx builder and context with sphinx_app in it,
         generate HTML
978988
def render(self, sphinx_app: Sphinx, context):
        

        # Called from kaybee.plugins.widgets.handlers.render_widgets

        builder: StandaloneHTMLBuilder = sphinx_app.builder
        resource = sphinx_app.env.resources[self.docname]
        context['sphinx_app'] = sphinx_app
        context['widget'] = self
        context['resource'] = resource

        # make_context is optionally implemented on the concrete class
        # for each widget
        self.make_context(context, sphinx_app)

        # NOTE: Can use builder.templates.render_string
        template = self.template + '.html'
        html = builder.templates.render(template, context)
        return html
938515
def browse(ctx):
    """"""
    page_html = Path(ctx.config.sphinx.destdir)/"html"/"index.html"
    if not page_html.exists():
        build(ctx, builder="html")
    assert page_html.exists()
    open_cmd = "open"   # -- WORKS ON: MACOSX
    if sys.platform.startswith("win"):
        open_cmd = "start"
    ctx.run("{open} {page_html}".format(open=open_cmd, page_html=page_html))
1234786
def setup(app):
    """"""
    global _is_sphinx
    _is_sphinx = True
    app.add_config_value('no_underscore_emphasis', False, 'env')
    app.add_config_value('m2r_parse_relative_links', False, 'env')
    app.add_config_value('m2r_anonymous_references', False, 'env')
    app.add_config_value('m2r_disable_inline_math', False, 'env')
    app.add_source_parser('.md', M2RParser)
    app.add_directive('mdinclude', MdInclude)
    metadata = dict(
        version=__version__,
        parallel_read_safe=True,
        parallel_write_safe=True,
    )
    return metadata
1202126
def update_body(app, pagename, templatename, context, doctree):
    

    STATIC_URL = context.get('STATIC_URL', DEFAULT_STATIC_URL)
    online_builders = [
        'readthedocs', 'readthedocsdirhtml', 'readthedocssinglehtml'
    ]
    if app.builder.name == 'readthedocssinglehtmllocalmedia':
        if 'html_theme' in context and context['html_theme'] == 'sphinx_rtd_theme':
            theme_css = '_static/css/theme.css'
        else:
            theme_css = '_static/css/badge_only.css'
    elif app.builder.name in online_builders:
        if 'html_theme' in context and context['html_theme'] == 'sphinx_rtd_theme':
            theme_css = '%scss/sphinx_rtd_theme.css' % STATIC_URL
        else:
            theme_css = '%scss/badge_only.css' % STATIC_URL
    else:
        # Only insert on our HTML builds
        return

    inject_css = True

    # Starting at v0.4.0 of the sphinx theme, the theme CSS should not be injected
    # This decouples the theme CSS (which is versioned independently) from readthedocs.org
    if theme_css.endswith('sphinx_rtd_theme.css'):
        try:
            import sphinx_rtd_theme
            inject_css = LooseVersion(sphinx_rtd_theme.__version__) < LooseVersion('0.4.0')
        except ImportError:
            pass

    if inject_css and theme_css not in app.builder.css_files:
        if sphinx.version_info < (1, 8):
            app.builder.css_files.insert(0, theme_css)
        else:
            app.add_css_file(theme_css)

    # This is monkey patched on the signal because we can't know what the user
    # has done with their `app.builder.templates` before now.

    if not hasattr(app.builder.templates.render, '_patched'):
        # Janky monkey patch of template rendering to add our content
        old_render = app.builder.templates.render

        def rtd_render(self, template, render_context):
            """
            A decorator that renders the content with the users template renderer,
            then adds the Read the Docs HTML content at the end of body.
            """
            # Render Read the Docs content
            template_context = render_context.copy()
            template_context['rtd_css_url'] = '{}css/readthedocs-doc-embed.css'.format(STATIC_URL)
            template_context['rtd_analytics_url'] = '{}javascript/readthedocs-analytics.js'.format(
                STATIC_URL,
            )
            source = os.path.join(
                os.path.abspath(os.path.dirname(__file__)),
                '_templates',
                'readthedocs-insert.html.tmpl'
            )
            templ = open(source).read()
            rtd_content = app.builder.templates.render_string(templ, template_context)

            # Handle original render function
            content = old_render(template, render_context)
            end_body = content.lower().find('</head>')

            # Insert our content at the end of the body.
            if end_body != -1:
                content = content[:end_body] + rtd_content + "\n" + content[end_body:]
            else:
                log.debug("File doesn't look like HTML. Skipping RTD content addition")

            return content

        rtd_render._patched = True
        app.builder.templates.render = types.MethodType(rtd_render,
                                                        app.builder.templates)
427820
def markdown(doc, title=True, template='short_documentation.md'):
    """"""

    from jinja2 import Environment, PackageLoader, select_autoescape
    env = Environment(
        loader=PackageLoader('metapack', 'support/templates')
        #autoescape=select_autoescape(['html', 'xml'])
    )

    context = display_context(doc)

    return env.get_template(template).render(**context)
398438
def run_sphinx():
    """"""
    old_dir = here_directory()
    os.chdir(str(doc_directory()))
    doc_status = subprocess.check_call(['make', 'html'], shell=True)
    os.chdir(str(old_dir))  # go back to former working directory
    if doc_status is not 0:
        exit(Fore.RED + 'Something broke generating your documentation...')
961351
def setup(app) -> Dict[str, Any]:
    
    app.setup_extension("sphinx.ext.graphviz")
    app.add_node(
        inheritance_diagram,
        html=(html_visit_inheritance_diagram, None),
        latex=(latex_visit_inheritance_diagram, None),
        man=(skip, None),
        texinfo=(skip, None),
        text=(skip, None),
    )
    app.add_directive("inheritance-diagram", InheritanceDiagram)
    return {
        "version": uqbar.__version__,
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }
1072614
def _render_with_context(self, parsed_node, config):
        
        context = dbt.context.parser.generate(
            parsed_node,
            self.root_project_config,
            self.macro_manifest,
            config)

        dbt.clients.jinja.get_rendered(
            parsed_node.raw_sql, context, parsed_node.to_shallow_dict(),
            capture_macros=True)
676277
def render_app_name(context, app, template="/admin_app_name.html"):
    
    try:
        template = app['app_label'] + template
        text = render_to_string(template, context)
    except:
        text = app['name']
    return text
1341705
def generate_docs(app):
    
    config = app.config
    config_dir = app.env.srcdir
    source_root = os.path.join(config_dir, config.apidoc_source_root)
    output_root = os.path.join(config_dir, config.apidoc_output_root)
    execution_dir = os.path.join(config_dir, '..')

    # Remove any files generated by earlier builds
    cleanup(output_root)

    command = ['sphinx-apidoc', '-f', '-o', output_root, source_root]
    # Exclude anything else we were specifically asked to
    for exclude in config.apidoc_exclude:
        command.append(os.path.join(source_root, exclude))
    process = Popen(command, cwd=execution_dir)
    process.wait()
132602
def render(self, context):
        
        notifications = self.obj.resolve(context)
        return self.generate_html(notifications)
1183812
def gen(skipdirhtml=False):
    """"""
    docs_changelog = 'docs/changelog.rst'
    check_git_unchanged(docs_changelog)
    pandoc('--from=markdown', '--to=rst', '--output=' + docs_changelog, 'CHANGELOG.md')
    if not skipdirhtml:
        sphinx_build['-b', 'dirhtml', '-W', '-E', 'docs', 'docs/_build/dirhtml'] & FG
    sphinx_build['-b', 'html', '-W', '-E', 'docs', 'docs/_build/html'] & FG
1038643
def sphinx_extension(app, exception):
    ""
    if not app.builder.name in ("html", "dirhtml"):
        return

    if not app.config.sphinx_to_github:
        if app.config.sphinx_to_github_verbose:
            print("Sphinx-to-github: Disabled, doing nothing.")
        return

    if exception:
        if app.config.sphinx_to_github_verbose:
            print("Sphinx-to-github: Exception raised in main build, doing nothing.")
        return

    dir_helper = DirHelper(
            os.path.isdir,
            os.listdir,
            os.walk,
            shutil.rmtree
            )

    file_helper = FileSystemHelper(
            open,
            os.path.join,
            shutil.move,
            os.path.exists
            )

    operations_factory = OperationsFactory()
    handler_factory = HandlerFactory()

    layout_factory = LayoutFactory(
            operations_factory,
            handler_factory,
            file_helper,
            dir_helper,
            app.config.sphinx_to_github_verbose,
            sys.stdout,
            force=True
            )

    layout = layout_factory.create_layout(app.outdir)
    layout.process()
928940
def generate_html(store):
    
    spline = {
        'version': VERSION,
        'url': 'https://github.com/Nachtfeuer/pipeline',
        'generated': datetime.now().strftime("%A, %d. %B %Y - %I:%M:%S %p")
    }

    html_template_file = os.path.join(os.path.dirname(__file__), 'templates/report.html.j2')
    with open(html_template_file) as handle:
        html_template = handle.read()
        return render(html_template, spline=spline, store=store)
858195
def _copy_searchtools(self, renderer=None):
        
        log.info(bold('copying searchtools... '), nonl=True)

        if sphinx.version_info < (1, 8):
            search_js_file = 'searchtools.js_t'
        else:
            search_js_file = 'searchtools.js'
        path_src = os.path.join(
            package_dir, 'themes', 'basic', 'static', search_js_file
        )
        if os.path.exists(path_src):
            path_dest = os.path.join(self.outdir, '_static', 'searchtools.js')
            if renderer is None:
                # Sphinx 1.4 used the renderer from the existing builder, but
                # the pattern for Sphinx 1.5 is to pass in a renderer separate
                # from the builder. This supports both patterns for future
                # compatibility
                if sphinx.version_info < (1, 5):
                    renderer = self.templates
                else:
                    from sphinx.util.template import SphinxRenderer
                    renderer = SphinxRenderer()
            with codecs.open(path_src, 'r', encoding='utf-8') as h_src:
                with codecs.open(path_dest, 'w', encoding='utf-8') as h_dest:
                    data = h_src.read()
                    data = self.REPLACEMENT_PATTERN.sub(self.REPLACEMENT_TEXT, data)
                    h_dest.write(renderer.render_string(
                        data,
                        self.get_static_readthedocs_context()
                    ))
        else:
            log.warning('Missing {}'.format(search_js_file))
        log.info('done')
940634
def pandoc_process(app, what, name, obj, options, lines):
    "

    if not lines:
        return None

    input_format = app.config.mkdsupport_use_parser
    output_format = 'rst'

    # Since default encoding for sphinx.ext.autodoc is unicode and pypandoc.convert_text, which will always return a
    # unicode string, expects unicode or utf-8 encodes string, there is on need for dealing with coding
    text = SEP.join(lines)
    text = pypandoc.convert_text(text, output_format, format=input_format)

    # The 'lines' in Sphinx is a list of strings and the value should be changed
    del lines[:]
    lines.extend(text.split(SEP))
111112
def render_widgets(kb_app: kb,
                   sphinx_app: Sphinx,
                   doctree: doctree,
                   fromdocname: str,
                   ):
    

    builder: StandaloneHTMLBuilder = sphinx_app.builder

    for node in doctree.traverse(widget):
        # Render the output
        w = sphinx_app.env.widgets.get(node.name)
        context = builder.globalcontext.copy()

        # Add in certain globals
        context['resources'] = sphinx_app.env.resources
        context['references'] = sphinx_app.env.references
        output = w.render(sphinx_app, context)

        # Put the output into the node contents
        listing = [nodes.raw('', output, format='html')]
        node.replace_self(listing)