sphinx“matlabdomain”扩展
sphinxcontrib-matlabdomain的Python项目详细描述
这个包包含matlab sphinx域和autodoc扩展。
安装
使用Pip, Setuptools Easy Install或 Python Distributions Utilities (Distutils)。
管道:
~$ pip install -U sphinxcontrib-matlabdomain
易于安装:
~$ easy_install -U sphinxcontrib-matlabdomain
distutils:
~/downloads$ curl https://pypi.python.org/packages/source/s/sphinxcontrib-matlabdomain/sphinxcontrib-matlabdomain-0.X.tar.gz ~/downloads$ tar -xf sphinxcontrib-matlabdomain-0.X.tar.gz ~/downloads$ cd sphinxcontrib_matlabdomain-0.X ~/downloads/sphinxcontrib_matlabdomain-0.X$ python setup.py install
要求
这个包是Sphinx的扩展。
用法
一般情况下,用法与编写python代码的用法相同。
配置
在sphinx conf.py文件中,将sphinxcontrib.matlab添加到 分机。要使用自动文档功能,还可以添加sphinx.ext.autodoc 到扩展列表。
为了让sphinx的matlab域自动记录matlab源代码,设置 将matlab_src_dir的配置值添加到绝对路径,而不是添加 他们要sys.path。目前只能指定一个Matlab路径,但是 将搜索该树中的子文件夹。
为了方便起见primary domain 可以设置为mat。
角色和指令
请看Sphinx Domains和 sphinx.ext.autodoc用于 关于角色和指令使用的文档。可以记录Matlab代码 使用以下角色和指令:
Directive | MATLAB object |
---|---|
^{tt7}$ | folders, packages and namespaces |
^{tt8}$ |
|
^{tt9}$ |
|
^{tt10}$ |
|
^{tt11}$ | function definition and signature |
^{tt12}$ |
|
^{tt13}$ |
|
^{tt14}$ | script definition |
^{tt15}$ |
|
^{tt16}$ |
|
^{tt17}$ | class definition and optional signature |
^{tt18}$ |
|
^{tt19}$ |
|
^{tt20}$ | method definition and signature |
^{tt21}$ |
|
^{tt22}$ |
|
^{tt23}$ | static method definition and signature |
^{tt24}$ |
|
^{tt22}$ |
|
^{tt26}$ | property definition |
^{tt27}$ |
|
^{tt28}$ |
|
有几个选项可用于自动指令。
- :members:自动文档公共成员
- :show-inheritance:列表基
- :undoc-members:没有docstrings的文档成员
- :annotation:指定属性注释而不是默认值
还可以在conf.py中设置几个配置值,它们将 影响自动记录。
- autoclass_content可以设置为class、both或init,其中 确定将哪个docstring用于类。构造函数docstring 设置为init时使用。
- autodoc_member_order可以设置为alphabetical,groupwise或 bysource。
- autodoc_default_flags可以设置为要应用的选项列表。使用 no-flag指令选项禁用此配置值一次。
注意
模块角色和指令为Matlab创建一个psuedo命名空间 对象,类似于包。它们表示文件夹的路径 包含Matlab对象。如果未指定模块,则Sphinx将 假设对象是内置的。
示例:给定文件夹test_data中的以下Matlab源代码:
classdef MyHandleClass < handle & my.super.Class % a handle class % % :param x: a variable %% some comments properties x % a property end methods function h = MyHandleClass(x) h.x = x end function x = get.x(obj) % how is this displayed? x = obj.x end end methods (Static) function w = my_static_function(z) % A static function in :class:`MyHandleClass`. % % :param z: input z % :returns: w w = z end end end
使用以下文档:
Test Data ========= This is the test data module. .. automodule:: test_data :mod:`test_data` is a really cool module. My Handle Class --------------- This is the handle class definition. .. autoclass:: MyHandleClass :show-inheritance: :members:
在线演示
存储库中的测试文档位于以下位置: http://bwanamarko.alwaysdata.net/matlabdomain/
注意
sphinx样式标记用于记录参数、类型、返回和 例外情况。在 参数说明。当前只有在 它们位于属性定义后面的同一行。吸气剂和 setter方法与当前的方法类似,但dot是 替换为下划线。属性的默认值表示为 Unicode字符串,因此字符串将被双引号括起来。