For each resource type, register a new Sphinx directive
427370
def add_directives(kb_app: kb,
                   sphinx_app: Sphinx,
                   sphinx_env: BuildEnvironment,
                   docnames=List[str],
                   ):
    

    for k, v in list(kb_app.config.resources.items()):
        sphinx_app.add_directive(k, ResourceDirective)
1290260
def generate_configuration(directory):
    
    
    # conf.py file for Sphinx
    conf = osp.join(get_module_source_path('spyder.plugins.help.utils'),
                    'conf.py')

    # Docstring layout page (in Jinja):
    layout = osp.join(osp.join(CONFDIR_PATH, 'templates'), 'layout.html')
    
    os.makedirs(osp.join(directory, 'templates'))
    os.makedirs(osp.join(directory, 'static'))
    shutil.copy(conf, directory)
    shutil.copy(layout, osp.join(directory, 'templates'))
    open(osp.join(directory, '__init__.py'), 'w').write('')
    open(osp.join(directory, 'static', 'empty'), 'w').write('')
1248401
def docs(ctx, output='html', rebuild=False, show=True, verbose=True):
    """"""
    sphinx_build = ctx.run(
        'sphinx-build -b {output} {all} {verbose} docs docs/_build'.format(
            output=output,
            all='-a -E' if rebuild else '',
            verbose='-v' if verbose else ''))
    if not sphinx_build.ok:
        fatal("Failed to build the docs", cause=sphinx_build)

    if show:
        path = os.path.join(DOCS_OUTPUT_DIR, 'index.html')
        if sys.platform == 'darwin':
            path = 'file://%s' % os.path.abspath(path)
        webbrowser.open_new_tab(path)
1210429
def _insert_common_sphinx_configs(c, *, project_name):
    
    c['project'] = project_name

    # The suffix(es) of source filenames.
    # You can specify multiple suffix as a list of string:
    c['source_suffix'] = '.rst'

    # The encoding of source files.
    c['source_encoding'] = 'utf-8-sig'

    # The master toctree document.
    c['master_doc'] = 'index'

    # Configure figure numbering
    c['numfig'] = True
    c['numfig_format'] = {'figure': 'Figure %s',
                          'table': 'Table %s',
                          'code-block': 'Listing %s'}

    # The reST default role (used for this markup: `text`)
    c['default_role'] = 'obj'

    # This is added to the end of RST files - a good place to put substitutions
    # to be used globally.
    c['rst_epilog'] = """
.. _Astropy: http://astropy.org
    """

    # A list of warning types to suppress arbitrary warning messages. We mean
    # to override directives in
    # astropy_helpers.sphinx.ext.autodoc_enhancements, thus need to ignore
    # those warning. This can be removed once the patch gets released in
    # upstream Sphinx (https://github.com/sphinx-doc/sphinx/pull/1843).
    # Suppress the warnings requires Sphinx v1.4.2
    c['suppress_warnings'] = ['app.add_directive', ]

    return c
870731
def add_resource(mt_file, ref, cache):
    """"""

    if isinstance(mt_file, MetapackDoc):
        doc = mt_file
    else:
        doc = MetapackDoc(mt_file)

    if not 'Resources' in doc:
        doc.new_section('Resources')

    doc['Resources'].args = [e for e in set(doc['Resources'].args + ['Name', 'StartLine', 'HeaderLines', 'Encoding']) if
                             e]

    seen_names = set()

    u = parse_app_url(ref)

    # The web and file URLs don't list the same.

    if u.proto == 'file':
        entries = u.list()
    else:
        entries = [ssu for su in u.list() for ssu in su.list()]

    errors = []

    for e in entries:
        if not add_single_resource(doc, e, cache=cache, seen_names=seen_names):
            errors.append(e)

    if errors:
        prt()
        warn("Found, but failed to add these urls:")
        for e in errors:
            print('    ', e)

    write_doc(doc, mt_file)
1076990
def enable_sphinx_if_possible():
    """"""
    if SPHINX_INSTALLED:
        srcdir = tempfile.mkdtemp()
        outdir = os.path.join(srcdir, '_build')
        try:
            sphinx.application.Sphinx(srcdir=srcdir,
                                      confdir=None,
                                      outdir=outdir,
                                      doctreedir=outdir,
                                      buildername='dummy',
                                      status=None)
            yield
        finally:
            shutil.rmtree(srcdir)
    else:
        yield
1110671
def run(self):
        
        env = self.state.document.settings.env

        try:
            class_name = self.arguments[0]
        except IndexError:
            raise SphinxError(
                '{0} directive requires a class name as an '
                'argument'.format(self.directive_name)
            )
        self._logger.debug('%s using class %s',
                           self.directive_name, class_name)

        summary_node = self._create_summary_node(class_name)

        # target_id = format_task_id(class_name)
        target_id = self.get_target_id(class_name)
        target_node = nodes.target('', '', ids=[target_id])

        # Store these task/configurable topic nodes in the environment for
        # later cross referencing.
        if not hasattr(env, 'lsst_task_topics'):
            env.lsst_task_topics = {}
        env.lsst_task_topics[target_id] = {
            'docname': env.docname,
            'lineno': self.lineno,
            'target': target_node,
            'summary_node': summary_node,
            'fully_qualified_name': class_name,
            'type': self.get_type(class_name)
        }

        return [target_node]
60752
def register_templates(self, directory):
        
        try:
            resource_listdir(directory, 'v{}'.format(ES_VERSION[0]))
            directory = '{}/v{}'.format(directory, ES_VERSION[0])
        except (OSError, IOError) as ex:
            if getattr(ex, 'errno', 0) == errno.ENOENT:
                raise OSError(
                    "Please move your templates to a subfolder named "
                    "according to the Elasticsearch version "
                    "which your templates are intended "
                    "for. (e.g. '{}.v{}')".format(directory,
                                                  ES_VERSION[0]))
        result = {}
        module_name, parts = directory.split('.')[0], directory.split('.')[1:]
        parts = tuple(parts)

        def _walk_dir(parts):
            resource_name = os.path.join(*parts)

            for filename in resource_listdir(module_name, resource_name):
                template_name = build_index_name(
                    self.app,
                    *(parts[1:] + (filename, ))
                )
                file_path = os.path.join(resource_name, filename)

                if resource_isdir(module_name, file_path):
                    _walk_dir((parts + (filename, )))
                    continue

                ext = os.path.splitext(filename)[1]
                if ext not in {'.json', }:
                    continue

                result[template_name] = resource_filename(
                    module_name, os.path.join(resource_name, filename))

        # Start the recursion here:
        _walk_dir(parts)
        return result
1018036
def construct_meta(need_data, env):
    

    hide_options = env.config.needs_hide_options
    if not isinstance(hide_options, list):
        raise SphinxError('Config parameter needs_hide_options must be of type list')

    node_meta = nodes.line_block(classes=['needs_meta'])
    # need parameters
    param_status = "status: "
    param_tags = "tags: "

    if need_data["status"] is not None and 'status' not in hide_options:
        status_line = nodes.line(classes=['status'])
        # node_status = nodes.line(param_status, param_status, classes=['status'])
        node_status = nodes.inline(param_status, param_status, classes=['status'])
        status_line.append(node_status)
        status_line.append(nodes.inline(need_data["status"], need_data["status"],
                                        classes=["needs-status", str(need_data['status'])]))
        node_meta.append(status_line)

    if need_data["tags"] and 'tags' not in hide_options:
        tag_line = nodes.line(classes=['tags'])
        # node_tags = nodes.line(param_tags, param_tags, classes=['tags'])
        node_tags = nodes.inline(param_tags, param_tags, classes=['tags'])
        tag_line.append(node_tags)
        for tag in need_data['tags']:
            # node_tags.append(nodes.inline(tag, tag, classes=["needs-tag", str(tag)]))
            # node_tags.append(nodes.inline(' ', ' '))
            tag_line.append(nodes.inline(tag, tag, classes=["needs-tag", str(tag)]))
            tag_line.append(nodes.inline(' ', ' '))
        node_meta.append(tag_line)

    # Links incoming
    if need_data['links_back'] and 'links_back' not in hide_options:
        node_incoming_line = nodes.line(classes=['links', 'incoming'])
        prefix = "links incoming: "
        node_incoming_prefix = nodes.inline(prefix, prefix)
        node_incoming_line.append(node_incoming_prefix)
        node_incoming_links = Need_incoming(reftarget=need_data['id'])
        node_incoming_links.append(nodes.inline(need_data['id'], need_data['id']))
        node_incoming_line.append(node_incoming_links)
        node_meta.append(node_incoming_line)

    # # Links outgoing
    if need_data['links'] and 'links' not in hide_options:
        node_outgoing_line = nodes.line(classes=['links', 'outgoing'])
        prefix = "links outgoing: "
        node_outgoing_prefix = nodes.inline(prefix, prefix)
        node_outgoing_line.append(node_outgoing_prefix)
        node_outgoing_links = Need_outgoing(reftarget=need_data['id'])
        node_outgoing_links.append(nodes.inline(need_data['id'], need_data['id']))
        node_outgoing_line.append(node_outgoing_links)
        node_meta.append(node_outgoing_line)

    extra_options = getattr(env.config, 'needs_extra_options', {})
    node_extra_options = []
    for key, value in extra_options.items():
        if key in hide_options:
            continue
        param_data = need_data[key]
        if param_data is None or not param_data:
            continue
        param_option = '{}: '.format(key)
        option_line = nodes.line(classes=['extra_option'])
        option_line.append(nodes.inline(param_option, param_option, classes=['extra_option']))
        option_line.append(nodes.inline(param_data, param_data,
                                        classes=["needs-extra-option", str(key)]))
        node_extra_options.append(option_line)

    node_meta += node_extra_options

    global_options = getattr(env.config, 'needs_global_options', {})
    node_global_options = []
    for key, value in global_options.items():
        # If a global option got locally overwritten, it must already part of extra_options.
        # In this skipp output, as this is done during extra_option handling
        if key in extra_options or key in hide_options:
            continue

        param_data = need_data[key]
        if param_data is None or not param_data:
            continue
        param_option = '{}: '.format(key)
        global_option_line = nodes.line(classes=['global_option'])
        global_option_line.append(nodes.inline(param_option, param_option, classes=['global_option']))
        global_option_line.append(nodes.inline(param_data, param_data,
                                               classes=["needs-global-option", str(key)]))
        node_global_options.append(global_option_line)

    node_meta += node_global_options

    return node_meta
531195
def register(resource, options = {}, &block)
      ns = options.fetch(:namespace) { default_namespace }
      namespace(ns).register resource, options, &block
    end
399707
def setup(app):
    """"""
    sphinx_compatibility._app = app

    app.add_config_value('sphinx_gallery_conf', DEFAULT_GALLERY_CONF, 'html')
    for key in ['plot_gallery', 'abort_on_example_error']:
        app.add_config_value(key, get_default_config_value(key), 'html')

    try:
        app.add_css_file('gallery.css')
    except AttributeError:  # Sphinx < 1.8
        app.add_stylesheet('gallery.css')

    # Sphinx < 1.6 calls it `_extensions`, >= 1.6 is `extensions`.
    extensions_attr = '_extensions' if hasattr(
        app, '_extensions') else 'extensions'
    if 'sphinx.ext.autodoc' in getattr(app, extensions_attr):
        app.connect('autodoc-process-docstring', touch_empty_backreferences)

    app.connect('builder-inited', generate_gallery_rst)
    app.connect('build-finished', copy_binder_files)
    app.connect('build-finished', summarize_failing_examples)
    app.connect('build-finished', embed_code_links)
    metadata = {'parallel_read_safe': True,
                'parallel_write_safe': False,
                'version': _sg_version}
    return metadata
465524
def setup(app):
    ""
    app.add_config_value("sphinx_to_github", True, '')
    app.add_config_value("sphinx_to_github_verbose", True, '')
    app.connect("build-finished", sphinx_extension)
1344849
def livehtml(context):
    ""
    builder = 'html'
    outputdir = os.path.join(DOCS_BUILDDIR, builder)
    cmdline = 'sphinx-autobuild -b {} {} {}'.format(builder, DOCS_SRCDIR, outputdir)
    context.run(cmdline, pty=True)
56327
def setup(cls, app):  # pragma: no cover
        """"""
        if cls.directive_name is None:
            raise NotImplementedError('directive_name must be set by '
                                      'subclasses of BaseDirective')
        if not app.registry.has_domain('http'):
            setup_httpdomain(app)
        app.add_config_value('{}_harness'.format(cls.directive_name),
                             None, 'env')
        app.add_directive(cls.directive_name, cls)
        app.connect('builder-inited', cls.run_setup)
        app.connect('build-finished', cls.run_teardown)
        app.connect('env-get-outdated', cls.get_outdated_docs)
        app.connect('env-purge-doc', cls.purge_docs)
316897
def setup(app):
    
    import sphinxcontrib_django.docstrings
    import sphinxcontrib_django.roles

    # Setup both modules at once. They can also be separately imported to
    # use only fragments of this package.
    sphinxcontrib_django.docstrings.setup(app)
    sphinxcontrib_django.roles.setup(app)
1177414
private function registerResources()
    {
        $configFilename = __DIR__ . '/../../config/arbory.php';

        $this->mergeConfigFrom( $configFilename, 'arbory' );

        $this->publishes( [
            $configFilename => config_path( 'arbory.php' )
        ], 'config' );

        $this->publishes( [
            __DIR__ . '/../../stubs/settings.stub' => config_path( 'settings.php' )
        ], 'config' );

        $this->publishes( [
            __DIR__ . '/../../stubs/admin_routes.stub' => base_path( '/routes/admin.php' )
        ], 'config' );

        $this->publishes([
            __DIR__ . '/../../resources/lang/' => base_path('resources/lang/vendor/arbory')
        ], 'lang');

        $this->loadMigrationsFrom( __DIR__ . '/../../database/migrations' );
        $this->loadViewsFrom( __DIR__ . '/../../resources/views', 'arbory' );
    }
388493
def _on_sphinx_thread_html_ready(self, html_text):
        """"""
        self._sphinx_thread.wait()
        self.set_rich_text_html(html_text, QUrl.fromLocalFile(self.css_path))