We have a module, in which each class file is in a file starting with an underscore. In the init.py, we import these files, and we expose constructor functions for each class (this is necessary as each class constructor needs some additional state that we don't want users of the module to need to bother with).
E.g. we may have _foo.py with:
class Foo(object):
def __init(context, params):
...
and in init.py we have:
from ._foo import Foo as _Foo
def foo(params):
return _Foo(_getContext(), params)
I'm trying to generate documentation with Sphinx autodoc for this. I obviously want documentation to be generated for Foo and its methods (although preferably not its constructor), as well as for the foo() constructor wrapper.
I can get Sphinx to generate docs for foo() but can't seem to get it to generate anything for Foo. I've tried:
.. automodule:: foo_module
:members:
as well as:
.. autoclass:: foo_module.Foo
:members:
but to no avail. The former just includes foo(); the latter gives me an error:
index.rst:17: WARNING: autodoc: failed to import class u'Foo' from module u'foo_module'; the following exception was raised:
Traceback (most recent call last):
File "/python2.7/site-packages/sphinx/ext/autodoc.py", line 342, in import_object
obj = self.get_attr(obj, part)
File "/python2.7/site-packages/sphinx/ext/autodoc.py", line 241, in get_attr
return safe_getattr(obj, name, *defargs)
File "/python2.7/site-packages/sphinx/util/inspect.py", line 114, in safe_getattr
raise AttributeError(name)
AttributeError: Foo
Is there a way around this?