mm_extensions.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:mongomotor 作者: jucacrispim 项目源码 文件源码
def process_mongomotor_nodes(app, doctree):
    # Search doctree for MongoMotor's methods and attributes whose docstrings
    #  were copied from MongoEngine, and fix them up for MongoMotor:
    #   1. Remove all version annotations like "New in version 2.0" since
    #      PyMongo's version numbers are meaningless in Motor's docs.
    #   2. Remove "seealso" directives that reference PyMongo's docs.
    #
    # We do this here, rather than by registering a callback to Sphinx's
    # 'autodoc-process-signature' event, because it's way easier to handle the
    # parsed doctree before it's turned into HTML than it is to update the RST.

    for objnode in doctree.traverse(desc):
        if objnode['objtype'] in ('method', 'attribute', 'classmethod'):
            signature_node = find_by_path(objnode, [desc_signature])[0]
            name = '.'.join([
                signature_node['module'], signature_node['fullname']])

            assert name.startswith('mongomotor.')
            obj_mm_info = mm_info.get(name)
            if obj_mm_info:
                desc_content_node = find_by_path(objnode, [desc_content])[0]
                if (obj_mm_info.get('is_async_method') or
                        obj_mm_info.get('has_coroutine_annotation')):
                    coro_annotation = addnodes.desc_annotation(
                        'coroutine ', 'coroutine ',
                        classes=['coro-annotation'])
                    signature_node.insert(0, coro_annotation)

                if obj_mm_info['is_pymongo_docstring']:
                    # Remove all "versionadded", "versionchanged" and
                    # "deprecated" directives from the docs we imported from
                    # PyMongo
                    version_nodes = find_by_path(
                        desc_content_node, [versionmodified])

                    for version_node in version_nodes:
                        version_node.parent.remove(version_node)

                    # Remove all "seealso" directives that contain :doc:
                    # references from PyMongo's docs
                    seealso_nodes = find_by_path(desc_content_node, [seealso])

                    for seealso_node in seealso_nodes:
                        if 'reftype="doc"' in str(seealso_node):
                            seealso_node.parent.remove(seealso_node)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号