Sections
Timeline
View Tickets
New Ticket
Sub-Sections
Download
Unified Diff
Zip Archive
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Changeset 45

Show
Ignore:
Timestamp:
24/06/07 05:55:07 (17 months ago)
Author:
gak
Message:

check to see if examples scripts are run from the command line (so epydoc can parse them without running them)

Location:
trunk/examples
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/basic.py

    r42 r45  
    3939        pass 
    4040 
    41 banana = Banana() 
    42 banana.eat() 
     41def main(): 
     42    banana = Banana() 
     43    banana.eat() 
     44    pycallgraph.make_dot_graph('basic.png') 
    4345 
    44 pycallgraph.make_dot_graph('basic.png') 
     46if __name__ == '__main__': 
     47    main() 
    4548 
    4649# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • trunk/examples/colours.py

    r42 r45  
    1 #!/usr/bin/env python 
     1    #!/usr/bin/env python 
    22""" 
    33pycallgraph 
     
    2525This example demonstrates several different methods on colouring your graph. 
    2626 
    27 See U{http://www.graphviz.org/doc/info/attrs.html#k:color} for details on how 
     27See U{http://www.graphviz.org/doc/info/attrs.html    #k:color} for details on how 
    2828to return colour formats to Graphviz. 
    2929""" 
     
    3333import pycallgraph 
    3434 
    35 # Do the trace, remember the values for later 
    36 pycallgraph.start_trace() 
    37 import HTMLParser 
    38 pycallgraph.stop_trace() 
     35def main(): 
     36    # Do the trace, remember the values for later 
     37    pycallgraph.start_trace() 
     38    import HTMLParser 
     39    pycallgraph.stop_trace() 
    3940 
    40 # Set the edge colour to black for all examples 
    41 pycallgraph.settings['edge_colour'] = lambda a, b: 'black' 
     41    # Set the edge colour to black for all examples 
     42    pycallgraph.settings['edge_colour'] = lambda a, b: 'black' 
    4243 
    43 # Default node colouring 
    44 pycallgraph.make_dot_graph('colours-default.png') 
     44    # Default node colouring 
     45    pycallgraph.make_dot_graph('colours-default.png') 
    4546 
    46 # Rainbow 
    47 def rainbow(calls, total_time): 
    48     """Colour using only changes in hue. 
     47    # Rainbow 
     48    def rainbow(calls, total_time): 
     49        """Colour using only changes in hue. 
    4950 
    50     It will go from 0 to 0.8 which is red, orange, yellow, green, cyani, blue 
    51     then purple. 
     51        It will go from 0 to 0.8 which is red, orange, yellow, green, cyani, blue 
     52        then purple. 
    5253 
    53     See U{http://en.wikipedia.org/wiki/Hue} for more information on hue. 
    54     """ 
    55     return '%f 0.8 0.8' % (calls * 0.8) 
     54        See U{http://en.wikipedia.org/wiki/Hue} for more information on hue. 
     55        """ 
     56        return '%f 0.8 0.8' % (calls * 0.8) 
    5657 
    57 pycallgraph.settings['node_colour'] = rainbow 
    58 pycallgraph.make_dot_graph('colours-rainbow.png') 
     58    pycallgraph.settings['node_colour'] = rainbow 
     59    pycallgraph.make_dot_graph('colours-rainbow.png') 
    5960 
    60 # Greyscale 
    61 def greyscale(calls, total_time): 
    62     """Goes from dark grey to a light grey.""" 
    63     return '0 0 %f' % (calls / 2 + 0.4) 
     61    # Greyscale 
     62    def greyscale(calls, total_time): 
     63        """Goes from dark grey to a light grey.""" 
     64        return '0 0 %f' % (calls / 2 + 0.4) 
    6465 
    65 pycallgraph.settings['node_colour'] = greyscale 
    66 pycallgraph.make_dot_graph('colours-greyscale.png') 
     66    pycallgraph.settings['node_colour'] = greyscale 
     67    pycallgraph.make_dot_graph('colours-greyscale.png') 
    6768 
    68 # Differences between calls and total time 
    69 def orange_green(calls, total_time): 
    70     """Make a higher total time have an orange colour and a higher number of 
    71     calls have a green colour using RGB. 
    72     """ 
    73     return '#%02X%02X%02X' % ( 
    74         0x30 + total_time * 0xc0, 
    75         0x30 + calls * 0xc0 + total_time * 0x70, 
    76         0x30, 
    77     ) 
     69    # Differences between calls and total time 
     70    def orange_green(calls, total_time): 
     71        """Make a higher total time have an orange colour and a higher number of 
     72        calls have a green colour using RGB. 
     73        """ 
     74        return '    #%02X%02X%02X' % ( 
     75            0x30 + total_time * 0xc0, 
     76            0x30 + calls * 0xc0 + total_time * 0x70, 
     77            0x30, 
     78        ) 
    7879 
    79 pycallgraph.settings['node_colour'] = orange_green 
    80 pycallgraph.make_dot_graph('colours-orange-green.png') 
     80    pycallgraph.settings['node_colour'] = orange_green 
     81    pycallgraph.make_dot_graph('colours-orange-green.png') 
    8182 
    82 # Random! 
    83 def rand(calls, total_time): 
    84     """Random with a touch of usefulness""" 
    85     return '%f %f %f' % (random.random(), calls * 0.5 + 0.5, calls * 0.5 + 0.5) 
     83    # Random! 
     84    def rand(calls, total_time): 
     85        """Random with a touch of usefulness""" 
     86        return '%f %f %f' % (random.random(), calls * 0.5 + 0.5, calls * 0.5 + 0.5) 
    8687 
    87 pycallgraph.settings['node_colour'] = rand 
    88 pycallgraph.make_dot_graph('colours-random.png') 
     88    pycallgraph.settings['node_colour'] = rand 
     89    pycallgraph.make_dot_graph('colours-random.png') 
    8990 
     91if __name__ == '__main__': 
     92    main() 
    9093 
     94# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • trunk/examples/filter.py

    r42 r45  
    6565    pycallgraph.make_dot_graph('filter-max-depth.png') 
    6666 
    67 filter_exclude() 
    68 filter_include() 
    69 filter_max_depth() 
     67def main(): 
     68    filter_exclude() 
     69    filter_include() 
     70    filter_max_depth() 
     71 
     72if __name__ == '__main__': 
     73    main() 
    7074 
    7175# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • trunk/examples/import.py

    r42 r45  
    2828import pycallgraph 
    2929 
    30 pycallgraph.settings['dont_exclude_anything'] = True 
     30def main(): 
     31    pycallgraph.settings['dont_exclude_anything'] = True 
     32    import_list = ['pickle', 'htmllib'] 
    3133 
    32 import_list = ['pickle', 'htmllib'] 
     34    for imp in import_list: 
     35        pycallgraph.start_trace() 
     36        __import__(imp) 
     37        pycallgraph.make_dot_graph('import-%s.png' % imp) 
    3338 
    34 for imp in import_list: 
    35     pycallgraph.start_trace() 
    36     __import__(imp) 
    37     pycallgraph.make_dot_graph('import-%s.png' % imp) 
     39if __name__ == '__main__': 
     40    main() 
    3841 
    3942# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • trunk/examples/large.py

    r42 r45  
    2929import pycallgraph 
    3030 
    31 pycallgraph.start_trace() 
    32 import urllib 
    33 from xml.dom.minidom import parse, parseString 
    34 parseString(urllib.urlopen('http://w3.org/').read()) 
    35 pycallgraph.make_dot_graph('large.png') 
     31def main(): 
     32    pycallgraph.start_trace() 
     33    import urllib 
     34    from xml.dom.minidom import parse, parseString 
     35    parseString(urllib.urlopen('http://w3.org/').read()) 
     36    pycallgraph.make_dot_graph('large.png') 
     37 
     38if __name__ == '__main__': 
     39    main() 
    3640 
    3741# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • trunk/examples/recursive.py

    r42 r45  
    3636    return n * factorial(n-1) 
    3737 
    38 for a in xrange(1, 10): 
    39     print factorial(a) 
    4038 
    41 pycallgraph.make_dot_graph('recursive.png') 
     39def main(self): 
     40    for a in xrange(1, 10): 
     41        print factorial(a) 
     42 
     43    pycallgraph.make_dot_graph('recursive.png') 
     44 
     45if __name__ == '__main__': 
     46    main() 
    4247 
    4348# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: 
  • trunk/examples/regexp.py

    r42 r45  
    2828import re 
    2929 
    30 pycallgraph.start_trace() 
     30def main(): 
     31    pycallgraph.start_trace() 
     32    re.search('(hel[j-s]o).*(th[^e]*ere)', 'hello there') 
     33    pycallgraph.make_dot_graph('regexp.png') 
    3134 
    32 re.search('(hel[j-s]o).*(th[^e]*ere)', 'hello there') 
    33  
    34 pycallgraph.make_dot_graph('regexp.png') 
     35if __name__ == '__main__': 
     36    main() 
    3537 
    3638# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: