跳转到主要内容

Sphinx扩展,用于自动生成API树。

项目描述

sphinx-apitree

Unittests PyPI version

apitree 是一个小型库,可以以最小的摩擦生成可用的文档!

apitree 负责一切,因此您可以只关注代码。

使用方法

docs/conf.py 中,替换所有内容为

import apitree

apitree.make_project(
    # e.g. `import visu3d as v3d` -> {'v3d': 'visu3d'}
    project_name={'alias': 'my_module'},
    globals=globals(),
)

然后生成文档

sphinx-build -b html docs/ docs/_build

要在您的 toctree 中添加 api/my_module/index,例如

..toctree:
  :caption: API

  api/my_module/index

功能

  • 全部包含:单次函数调用包括主题、API生成等 ...
  • 自动生成API树
    • 不需要 __all__(智能检测哪些符号已记录)
    • 添加可展开的toc树,包含所有符号
  • 添加到 GitHub 的链接。
  • 默认支持Markdown(.md)/ Jupyter(.ipynb
  • 自动交叉引用(只需在Markdown内联代码中注释 my_symbol,链接会自动添加)
  • autodocapitree 相反,它还记录
    • 类型注解(Union[],...)
    • 属性
  • ...

在项目中安装

  1. pyproject.toml

    [project.optional-dependencies]
    # Installed through `pip install .[docs]`
    docs = [
        # Install `apitree` with all extensions (sphinx, theme,...)
        "sphinx-apitree[ext]",
    ]
    
  2. .readthedocs.yaml

    sphinx:
    configuration: docs/conf.py
    
    python:
    install:
        - method: pip
        path: .
        extra_requirements:
            - docs
    

选项

默认情况下,apitree 尝试自动推断一切。但是有时用户想覆盖默认选项。

  • 包与模块:默认情况下,所有 __init__.py 定义公共API(记录导入),而模块(module.py)定义实现(不记录导入)。您可以通过在模块定义中添加来显式标记模块为包,以便记录其导入,如下所示

    __apitree__ = dict(
        is_package=True,
    )
    

使用apitree的项目示例

生成于

echo start \
&& cd ../visu3d          && sphinx-build -b html docs/ docs/_build \
&& cd ../dataclass_array && sphinx-build -b html docs/ docs/_build \
&& cd ../etils           && sphinx-build -b html docs/ docs/_build \
&& cd ../kauldron        && sphinx-build -b html docs/ docs/_build \
&& echo finished

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

sphinx_apitree-1.5.3.tar.gz (19.7 kB 查看散列)

上传时间

构建分布

sphinx_apitree-1.5.3-py3-none-any.whl (24.8 kB 查看散列)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面