当前位置: 首页>>代码示例>>Python>>正文


Python application.Sphinx方法代码示例

本文整理汇总了Python中sphinx.application.Sphinx方法的典型用法代码示例。如果您正苦于以下问题:Python application.Sphinx方法的具体用法?Python application.Sphinx怎么用?Python application.Sphinx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sphinx.application的用法示例。


在下文中一共展示了application.Sphinx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def test(monkeypatch, tmpdir, tail, expected_error):
    """Test valid and invalid values."""
    tmpdir.join('conf.py').write(BASE_CONFIG.format(py.path.local(__file__).join('..', '..')))
    tmpdir.join('conf.py').write(tail, mode='a')
    tmpdir.join('index.rst').write('====\nMain\n====\n\n.. toctree::\n    :maxdepth: 2\n.. disqus::')
    monkeypatch.setattr(directives, '_directives', getattr(directives, '_directives').copy())
    monkeypatch.setattr(roles, '_roles', getattr(roles, '_roles').copy())

    srcdir = confdir = str(tmpdir)
    outdir = tmpdir.join('_build', 'html')
    doctreedir = outdir.join('doctrees').ensure(dir=True, rec=True)
    app = application.Sphinx(srcdir, confdir, str(outdir), str(doctreedir), 'html')

    if not expected_error:
        app.builder.build_all()
        html_body = outdir.join('index.html').read()
        disqus_div = re.findall(r'(<div[^>]+ id="disqus_thread"[^>]*></div>)', html_body)[0]
        assert 'data-disqus-shortname="good"' in disqus_div
        return

    with pytest.raises(errors.ExtensionError) as exc:
        app.builder.build_all()
    assert expected_error == exc.value.args[0] 
开发者ID:Robpol86,项目名称:sphinxcontrib-disqus,代码行数:25,代码来源:test_shortname.py

示例2: test

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def test(monkeypatch, tmpdir, expected, rst_title, option):
    """Test valid and invalid values."""
    tmpdir.join('conf.py').write(BASE_CONFIG.format(py.path.local(__file__).join('..', '..')))
    tmpdir.join('conf.py').write('', mode='a')
    tmpdir.join('index.rst').write('{}.. toctree::\n    :maxdepth: 2\n.. disqus::\n{}'.format(rst_title, option))
    monkeypatch.setattr(directives, '_directives', getattr(directives, '_directives').copy())
    monkeypatch.setattr(roles, '_roles', getattr(roles, '_roles').copy())

    srcdir = confdir = str(tmpdir)
    outdir = tmpdir.join('_build', 'html')
    doctreedir = outdir.join('doctrees').ensure(dir=True, rec=True)
    app = application.Sphinx(srcdir, confdir, str(outdir), str(doctreedir), 'html')

    if expected:
        app.builder.build_all()
        html_body = outdir.join('index.html').read()
        disqus_div = re.findall(r'(<div[^>]+ id="disqus_thread"[^>]*></div>)', html_body)[0]
        assert 'data-disqus-identifier="{}"'.format(expected) in disqus_div
        return

    with pytest.raises(DisqusError) as exc:
        app.builder.build_all()
    assert 'No title nodes found in document, cannot derive disqus_identifier config value.' == exc.value.args[0] 
开发者ID:Robpol86,项目名称:sphinxcontrib-disqus,代码行数:25,代码来源:test_identifier.py

示例3: sphinx_app

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def sphinx_app(tmpdir_factory, req_mpl, req_pil):
    temp_dir = (tmpdir_factory.getbasetemp() / 'root').strpath
    src_dir = op.join(op.dirname(__file__), 'tinybuild')

    def ignore(src, names):
        return ('_build', 'gen_modules', 'auto_examples')

    shutil.copytree(src_dir, temp_dir, ignore=ignore)
    # For testing iteration, you can get similar behavior just doing `make`
    # inside the tinybuild directory
    src_dir = temp_dir
    conf_dir = temp_dir
    out_dir = op.join(temp_dir, '_build', 'html')
    toctrees_dir = op.join(temp_dir, '_build', 'toctrees')
    # Avoid warnings about re-registration, see:
    # https://github.com/sphinx-doc/sphinx/issues/5038
    with docutils_namespace():
        app = Sphinx(src_dir, conf_dir, out_dir, toctrees_dir,
                     buildername='html', status=StringIO(),
                     warning=StringIO())
        # need to build within the context manager
        # for automodule and backrefs to work
        app.build(False, [])
    return app 
开发者ID:sphinx-gallery,项目名称:sphinx-gallery,代码行数:26,代码来源:test_full.py

示例4: sphinx_app_wrapper

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def sphinx_app_wrapper(tmpdir, conf_file, req_mpl, req_pil):
    _fixturedir = os.path.join(os.path.dirname(__file__), 'testconfs')
    srcdir = os.path.join(str(tmpdir), "config_test")
    shutil.copytree(_fixturedir, srcdir)
    shutil.copytree(os.path.join(_fixturedir, "src"),
                    os.path.join(str(tmpdir), "examples"))

    base_config = """
import os
import sphinx_gallery
extensions = %r
exclude_patterns = ['_build']
source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'Sphinx-Gallery <Tests>'\n\n
""" % (conf_file['extensions'],)
    with open(os.path.join(srcdir, "conf.py"), "w") as conffile:
        conffile.write(base_config + conf_file['content'])

    return SphinxAppWrapper(
        srcdir, srcdir, os.path.join(srcdir, "_build"),
        os.path.join(srcdir, "_build", "toctree"), "html", warning=StringIO(),
        status=StringIO()) 
开发者ID:sphinx-gallery,项目名称:sphinx-gallery,代码行数:26,代码来源:conftest.py

示例5: build

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def build(self):
        """Build the documentation. Places the data into the `outdir`
        directory. Use it like this::

            support = WebSupport(srcdir, builddir, search='xapian')
            support.build()

        This will read reStructured text files from `srcdir`. Then it will
        build the pickles and search index, placing them into `builddir`.
        It will also save node data to the database.
        """
        if not self.srcdir:
            raise RuntimeError('No srcdir associated with WebSupport object')

        from sphinx.application import Sphinx
        app = Sphinx(self.srcdir, self.srcdir, self.outdir, self.doctreedir,
                     self.buildername, self.confoverrides, status=self.status,
                     warning=self.warning)
        app.builder.set_webinfo(self.staticdir, self.staticroot,  # type: ignore
                                self.search, self.storage)

        self.storage.pre_build()
        app.build()
        self.storage.post_build() 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:26,代码来源:core.py

示例6: setup

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def setup(app):
    """Sphinx extension setup function

    When the extension is loaded, Sphinx imports this module and executes
    the ``setup()`` function, which in turn notifies Sphinx of everything
    the extension offers.

    Parameters
    ----------
    app : sphinx.application.Sphinx
        Application object representing the Sphinx process

    Notes
    -----
    This function uses the setup function of the :mod:`sphinx.ext.napoleon`
    module"""
    from sphinx.application import Sphinx
    if not isinstance(app, Sphinx):
        return  # probably called by tests

    app.connect('autodoc-process-docstring', process_docstring)
    return napoleon_setup(app) 
开发者ID:psyplot,项目名称:psyplot,代码行数:24,代码来源:extended_napoleon.py

示例7: _find_duplicate_default_nodes

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def _find_duplicate_default_nodes():
    from sphinx import addnodes # pylint:disable=import-outside-toplevel

    class App(object):

        def __init__(self):
            self.nodes = set()

        def add_node(self, node):
            self.nodes.add(node.__name__)


    app = App()
    try:
        addnodes.setup(app)
    except AttributeError:
        # Sphinx 1 doesn't have this
        pass

    return app.nodes 
开发者ID:NextThought,项目名称:sphinxcontrib-programoutput,代码行数:22,代码来源:__init__.py

示例8: app

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def app(self):
        """
        Sphinx application for the current test.
        """
        srcdir = self.srcdir
        outdir = self.outdir
        doctreedir = self.doctreedir
        confoverrides = self.confoverrides
        warningiserror = not self.ignore_warnings

        app = Sphinx(str(srcdir), str(srcdir), str(outdir), str(doctreedir), 'html',
                     status=None, warning=None, freshenv=None,
                     warningiserror=warningiserror, confoverrides=confoverrides)
        if self.build_app:
            app.build()
        return app 
开发者ID:NextThought,项目名称:sphinxcontrib-programoutput,代码行数:18,代码来源:__init__.py

示例9: merge_typehints

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def merge_typehints(app: Sphinx, domain: str, objtype: str, contentnode: Element) -> None:
    if domain != 'py':
        return
    if app._autodoc_typehints_description is False:  # type: ignore
        return

    signature = cast(addnodes.desc_signature, contentnode.parent[0])
    if signature['module']:
        fullname = '.'.join([signature['module'], signature['fullname']])
    else:
        fullname = signature['fullname']
    annotations = app.env.temp_data.get('annotations', {})
    if annotations.get(fullname, {}):
        field_lists = [n for n in contentnode if isinstance(n, nodes.field_list)]
        if field_lists == []:
            field_list = insert_field_list(contentnode)
            field_lists.append(field_list)

        for field_list in field_lists:
            modify_field_list(field_list, annotations[fullname]) 
开发者ID:thu-coai,项目名称:cotk,代码行数:22,代码来源:typehints.py

示例10: merge_autodoc_default_flags

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def merge_autodoc_default_flags(app: Sphinx, config: Config) -> None:
    """This merges the autodoc_default_flags to autodoc_default_options."""
    if not config.autodoc_default_flags:
        return

    # Note: this option will be removed in Sphinx-4.0.  But I marked this as
    # RemovedInSphinx *30* Warning because we have to emit warnings for users
    # who will be still in use with Sphinx-3.x.  So we should replace this by
    # logger.warning() on 3.0.0 release.
    warnings.warn('autodoc_default_flags is now deprecated. '
                  'Please use autodoc_default_options instead.',
                  RemovedInSphinx30Warning, stacklevel=2)

    for option in config.autodoc_default_flags:
        if isinstance(option, str):
            config.autodoc_default_options[option] = None
        else:
            logger.warning(
                __("Ignoring invalid option in autodoc_default_flags: %r"),
                option, type='autodoc'
            ) 
开发者ID:thu-coai,项目名称:cotk,代码行数:23,代码来源:__init__.py

示例11: update_annotations_using_type_comments

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def update_annotations_using_type_comments(app: Sphinx, obj: Any, bound_method: bool) -> None:
    """Update annotations info of *obj* using type_comments."""
    try:
        function = get_type_comment(obj)
        if function and hasattr(function, 'argtypes'):
            if function.argtypes != [ast.Ellipsis]:  # type: ignore
                sig = inspect.signature(obj, bound_method)
                for i, param in enumerate(sig.parameters.values()):
                    if param.name not in obj.__annotations__:
                        annotation = ast_unparse(function.argtypes[i])  # type: ignore
                        obj.__annotations__[param.name] = annotation

            if 'return' not in obj.__annotations__:
                obj.__annotations__['return'] = ast_unparse(function.returns)  # type: ignore
    except NotImplementedError as exc:  # failed to ast.unparse()
        logger.warning("Failed to parse type_comment for %r: %s", obj, exc) 
开发者ID:thu-coai,项目名称:cotk,代码行数:18,代码来源:type_comment.py

示例12: setup

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def setup(app: Sphinx) -> None:
    """Initialize the extension."""
    app.add_config_value(
        'scm_version_title_settings',
        {
            'scm': 'git',
            'date_format': '%d %b %Y',
        },
        'html',
    )
    app.add_node(
        version_subtitle,
        html=(
            _visit_version_subtitle,
            _depart_version_subtitle,
        ),
    )
    app.add_directive(
        'scm-version-title', SCMVersionTitle,
    )

    return {
        'parallel_read_safe': True,
        'version': __version__,
    } 
开发者ID:cherrypy,项目名称:cheroot,代码行数:27,代码来源:scm_tag_titles_ext.py

示例13: sphinx_built_file

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def sphinx_built_file(test_dir, test_file):
    os.chdir('tests/{0}'.format(test_dir))
    try:
        app = Sphinx(
            srcdir='.',
            confdir='.',
            outdir='_build/text',
            doctreedir='_build/.doctrees',
            buildername='html',
            verbosity=1,
        )
        app.build(force_all=True)
        with io.open(test_file, encoding='utf-8') as fin:
            yield fin.read().strip()
    finally:
        shutil.rmtree('_build')
        os.chdir('../..') 
开发者ID:readthedocs,项目名称:recommonmark,代码行数:19,代码来源:test_sphinx.py

示例14: build

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def build(root, builder='html', **kwargs):
    tmpdir = tempfile.mkdtemp()

    srcdir = os.path.join(os.path.dirname(__file__), 'roots', root)
    destdir = os.path.join(tmpdir, builder)
    doctreedir = os.path.join(tmpdir, 'doctree/')

    status = StringIO()
    warning = StringIO()

    kwargs.update({
        'status': status,
        'warning': warning,
    })

    confoverrides = kwargs.pop('confoverrides', {})
    confoverrides['html_theme'] = 'sphinx_rtd_theme'
    extensions = confoverrides.get('extensions', [])
    extensions.append('readthedocs_ext.readthedocs')
    confoverrides['extensions'] = extensions
    kwargs['confoverrides'] = confoverrides

    try:
        app = Sphinx(srcdir, srcdir, destdir, doctreedir, builder, **kwargs)
        app.builder.build_all()
        yield (app, status.getvalue(), warning.getvalue())
    except Exception as e:
        print('# root:', root)
        print('# builder:', builder)
        print('# source:', srcdir)
        print('# destination:', destdir)
        print('# status:', '\n' + status.getvalue())
        print('# warning:', '\n' + warning.getvalue())
        raise
    finally:
        shutil.rmtree(tmpdir) 
开发者ID:tirthajyoti,项目名称:doepy,代码行数:38,代码来源:util.py

示例15: setup

# 需要导入模块: from sphinx import application [as 别名]
# 或者: from sphinx.application import Sphinx [as 别名]
def setup(app: Sphinx):
    NumpyDocstring._parse_returns_section = scanpy_parse_returns_section 
开发者ID:YosefLab,项目名称:scVI,代码行数:4,代码来源:typed_returns.py


注:本文中的sphinx.application.Sphinx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。