1#!/usr/bin/env python3 2 3# -------------------------------------------------------------------- 4 5 6# -------------------------------------------------------------------- 7 8try: 9 from docutils.nodes import NodeVisitor 10 11 NodeVisitor.unknown_visit = lambda self, node: None 12 NodeVisitor.unknown_departure = lambda self, node: None 13except ImportError: 14 pass 15 16try: # epydoc 3.0.1 + docutils 0.6 17 from docutils.nodes import Text 18 from UserString import UserString 19 20 if not isinstance(Text, UserString): 21 22 def Text_get_data(s): 23 try: 24 return s._data 25 except AttributeError: 26 return s.astext() 27 28 def Text_set_data(s, d): 29 s.astext = lambda: d 30 s._data = d 31 32 Text.data = property(Text_get_data, Text_set_data) 33except ImportError: 34 pass 35 36# -------------------------------------------------------------------- 37 38from epydoc.docwriter import dotgraph 39from epydoc import docstringparser as dsp 40 41import re 42import sys 43import os 44import epydoc.cli 45 46dotgraph._DOT_VERSION_RE = re.compile(r'dot (?:- Graphviz )version ([\d\.]+)') 47 48try: 49 dotgraph.DotGraph.DEFAULT_HTML_IMAGE_FORMAT = 'png' 50 51except AttributeError: 52 DotGraph_to_html = dotgraph.DotGraph.to_html 53 DotGraph_run_dot = dotgraph.DotGraph._run_dot 54 55 def to_html(self, image_file, image_url, center=True): 56 if image_file[-4:] == '.gif': 57 image_file = image_file[:-4] + '.png' 58 if image_url[-4:] == '.gif': 59 image_url = image_url[:-4] + '.png' 60 return DotGraph_to_html(self, image_file, image_url) 61 62 def _run_dot(self, *options): 63 if '-Tgif' in options: 64 opts = list(options) 65 for i, o in enumerate(opts): 66 if o == '-Tgif': 67 opts[i] = '-Tpng' 68 options = type(options)(opts) 69 return DotGraph_run_dot(self, *options) 70 71 dotgraph.DotGraph.to_html = to_html 72 dotgraph.DotGraph._run_dot = _run_dot 73 74# -------------------------------------------------------------------- 75 76 77_SIGNATURE_RE = re.compile( 78 # Class name (for builtin methods) 79 r'^\s*((?P<class>\w+)\.)?' 80 + 81 # The function name 82 r'(?P<func>\w+)' 83 + 84 # The parameters 85 r'\(((?P<self>(?:self|cls|mcs)),?)?(?P<params>.*)\)' 86 + 87 # The return value (optional) 88 r'(\s*(->)\s*(?P<return>\S.*?))?' 89 + 90 # The end marker 91 r'\s*(\n|\s+(--|<=+>)\s+|$|\.\s+|\.\n)' 92) 93 94 95dsp._SIGNATURE_RE = _SIGNATURE_RE 96 97# -------------------------------------------------------------------- 98 99 100def epydocify(): 101 dirname = os.path.dirname(__file__) 102 config = os.path.join(dirname, 'epydoc.cfg') 103 sys.argv.append('--config=' + config) 104 epydoc.cli.cli() 105 106 107if __name__ == '__main__': 108 epydocify() 109 110# -------------------------------------------------------------------- 111