2014-03-28 66 views
6

我一直在試圖記錄我的基於MongoEngine的應用程序,但我在記錄我的文檔類的屬性時遇到問題。獅身人面像類屬性文檔

我已經採取了正確的語法,這樣做是:

class Asset(Document): 
    #: This is the URI of the document 
    uri = StringField() 

我已經試過記錄我發現,甚至補充說,是不是MongoEngine屬性這些屬性的各種方式字段只是爲了確保這不是問題:

class Asset(Document): 
    """ 
    The representation of a file uploaded into the data store. 
    """ 

    #: This is a test attribute. 
    foo = 'bar' 
    """baz?""" 

    #: This is a URI. 
    uri = StringField(required=True) 
    """This is a URI """ 

我已經試過各種指令在相應的.rst文件中的各種組合。目前,它看起來像這樣:

.. currentmodule:: mymodule.asset 
.. autoclass:: Asset 
.. autoattribute:: Asset.foo 
.. autoattribute:: Asset.uri 

輸出不是很滿意:foo的屬性沒有顯示在所有文件和URI領域擁有MongoEngine的「Unicode字符串場。」 (StringField類的文檔)作爲文檔。此外,屬性文檔不會放在類下「(與automodule +:成員: - 使用它們的MongoEngine描述輸出所有字段)

我錯過了Sphinx Extension嗎?或者我搞砸了語法?

回答

0

事實證明,這個問題是由別的東西造成的,除了mzjn的回答是:我不得不完全限定類我是..autoclass::荷蘭國際集團,因爲我爲..currentmodule::指定的模塊被導入使用from x import y語法爲它工作,即語法如下工作:

.. currentmodule: mymodule.asset 
.. autoclass: mymodule.asset.Asset 
    :members: 

長話短說:檢查進口!

7

獲取類的成員進入文檔,使用:members:選項:

.. autoclass:: Asset 
    :members: 

沒有:members:only the class docstring插入。

另請參閱autodoc_default_flags配置選項。


你可以得到相同的結果與上面autoattribute並沒有:members:(注意壓痕):

.. autoclass:: Asset 

    .. autoattribute:: foo 
    .. autoattribute:: uri 

使用文檔字符串我無法重現的問題,即uri屬性被記錄在案來自StringField。

我正在使用Sphinx 1.2.2。

+0

嗨,這是問題的一部分,我已經添加了一個自己的答案[這裏](http://stackoverflow.com/a/23086206/660848)修復了這個問題,並且還提出了「sphinx.ext .viewcode「擴展工作。萬歲! :) – wonderb0lt