Module and program to extract documentation strings from modules and transform them into documents of various formats. These formats are currently:
This file may be either used as a program or as an imported module.
When used as a program, the synopsis is
For usage as an imported module refer to the functions pymanual_latex and pymanual_htb .
Professionally, I use the programming languages C/C++, C# and JAVA. On these programming languages, the tool doxygen is available for in-source-documentation. Being able to produce comprehensible documentation of classes and functions directly within the source code proved to be extremely valuable.
pymanual.py is yet another approach to extend the usability of documentation strings. The program recognizes each occurance of a function name or a class name and produces hyperlinks to the corresponding documentation. pymanual.py allows the specification of section, item lists, enumerations, and description lists. Inlined code fragments may be highlighted. The program also recognizes parts of the documentation string that obviously have been added for use by module doctest .
pymanual does not produce any diagrams but
Modules, classes, and funtions providing pymanual documentation may also specifiy some limited degree of meta information on authors, version, and copyright that will be displayed in the documentaton (cf.) However, like pydoc this program requires the imported modules to be compilable (since modules to be documented will be imported before producing any ouput).
Text formatting with pymanual.py aims mainly at achieving two goals:
Linebreaks in the original plain text will not break lines in the richly formatted documentation. As an exception of this general rule, empty lines introduce new text paragraphs in the richly formatted documentation.
Use the lower than (<) and the larger than characters to embrace a single word that shall be highlighted as a code fragment (a file, class or function name). Use two lower than and greater than characters to embrace code fragments containing more than one word within the same line of the plain text source of the documentation. Note, that names of also documented modules, classes, and functions will recognized by the system. So, embracing such words is optional but recommended, to enhance comprehensibleness of the plain text. Inlined code fragments are usually presented in bold letters. Inlined code fragments are often printed in true type letters. However, using bold letters instead results into a much more harmonic text layout.
Analogously, "<!" and "!>" might be used to embrace emphasized text passages. These passages are usually printed in italics.
pymanual supports item lists, enumerations, and description lists. Use the star (*) to introduce an item of an item list as the first character of a new line in the original plain text. The double cross (#) specifies a new item of an enumeration. To specify a new item in a description list, type the name of the description (a single word) followed by a colon (:). If the name of the description consists of more than one word, use the underscore (_) as separator. The rest of the line in the plain text is considered to hold text describing the item. If the next lines start with a colon, they will also be added to the description of the item.
Each item may contain additional item lists, enumerations, or description lists. To start an encapsulated item list, start the line in the plain text source with a colon directly followed by s start (:*). Use ":#" to start a new enumeration or "item_name:" to start a description list start with a description on "item name".
Example:
Plain text source of the example:
<!Example:!> * an <<item>> : <<covering two lines>> in the original plain text documentation. :# encapsulated enumeration item 1. :# encapsulated enumeration item 2. ::description_item1: This is a part of the enumeration. :description_item2: This is a part of the item list. description_item3: This is indention level 0. description_item4: This also.
In addition to inlined code fragments that typically consist of single program symbols or short expressions, program documentations usually contain longer code fragments to present source code examples or preformatted text to show for instance text examples for configuration files etc.
This is some preformatted text. The content is presented in true type letters. Preceed each line containing preformatted text with a bar '|'.Original plain text of the example above:
| This is some preformatted text. | The content is presented in true type letters. | Preceed each line containing preformatted text with a bar '|'.
Source code occurs in Python documentations for two purposes:
>>> 2+2 # a Python expression
4
>>> # in this mode you have to provide the result of an expression
>>> # since module doctest looks for prompts in the documentation
>>> # an will report errors if results are missing.
>>> context=FormattingContext(pymanual)
>>> # names of modules, classes, functions, and methods will also be
>>> # recognized in this mode.
>>>
>>> # leave this mode by an empty line in the plain text documentation.
In plain text, this example looks as follows:
>>> 2+2 # a Python expression 4 >>> # in this mode you have to provide the result of an expression >>> # since module doctest looks for prompts in the documentation >>> # and will report errors if results are missing. >>> context=FormattingContext(pymanual) >>> # names of modules, classes, functions, and methods will also be >>> # recognized in this mode. >>> >>> # leave this mode by an empty line in the plain text documentation.If you intend to use doctest , you may want to present code snippets that you do not want to be evaluated by doctest . In such cases you should use "|>>" instead of the standard Python prompt ">>>". This keyword will result into exactly the same formatted documentation but will be ignored by doctest .
|>> 2+2 # a simple Python expression
5
|>> # the example above presents an obvously wrong result. however,
|>> # it will not be tested anyway.
|>> pymanual_htb(['pymanual'], '.','HTB', FormatterHTB.m_englishPattern, FormatterHTB.m_englishTexts, FormatterHTB.m_englishTitle [])
|>> # modules, functions, and classes will also be recognized in this mode.
Longer texts (like this one) should be organized in sections. pymanual.py supports three levels of sections. Embrace the headline of a section in the plain text documentation with " == ", " == = ", or " == == " to start a new section. For instance, the headline of this section has been produced by
=== Sectioning, Referencing, Indexing ===
Please note, that this three levels have to be mapped to sectioning levels provided by the used rich format. For instance, in LaTeX documents level, " == = " on modules is a subsubsection and on methods it is a paragraph .
A documentation may contain cross references to sections within the same documentation string. Therefore, a label has to be attached to a section. Labels are strings composed of letters and numbers serving as an identifier for a section. For instance, this section has the label refs . This label has been defined in the headline:
refs:=== Sectioning, Referencing, Indexing ===Now, each text within this documentation string may refer to this section (cf.) using the markup tag :ref[refs] . Please refer to (cf.) for current limitations of tags in pymanual.py in general and limitations of the ref markup tag in particular.
For the sake of comprehensibleness of the plain text documentation, pymanual.py provides only few tags, in fact only two. The other one is for producing a hierarchical index. pymanual.py produces an hierarchical index on modules, classes, functions, and methods automatically. However, documentation on source code may introduce additional notation for instance on domain concepts that should be listed in the index. This can be achieved by use of tag index . This paragraph contains the tag :index[index|example] . As a consequence, the hierarchical index of this document comprises the key word "index" with aspect "example" associated with a link to this paragraph.
pymanual.py analyses three sources of information. Two of these sources have been the issue of the previous sections.
Information on author, copyright, and version is inherited as usual in Python. Usually, information on these topics will only be presented if it changes. For instance in this file, only the pymanual module provides information on author, copyright, and version. So, this information will not be listed for functions and classes.
(c) 2005, 2006 Dr. Harald Meyer auf'm Hofe, D-67663 Kaiserslautern, Germany
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA