[Doc-SIG] gendoc 0.71 patch

Andrew Kuchling akuchlin@cnri.reston.va.us
Mon, 11 May 1998 09:56:10 -0400 (EDT)


I grabbed a copy of gendoc 0.71 this weekend in order to look at
adding a TeX formatter, and found I had to make various changes just
to get things to work.  Patch included below.

	My motivation for adding a TeX formatter is for the ongoing
XML work; some of it has very good docstrings which could make up the
docs, so I'd like to modify gendoc to output LaTeX code suitable for
the Library Reference (or similar documents such as HOWTOs).  Adding
TeX output that uses '\code{' and '}' instead of '<code>' and
'</code>' wasn't difficult, but the output doesn't look anything like
the usual docs because the structure is different; there are things
like \section SYNOPSIS, instead of \section{gendoc module}.  The
document structure hard-wired into the code is different from that in
the LaTeX docs.

	Any suggestions about the approach that should be taken to fix
this?

	There are smaller issues; in LaTeX we want to do more detailed 
markup, such as \class{Message} and \function{input()}, but perhaps
that will have to be left to manual editing afterwards. 

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
Ambition has but one reward for all: / A little power, a little transient
fame, A grave to rest in, and a fading name.
    -- William Winter

diff -r -C2 /scratch/gendoc/formatters/Formatters.py gendoc/formatters/Formatters.py
*** /scratch/gendoc/formatters/Formatters.py	Wed Feb  4 09:19:42 1998
--- gendoc/formatters/Formatters.py	Sun May 10 10:18:01 1998
***************
*** 141,145 ****
  
  def main(path):
!     files = reduce(lambda c, dir: c+os.listdir(dir), path, [])
      modules = filter(lambda file: file[-3:] == '.py', files)
  
--- 141,146 ----
  
  def main(path):
!     files = os.listdir(path+"")
! #    files = reduce(lambda c, dir: os.listdir(c+dir), path, [])
      modules = filter(lambda file: file[-3:] == '.py', files)
  
diff -r -C2 /scratch/gendoc/formatters/MIFFormatter.py gendoc/formatters/MIFFormatter.py
*** /scratch/gendoc/formatters/MIFFormatter.py	Wed Feb  4 10:16:38 1998
--- gendoc/formatters/MIFFormatter.py	Sun May 10 10:19:18 1998
***************
*** 63,67 ****
  import string
  import regsub
! from gendoc import docregex
  
  # Rename imported objects.
--- 63,67 ----
  import string
  import regsub
! import docregex
  
  # Rename imported objects.
Only in gendoc/formatters: TeXFormatter.py
diff -r -C2 /scratch/gendoc/formatters/__init__.py gendoc/formatters/__init__.py
*** /scratch/gendoc/formatters/__init__.py	Wed Feb  4 07:03:38 1998
--- gendoc/formatters/__init__.py	Sun May 10 10:44:50 1998
***************
*** 1,2 ****
  import Formatters
! Formatters.main(__path__)
--- 1,2 ----
  import Formatters
! Formatters.main(__path__[0])
diff -r -C2 /scratch/gendoc/gendoc gendoc/gendoc
*** /scratch/gendoc/gendoc	Wed Feb  4 03:16:26 1998
--- gendoc/gendoc	Sun May 10 10:17:42 1998
***************
*** 7,9 ****
  
  import gendoc.gendoc
! gendoc.gendoc.main()
--- 7,9 ----
  
  import gendoc.gendoc
! gendoc.gendoc.main_parseopts()
diff -r -C2 /scratch/gendoc/gendoc.py gendoc/gendoc.py
*** /scratch/gendoc/gendoc.py	Wed Apr  1 03:59:40 1998
--- gendoc/gendoc.py	Sun May 10 10:36:35 1998
***************
*** 164,167 ****
--- 164,168 ----
      # Process command line arguments
      try:
+ 	if len(sys.argv) == 1: raise getopt.error, "No arguments provided"
  	optlist, args = getopt.getopt(sys.argv[1:], '?ipuvd:h:f:')
      except getopt.error, str:
***************
*** 192,206 ****
  	    include_private_methods = 1
  	elif opt[0] == '-f':
! 	    try:
! 		formats.append(Formatters.formatters[opt[1]]())
! 	    except KeyError, key:
! 		print "Couldn't find a %s formatter (is it in the formatters subdir?)" % key
! 		frmtrs = reduce(lambda c, i: c+', '+i, Formatters.formatters.keys())
! 		print "Valid formatters are:", frmtrs
! 		sys.exit(0)
! 
  
      if not formats:
! 	formats = [Formatters.formatters['HTML']()]
  
      # Arguments in the '<key>=<value>' style are stripped, and stored in
--- 193,200 ----
  	    include_private_methods = 1
  	elif opt[0] == '-f':
! 	    formats.append( opt[1] )
  
      if not formats:
! 	formats = ['HTML']
  
      # Arguments in the '<key>=<value>' style are stripped, and stored in
***************
*** 231,235 ****
  	main(args, formats, head, parse, VERBOSE)
      except GendocException, x:
- 	import sys
  	sys.stderr.write(x)
  	sys.exit(0)
--- 225,228 ----
***************
*** 336,340 ****
  	import parser
      except:
- 	import sys
  	sys.stderr.write('You must include the parser module in your Setup\n')
  	sys.stderr.write('to run in parser mode!\n')
--- 329,332 ----
***************
*** 352,356 ****
  	    ast_tuple = parser.ast2tuple(parser.suite(text))
  	except:
- 	    import sys
  	    sys.stderr.write("Sorry, got a syntax error when parsing %s\n" % file)
  
--- 344,347 ----
***************
*** 420,424 ****
  	file = open(os.path.join(directory, filename), 'w')
      except IOError, str:
- 	import sys
  	sys.stderr.write("%s: %s" % (os.path.join(directory, filename), str))
  	sys.exit(1)
--- 411,414 ----
***************
*** 430,432 ****
  
  if __name__ == '__main__':
! 	main()
--- 420,422 ----
  
  if __name__ == '__main__':
! 	main_parseopts()