Пример #1
0
def process_generate_options(app: Sphinx) -> None:
    genfiles = app.config.autosummary_generate

    if genfiles is True:
        env = app.builder.env
        genfiles = [env.doc2path(x, base=None) for x in env.found_docs
                    if os.path.isfile(env.doc2path(x))]
    else:
        ext = list(app.config.source_suffix)
        genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
                    for genfile in genfiles]

        for entry in genfiles[:]:
            if not path.isfile(path.join(app.srcdir, entry)):
                logger.warning(__('autosummary_generate: file not found: %s'), entry)
                genfiles.remove(entry)

    if not genfiles:
        return

    suffix = get_rst_suffix(app)
    if suffix is None:
        logger.warning(__('autosummary generats .rst files internally. '
                          'But your source_suffix does not contain .rst. Skipped.'))
        return

    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    imported_members = app.config.autosummary_imported_members
    with mock(app.config.autosummary_mock_imports):
        generate_autosummary_docs(genfiles, builder=app.builder,
                                  suffix=suffix, base_path=app.srcdir,
                                  app=app, imported_members=imported_members)
Пример #2
0
def process_generate_options(app):
    genfiles = app.config.autosummary_generate

    ext = app.config.source_suffix

    if genfiles and not hasattr(genfiles, '__len__'):
        env = app.builder.env
        genfiles = [
            x + ext for x in env.found_docs if os.path.isfile(env.doc2path(x))
        ]

    if not genfiles:
        return

    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    genfiles = [
        genfile + (not genfile.endswith(ext) and ext or '')
        for genfile in genfiles
    ]

    generate_autosummary_docs(genfiles,
                              builder=app.builder,
                              warn=app.warn,
                              info=app.info,
                              suffix=ext,
                              base_path=app.srcdir)
Пример #3
0
def process_generate_options(app):
    # type: (Sphinx) -> None
    genfiles = app.config.autosummary_generate

    if genfiles and not hasattr(genfiles, '__len__'):
        env = app.builder.env
        genfiles = [env.doc2path(x, base=None) for x in env.found_docs
                    if os.path.isfile(env.doc2path(x))]

    if not genfiles:
        return

    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    ext = app.config.source_suffix
    genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
                for genfile in genfiles]

    suffix = get_rst_suffix(app)
    if suffix is None:
        logger.warning('autosummary generats .rst files internally. '
                       'But your source_suffix does not contain .rst. Skipped.')
        return

    generate_autosummary_docs(genfiles, builder=app.builder,
                              warn=logger.warning, info=logger.info,
                              suffix=suffix, base_path=app.srcdir,
                              app=app)
def _generate_stubs(app: Sphinx):
    gen_files = app.config.autosummary_generate

    if gen_files and not hasattr(gen_files, "__len__"):
        env = app.builder.env
        gen_files = [
            env.doc2path(x, base=None) for x in env.found_docs
            if Path(env.doc2path(x)).is_file()
        ]
    if not gen_files:
        return

    ext = app.config.source_suffix
    gen_files = [
        genfile + ("" if genfile.endswith(tuple(ext)) else ext[0])
        for genfile in gen_files
    ]

    suffix = autosummary.get_rst_suffix(app)
    if suffix is None:
        return

    generate_autosummary_docs(
        gen_files,
        builder=app.builder,
        warn=logger.warning,
        info=logger.info,
        suffix=suffix,
        base_path=app.srcdir,
        imported_members=True,
        app=app,
    )
Пример #5
0
def process_generate_options(app: Sphinx):
    genfiles = app.config.autosummary_generate

    if genfiles and not hasattr(genfiles, '__len__'):
        env = app.builder.env
        genfiles = [
            env.doc2path(x, base=None) for x in env.found_docs
            if Path(env.doc2path(x)).is_file()
        ]
    if not genfiles:
        return

    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    ext = app.config.source_suffix
    genfiles = [
        genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
        for genfile in genfiles
    ]

    suffix = autosummary.get_rst_suffix(app)
    if suffix is None:
        return

    generate_autosummary_docs(
        genfiles,
        builder=app.builder,
        warn=logger.warning,
        info=logger.info,
        suffix=suffix,
        base_path=app.srcdir,
        imported_members=True,
    )
Пример #6
0
def process_generate_options(app):
    # type: (Sphinx) -> None
    genfiles = app.config.autosummary_generate

    if genfiles and not hasattr(genfiles, '__len__'):
        env = app.builder.env
        genfiles = [env.doc2path(x, base=None) for x in env.found_docs
                    if os.path.isfile(env.doc2path(x))]

    if not genfiles:
        return

    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    ext = app.config.source_suffix
    genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
                for genfile in genfiles]

    suffix = get_rst_suffix(app)
    if suffix is None:
        logger.warning('autosummary generats .rst files internally. '
                       'But your source_suffix does not contain .rst. Skipped.')
        return

    generate_autosummary_docs(genfiles, builder=app.builder,
                              warn=logger.warning, info=logger.info,
                              suffix=suffix, base_path=app.srcdir)
Пример #7
0
def process_generate_options(app):
    genfiles = app.config.autosummary_generate
    if not genfiles:
        return
    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    ext = app.config.source_suffix
    genfiles = [path.join(app.srcdir, genfile +
                          (not genfile.endswith(ext) and ext or ''))
                for genfile in genfiles]
    generate_autosummary_docs(genfiles, warn=app.warn, info=app.info,
                              suffix=ext)
Пример #8
0
def test_generate_autosummary_docs_property(app):
    with patch('sphinx.ext.autosummary.generate.find_autosummary_in_files') as mock:
        mock.return_value = [AutosummaryEntry('target.methods.Base.prop', 'prop', None, False)]
        generate_autosummary_docs([], output_dir=app.srcdir, app=app)

    content = (app.srcdir / 'target.methods.Base.prop.rst').read_text()
    assert content == ("target.methods.Base.prop\n"
                       "========================\n"
                       "\n"
                       ".. currentmodule:: target.methods\n"
                       "\n"
                       ".. autoproperty:: Base.prop")
Пример #9
0
def process_generate_options(app):
    genfiles = app.config.autosummary_generate
    if not genfiles:
        return
    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    ext = app.config.source_suffix
    genfiles = [
        path.join(app.srcdir,
                  genfile + (not genfile.endswith(ext) and ext or ''))
        for genfile in genfiles
    ]
    generate_autosummary_docs(genfiles,
                              warn=app.warn,
                              info=app.info,
                              suffix=ext)
Пример #10
0
def process_generate_options(app):
    genfiles = app.config.autosummary_generate

    if genfiles and not hasattr(genfiles, '__len__'):
        env = app.builder.env
        genfiles = [env.doc2path(x, base=None) for x in env.found_docs
                    if os.path.isfile(env.doc2path(x))]

    if not genfiles:
        return

    from sphinx.ext.autosummary.generate import generate_autosummary_docs

    ext = app.config.source_suffix[0]
    genfiles = [genfile + (not genfile.endswith(ext) and ext or '')
                for genfile in genfiles]

    generate_autosummary_docs(genfiles, builder=app.builder,
                              warn=app.warn, info=app.info, suffix=ext,
                              base_path=app.srcdir)
Пример #11
0
def get_autosummary_api():
    import shutil
    from sphinx.ext.autosummary import import_by_name
    from sphinx.ext.autosummary.generate import DummyApplication, setup_documenters, generate_autosummary_docs

    sources = ['api.rst']
    output_dir = './tmp_generated'
    app = DummyApplication()
    setup_documenters(app)
    generate_autosummary_docs(sources, output_dir, app=app)

    autosummary_api = {}
    for module_name in _modules:
        try:
            module = importlib.import_module(module_name)
            module_item = ModuleItem(module)
            autosummary_api[module_name] = module_item
        except ImportError as err:
            print(f'module {module_name} could not be imported: {err}')
            autosummary_api[module_name] = err

    for generated_rst_file in os.listdir(output_dir):
        qualname, ext = os.path.splitext(generated_rst_file)
        qualname, obj, parent, module_name = import_by_name(qualname)
        module_item = autosummary_api[module_name]
        name = qualname.split('.')[-1]
        if inspect.isclass(obj) and name in module_item.classes:
            continue
        if inspect.isclass(parent):
            class_name = parent.__name__
            if class_name not in module_item.classes:
                module_item.insert_element(class_name, parent)
            class_item = module_item.classes[class_name]
            class_item.insert_element(name, obj)
        else:
            module_item.insert_element(name, obj)

    if os.path.exists(output_dir):
        shutil.rmtree(output_dir)

    return autosummary_api
Пример #12
0
def get_autosummary_api():
    import shutil
    from sphinx.ext.autosummary import import_by_name
    from sphinx.ext.autosummary.generate import DummyApplication, setup_documenters, generate_autosummary_docs

    sources = ['api.rst']
    output_dir = './tmp_generated'
    app = DummyApplication()
    setup_documenters(app)
    generate_autosummary_docs(sources, output_dir, app=app)

    autosummary_api = {}
    for module_name in _modules:
        try:
            module = importlib.import_module(module_name)
            module_item = ModuleItem(module)
            autosummary_api[module_name] = module_item
        except ImportError as err:
            print('module {} could not be imported: {}'.format(module_name, err))
            autosummary_api[module_name] = err

    for generated_rst_file in os.listdir(output_dir):
        qualname, ext = os.path.splitext(generated_rst_file)
        qualname, obj, parent, module_name = import_by_name(qualname)
        module_item = autosummary_api[module_name]
        name = qualname.split('.')[-1]
        if inspect.isclass(obj) and name in module_item.classes:
            continue
        if inspect.isclass(parent):
            class_name = parent.__name__
            if class_name not in module_item.classes:
                module_item.insert_element(class_name, parent)
            class_item = module_item.classes[class_name]
            class_item.insert_element(name, obj)
        else:
            module_item.insert_element(name, obj)

    if os.path.exists(output_dir):
        shutil.rmtree(output_dir)

    return autosummary_api