Documenting files with "from x import *"

Can sphinx .. automodule :: and other automatic functions be used to document modules that include from x import * statements, not including all documentation from imported modules?

EDIT: According to the point mzjn, if the attribute of the imported __module__ methods __module__ not match the module name, they should not be documented. However, for some of my modules they are.

my MLE is just a test_doc.py file with the following line:

 from pylab import * 

and documentation:

 .. automodule:: agpy.test_doc :members: 

If I include this line in test_doc.py :

 print "beta.__module__:",beta.__module__ 

I get the expected result:

 beta.__module__: None 

Any idea what is going on? Can I screw something in conf.py ?

EDIT: workaround, according to mzjn's answer, change the __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' 
+4
source share
1 answer

Yes, that should work. From the documentation :

In a module directive with a set of member options, only module members will be documented, the __module__ attribute of which is equal to the module name provided to the module. This is to prevent the documentation of imported classes or functions.


Update:

The problem is that the __module__ attribute for many pylab members is None (the members defined in the C / Cython mtrand , as far as I can tell).

The mtrand module is part of NumPy. Behind the scenes, pylab.beta (and several other functions) is a method of the numpy.random.mtrand.RandomState class. I can reproduce the documentation problem as follows:

With this source (pylabtest.py)

 from pylab import beta def mzjn(x): """mzjn docstring""" return x 

and this source documentation (pylabtest.rst)

 Pylab test ========== .. automodule:: pylabtest :members: 

Sphinx output in pylabtest.html includes both beta and mzjn .

But if

 beta.__module__ = "pylab" 

added to pylabtest.py, only mzjn documented.

+4
source

Source: https://habr.com/ru/post/1387616/


All Articles