views:

576

answers:

5

I'm about to start a project where I will be the only one doing actual code and two less experienced programmers (scary to think of myself as experienced!) will be watching and making suggestions on the program in general.

Is there a good (free) system that I can use to provide documentation for classes and functions based on the code I've written? It'd likely help them a lot in getting to grips with the structure of the data.

+11  A: 

I have used epydoc to generate documentation for Python modules from embedded docstrings. It's pretty easy to use and generates nice looking output in multiple formats.

Greg Hewgill
epydoc is really good. Except that, I didn't find a way to get around method signatures if the methods are decorated. The doc shows wrong method signatures if it is decorated. The temporary solution is- I disable introspection while generating docs and do only parsing. Do you know a way around it?
JV
+10  A: 

python.org is now using sphinx for it's documentation.

I personally like the output of sphinx over epydoc. I also feel the restructured text is easier to read in the docstrings than the epydoc markup.

JimB
Agreed. Also, the fact that the standard library is using it makes it a de-facto standard in my mind.
cdleary
I tried using sphinx, but it seemed like another kindof markup to be learned in itself, before it can be used. Since you said you like it, can you give me link for some kind of easy tutorial for it? I would like to give it another shot.
JV
@JV - I haven't used sphinx a lot, but I have spent hours looking at the documents it generates. It is another kind of markup, but it's based on reStructuredText, which is fairly common (and IMHO, intuitive). I found their docs very good - but I did have to sit down and read through them all.
JimB
Sphinx doesn't do automatic API generation like epydoc does though.
dowski
@dowski: Sphinx has an `autodoc` plugin which allows you to extract documentation from docstrings.
Martin Geisler
+2  A: 

See answers to can-i-document-python-code-with-doxygen-and-does-it-make-sense, especially those mentioning Epydoc and pydoctor.

gimel
+4  A: 

Sphinx can be useful for generating very verbose and informative docs that go above and beyond what simple API docs give you. However in many cases you'll be better served to use a wiki for these kind of documents. Also consider writing functional tests which demonstrate the usage of your code instead of documenting in words how to use your code.

Epydoc is very good at scanning your docstrings and looking at your code to generate API documents but is not necessarily good at giving much more in-depth information.

There is virtue to having both types of documentation for a project. However if you get in a time crunch it is always more beneficial to have good test coverage and meaningful tests than documentation.

mcrute
I agree on putting Design Doco in wiki. Links allow you to cross-reference requirements to code and tests by embedding links/URLs everywhere. Wiki is easy to write, and everyone can maintain it. Versioning and edit-contention are handled automatically (in many wiki packages). Most wiki packages are cross-platform, and FREE! <p/> I also agree on the benfits of automated tests. If a picture is worth 1000 words, an example has to be worth atleast 5000. <p/> Programers can and should communicate how-to-code in code ;-) Cheers. Keith.
corlettk
+2  A: 

I use Sphinx for my project, not only because it looks good, but also because Sphinx encourages writing documentation for humans to read, not just computers.

I find the JavaDoc-style documentation produced by tools like epydoc quite sad to read. It happens all too often that the programmer is mindlessly "documenting" arguments and return types simply because there would otherwise be a gap in the API docs. So you end up with code line this (which is supposed to look like Java, but it's been a while since I wrote Java, so it might not compile...)

/**
 * Set the name.
 *
 * @param firstName the first name.
 * @param lastName the last name.
 */
public void setName(String firstName, String lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

There is a very small amount of information in this so-called "documentation". I much prefer the Sphinx way where you (using the autodoc plugin) simply write

.. autofunction:: set_name

and Sphinx will then add a line to your documentation that says

set_name(first_name, last_name)

and from that every Python programmer should know what is going on.

Martin Geisler