4 Convert simple documentation to epydoc/pydoctor-compatible markup
7 from sys import stdin, stdout, argv
9 from tempfile import mkstemp
10 from subprocess import call
14 spaces = re.compile( r'\s+' )
15 singleLineExp = re.compile( r'\s+"([^"]+)"' )
16 commentStartExp = re.compile( r'\s+"""' )
17 commentEndExp = re.compile( r'"""$' )
18 returnExp = re.compile( r'\s+(returns:.*)' )
25 "Change foo: bar to @foo bar"
26 result = re.sub( r'(\w+):', r'@param \1', line )
27 result = re.sub( r' @', r'@', result)
30 def fixReturns( line ):
31 "Change returns: foo to @return foo"
32 return re.sub( 'returns:', r'@returns', line )
36 match = spaces.match( line )
40 indent = match.group(0)
41 if singleLineExp.match( line ):
42 return re.sub( '"', '"""', line )
43 if commentStartExp.match( line ):
46 line = fixReturns( line )
47 line = fixParam( line )
48 if commentEndExp.search( line ):
54 "Test transformations"
55 assert fixLine(' "foo"') == ' """foo"""'
56 assert fixParam( 'foo: bar' ) == '@param foo bar'
57 assert commentStartExp.match( ' """foo"""')
62 ' "Single line comment"\n'
63 ' """This is a test"""\n'
73 def fixLines( lines, fid ):
75 os.write( fid, fixLine( line ) )
77 if __name__ == '__main__':
80 infile = open( argv[1] )
81 outfid, outname = mkstemp()
82 fixLines( infile.readlines(), outfid )
85 call( [ 'doxypy', outname ] )