Documenting a package with Pydoc

R

Rob Cowie

I have searched this group and the wider net to find an answer to this,
but I haven't been successful.

Pydoc seems to be capable of writing documentation for all modules
within a package by simply pointing it to the package on the command
line...

pydoc -w <packagename_without_/>

Certainly, the method writedocs() appears to descend into a directory
and create docs for each importable object.

Perhaps I'm doing something wrong but when I do this, pydoc reports
that no Python documentation can be found for each of the contents of
the package. Of course, if I point pydoc directly to the modules, it
succeeds.

Am I doing something wrong?

Cheers, Rob C
 
G

Gabriel Genellina

Pydoc seems to be capable of writing documentation for all modules
within a package by simply pointing it to the package on the command
line...

pydoc -w <packagename_without_/>

Certainly, the method writedocs() appears to descend into a directory
and create docs for each importable object.

Perhaps I'm doing something wrong but when I do this, pydoc reports
that no Python documentation can be found for each of the contents of
the package. Of course, if I point pydoc directly to the modules, it
succeeds.

Am I doing something wrong?

That appears to be a bug. In pydoc.writedocs, when iterating over the
package directory contents, it uses inspect.getmodulename(path). That
returns the bare filename (without path nor extension) (is it ok???),
and later the resolve() function can't load the module because it
lacks package information.

For simple cases this patch may work: In writedocs, add the following
line at the beginning:
if pkgpath=='' and ispackage(dir): pkgpath = os.path.basename(dir) + '.'

This works for top level packages located at sys.path, but not for
packages located elsewhere.

By example, I can generate now the docs for pychart:

python c:\apps\python\lib\pydoc.py -w c:\apps\python\lib\site-packages\pychart



Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
R

Rob Cowie

Gabriel said:
That appears to be a bug. In pydoc.writedocs, when iterating over the
package directory contents, it uses inspect.getmodulename(path). That
returns the bare filename (without path nor extension) (is it ok???),
and later the resolve() function can't load the module because it
lacks package information.
I don't think this is a bug; inspect.getmodulename(path) does indeed
return a bare filename, but this is later augmented with the pkgpath.

I also can't find a resolve() function. Perhaps we have different
versions? I have revision 1.38.
For simple cases this patch may work: In writedocs, add the following
line at the beginning:
if pkgpath=='' and ispackage(dir): pkgpath = os.path.basename(dir) + '.'

This works for top level packages located at sys.path, but not for
packages located elsewhere.

By example, I can generate now the docs for pychart:

python c:\apps\python\lib\pydoc.py -w c:\apps\python\lib\site-packages\pychart



Gabriel Genellina
Softlab SRL
Thanks,

Rob C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,176
Latest member
Jerilyn201
Top