Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell PyDoc to generate documentation to user defined directory

Tags:

python

pydoc

PyDoc creates HTML documentation in current directory when generating documentation of modules. I really need to specify another directory which will be a placeholder for generated documentation instead the directory from which PyDoc is called.

I am using python -m pydoc -w <MODULES_DIR> to generate documentation.

Is this possible and if it is, how?

like image 213
Hrvoje Varga Avatar asked Sep 11 '11 18:09

Hrvoje Varga


1 Answers

I had the same issue and came across this question trying to figure it out. I couldn't figure out how to do it either, so this is my solution. Rather than try to trick pydoc to outputting to a specific location, I'm just generating the documentation in the current directory and moving the files to the location I want.

In my case, the target folder is named 'doc', and the source is located under the 'semlm' directory

mkdir -p doc
pydoc -w `find semlm -name '*.py'`
mv *.html doc

(You should be able to customize the pydoc command as you wish, but this is what worked for me).

I didn't want to type this all out every time so I put it in a Makefile. Here is an excerpt:

.PHONY: doc

doc:
    mkdir -p doc
    pydoc -w `find semlm -name '*.py'`
    mv *.html doc

The .PHONY: doc is needed because the Makefile target has the same name as a folder in the top level directory (i.e. 'doc'). Now I can generate documentation into the doc folder by running:

make doc

Perhaps there is a more elegant way, but this is the best I've found so far.

like image 135
blambert Avatar answered Sep 28 '22 08:09

blambert