python sphinx变量和类属性在automodule中 [英] python sphinx variables and class properties in automodule

查看:1352
本文介绍了python sphinx变量和类属性在automodule中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么在sphinx中使用automodule指令时无法看到类属性?



即使属性具有docstring



与django设置相同的事情CONSTANTS,它们没有显示。



我使用:

  .. automodule :: settings 
:member:
:show-inheritance:
:undoc-members:

我将设置分成模块



设置




  • __ init __。py

  • installed_apps.py

  • locale.py

  • db.py

  • cache.py

  • stage_stable.py

  • stage_test.py

  • stage_dev.py

  • ...

  • 模板.py



在__init__.py中,我从其他文件导入所有内容,并选择在哪个阶段我



它与django配合使用,简化了设置修改,...不适用于sphinx:{

解决方案

docstrings通常不适用于类属性,但是Sphinx的autodoc扩展可以在字段后面。您还可以在字段之前使用此特殊语法:

 #:my_field的文档。你可以
#:也可以使用一行或多行。
my_field =something

其他需要检查的事项是您已将autodoc扩展名列出在 conf.py 文件中。寻找 extensions = [sphinx.ext.autodoc] 。 (该列表可能包含多个扩展名。)



我以前在错误的地方提供了文档注释。与docstring不同的是,

由于上述不是问题,这里有另一种可能性。您的文档中必须可以访问 .. automodule :: 之后使用的模块或软件包。这意味着您需要确保将其位置添加到Python路径。我的项目设置如下:

  my_project / 
package /
__init__.py
...
doc /
build /
...
source /
conf.py
...

在这种情况下,我需要将 / my_package 添加到Python路径中我可以访问。为了做到这一点,我确定这是我的 conf.py 的顶部:

 code> import sys,os#我相信conf.py已经导入了sys,
import os.path#os和os.path。但是为了防止这种情况,我在这里列出了
#。

sys.path.insert(0,os.path.abspath(os.path.join('..','..')))

这有效地将 ./../ .. 添加到Python路径中,从conf我的例子中的.py是 my_project 目录。 (我也解决了一个绝对的道路,所以有更少的惊喜的可能性。)显然,你必须改变这个为你的具体情况。



我希望这有助于您。


I am wondering why I am not able to see class properties when using automodule directive in sphinx...

even if properties has docstring

same thing with django settings CONSTANTS, they are not shown.

I use:

.. automodule:: settings
   :members:
   :show-inheritance:
   :undoc-members:

I split settings into module

settings

  • __init__.py
  • installed_apps.py
  • locale.py
  • db.py
  • cache.py
  • stage_stable.py
  • stage_test.py
  • stage_dev.py
  • ...
  • templates.py

and in __init__.py i import everything from other files and select on which stage am I

it works with django, simplifies settings modification and... does not work with sphinx :{

解决方案

docstrings normally don't apply to class properties, but the autodoc extension to Sphinx is able to if you put it after the field. You can also use this special syntax, before the field:

#: Documentation for my_field.  You can
#: use one or more lines as well.
my_field = "something"

Other things to check are that you have the autodoc extension listed in the conf.py file. Look for extensions = ["sphinx.ext.autodoc"]. (The list may contain more than one extension.)

[edit:] I previously had the documentation comment in the wrong place. Unlike the docstring, the #: comments have to go before the field you are commenting.

[edit:] Since the above isn't the problem, here's another possibility. The module or package you use after .. automodule:: must be accessible to your documentation. This means you need to make sure you add its location to your Python path. My project is set up like this:

my_project/
    package/
        __init__.py
        ...
    doc/
        build/
            ...
        source/
            conf.py
            ...

In this case, I needed to add /my_package to the Python path so I could access package. To do so, I made sure this was in the top of my conf.py:

import sys, os   # I believe conf.py already imports sys,
import os.path   # os, and os.path.  But just in case, I
                 # list it here.

sys.path.insert(0, os.path.abspath(os.path.join('..','..')))

This effectively adds ./../.. to the Python path, which from conf.py in my example is the my_project directory. (I also resolve it to an absolute path just so there are fewer possibilities for surprises.) Obviously, you'd have to change this for your specific case.

I hope this helps you out.

这篇关于python sphinx变量和类属性在automodule中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆