使用"from x import *"记录文件 [英] Documenting files with "from x import *"
问题描述
sphinx的.. automodule ::和其他自动功能可以用于记录包含 from x import *
语句的模块,而不包含所有来自导入模块的文档吗?
根据 mzjn 的观点,只要导入方法的 __module__
属性与模块名称不同,就不应该记录它们.但是,对于我的某些模块,它们是.
我的 MLE 只是一个带有以下行的 test_doc.py
文件:
from pylab import *
和文档:
.. automodule :: agpy.test_doc:成员:
如果我在 test_doc.py
中包含这一行:
print "beta.__module__:",beta.__module__
我得到了预期的结果:
beta .__ module__:无
知道发生了什么吗?我可以在 conf.py
中搞砸吗?
根据 mzjn 的回答,一种解决方法是更改那些具有 __module__==None
的函数的 __module__
属性:
导入pylab从 pylab 导入 *对于 pylab.__dict__.iteritems() 中的 k,v:如果hasattr(v,'__ module__'):如果 v.__module__ 是 None:locals()[k].__module__ = 'pylab'
是的,应该可以.从文档:
<块引用>在设置了members选项的automodule指令中,仅记录其 __ module __
属性等于给automodule的模块名称的模块成员.这是为了防止记录导入的类或函数.
<小时>
更新:
问题似乎是许多pylab
成员的__module__
属性是None
(C/Cython模块中定义的成员<据我所知,是code> mtrand .
和此源文档(pylabtest.rst) pylabtest.html 中的 Sphinx 输出包括 但是如果 已添加到pylabtest.py中,仅记录了 Can sphinx's .. automodule:: and other automatic features be used to document modules that include EDIT:
As per mzjn's point, as long as the imported methods' my MLE is just a file and the documentation: If I include this line in I get the expected result: Any idea what's going on? Could I have screwed something up in EDIT: A workaround, as per mzjn's answer, to change the
Yes, that should work. From the documentation: In an automodule directive with the members option set, only module members whose
Update: The problem seems to be that the The With this source (pylabtest.py) and this source documentation (pylabtest.rst) the Sphinx output in pylabtest.html includes both But if is added to pylabtest.py, only 这篇关于使用"from x import *"记录文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!mtrand
模块是 NumPy 的一部分.在幕后,pylab.beta
(和其他几个函数)是
Pylab测试==========.. automodule :: pylabtest:成员:
beta
和 mzjn
.
beta .__ module__ ="pylab"
mzjn
.from x import *
statements without including all of the documentation from imported modules?__module__
attribute are not the same as the module name, they shouldn't be documented. However, for some of my modules, they are.test_doc.py
file with the following line:from pylab import *
.. automodule:: agpy.test_doc
:members:
test_doc.py
:print "beta.__module__:",beta.__module__
beta.__module__: None
conf.py
?__module__
attribute of those functions that have __module__==None
:import pylab
from pylab import *
for k,v in pylab.__dict__.iteritems():
if hasattr(v,'__module__'):
if v.__module__ is None:
locals()[k].__module__ = 'pylab'
__module__
attribute is equal to the module name as given to automodule will be documented. This is to prevent documentation of imported classes or functions.
__module__
attribute of many pylab
members is None
(the members defined in the C/Cython module mtrand
, as far as I can tell).mtrand
module is part of NumPy. Behind the scenes, pylab.beta
(and several other functions) is a method of the class numpy.random.mtrand.RandomState
. I can reproduce the documentation issue as follows:from pylab import beta
def mzjn(x):
"""mzjn docstring"""
return x
Pylab test
==========
.. automodule:: pylabtest
:members:
beta
and mzjn
. beta.__module__ = "pylab"
mzjn
is documented.