Changeset 121

Show
Ignore:
Timestamp:
07/03/07 16:01:18 (1 year ago)
Author:
apdavison
Message:

Fix to a wikidoc import bug.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/0.3/common.py

    r78 r121  
    134134    """Leaky integrate and fire model with fixed threshold and 
    135135    decaying-exponential post-synaptic current. (Separate synaptic currents for 
    136     excitatory and inhibitory synapses""" 
     136    excitatory and inhibitory synapses).""" 
    137137     
    138138    default_parameters = { 
     
    224224    connections are made with probability p, using either the random number 
    225225    generator supplied, or the default rng otherwise. 
    226     Weights should be in nA or uS.""" 
     226    Weights should be in nA or µS.""" 
    227227    pass 
    228228 
     
    268268        simulator-specific model that makes up the population. 
    269269        cellparams should be a dict which is passed to the neuron model 
    270           constructor 
     270          constructor. 
    271271        label is an optional name for the population. 
    272272        """ 
     
    304304        giving the parameter name, in which case val is the parameter value. 
    305305        val can be a numeric value, or list of such (e.g. for setting spike times). 
    306         e.g. p.set("tau_m",20.0). 
     306        e.g. p.set("tau_m",20.0) 
    307307             p.set({'tau_m':20,'v_rest':-65}) 
    308308        """ 
     
    426426        presynaptic_population and postsynaptic_population - Population objects. 
    427427         
    428         source - string specifying which attribute of the presynaptic cell signals action potentials 
     428        source - string specifying which attribute of the presynaptic cell signals action potentials. 
    429429         
    430430        target - string specifying which synapse on the postsynaptic cell to connect to 
     
    434434        Allowed methods are 'allToAll', 'oneToOne', 'fixedProbability', 
    435435        'distanceDependentProbability', 'fixedNumberPre', 'fixedNumberPost', 
    436         'fromFile', 'fromList' 
     436        'fromFile', 'fromList'. 
    437437         
    438438        methodParameters - dict containing parameters needed by the connection method, 
  • branches/0.3/doc/wikidoc.py

    r114 r121  
    22"""Writes documentation for the API in Wiki format.""" 
    33 
     4import os 
    45import sys 
    56import types, string, re, logging 
    6 import imp, os 
    7 common = imp.load_source('common', os.path.join('..','common.py')) 
    8 print common 
     7import imp 
     8 
     9# Rather painful way of importing 
     10this_file = os.path.abspath(__file__) 
     11common_file = os.path.join(os.path.split(os.path.split(this_file)[0])[0],'common.py') 
     12common = imp.load_source('common', common_file) 
    913 
    1014#-- Define global data --------------------------------------------------------- 
     
    2125leftdblquote = re.compile(r'"\b') 
    2226camelcase = re.compile(r'(\b([A-Z][a-z]+){2,99})') 
    23  
     27newline = "\n" 
    2428  
    2529#-- Define functions ----------------------------------------------------------- 
     
    2731def _(str): 
    2832    """Remove extraneous whitespace.""" 
     33    global newline 
    2934    lines = str.strip().split('\n') 
    3035    lines = [line.strip() for line in lines] 
     
    8893 
    8994def apidoc(output): 
     95    global newline 
    9096    classes = {} 
    9197    functions = [] 
     
    108114        class_fmt        = '\n===<span style="color:green">%s</span>===\n' 
    109115        horiz_line       = '\n----\n' 
     116        docstr_fmt       = '%s' 
    110117    elif output == 'trac': 
    111118        default_arg_fmt  = '%s=%s' 
     
    123130        class_fmt        = '\n== %s ==\n' 
    124131        horiz_line       = '\n----\n' 
     132        docstr_fmt       = '%s' 
    125133    elif output == 'latex': 
    126134        default_arg_fmt  = '%s{\\color{grey}=%s}' 
     
    138146        class_fmt        = '\n\\subsubsection*{%s}\n' 
    139147        horiz_line       = '' 
     148        docstr_fmt       = '%s' 
     149    elif output == 'reportlab_xml': 
     150        newline          = "<br/>\n" 
     151        default_arg_fmt  = '%s<font color="gray">=%s</font>' 
     152        func_sig_fmt     = '<b>%s</b>(%s)' 
     153        function_fmt     = '\n<para style="FunctionDef"> %s </para>\n' 
     154        method_fmt       = function_fmt 
     155        staticmethod_fmt = function_fmt 
     156        dict_fmt         = '\n\n<para><b>%s</b> = { ' 
     157        dict_fmt_end     = '}</para>\n' 
     158        data_element_fmt = "<para><b>%s</b> = %s</para>" 
     159        table_begin      = ''#"<table>[" 
     160        table_end        = ''#"]</table>" 
     161        #table_row_fmt    = "[ '%s', ':', '%s'],\n" 
     162        table_row_fmt    = "'%s': %s, " 
     163        category_fmt     = '\n<para style="Category">%s</para>\n' 
     164        class_fmt        = '\n<para style="Class">%s</para>\n' 
     165        horiz_line       = '' 
     166        docstr_fmt       = '<para>%s</para>' 
    140167     
    141168    # gather information from the common module 
     
    175202        outputStr += '\definecolor{paleblue}{rgb}{0.5,0.5,1.0}\n' 
    176203        outputStr += '\definecolor{grey}{rgb}{0.5,0.5,0.5}\n' 
     204         
     205    logging.info("==== FUNCTIONS ====") 
     206    outputStr += category_fmt % "Functions" 
     207    for funcname in functions: 
     208        funcinst = eval('common.%s' % funcname) 
     209        outputStr += function_fmt % func_sig(funcinst, default_arg_fmt, func_sig_fmt) 
     210        if funcinst.__doc__: 
     211            outputStr += docstr_fmt % _(funcinst.__doc__.strip()) 
     212        
     213    logging.info("==== CLASSES ====") 
     214    # sort classes by type: 
     215    error_classes = {} 
     216    celltype_classes = {} 
     217    other_classes = {} 
     218    for classname in classes.keys(): 
     219        if classname.find('Error') > -1: 
     220            error_classes[classname] = classes[classname] 
     221        elif issubclass(eval('common.%s' % classname),common.StandardCellType): 
     222            celltype_classes[classname] = classes[classname] 
     223        else: 
     224            other_classes[classname] = classes[classname] 
     225     
     226    logging.info('Sorting classes...') 
     227    logging.info('Error classes:    %s' % ', '.join(error_classes.keys())) 
     228    logging.info('Celltype classes: %s' % ', '.join(celltype_classes.keys())) 
     229    logging.info('Other classes:    %s' % ', '.join(other_classes.keys())) 
     230     
     231    # Now iterate through the classes 
     232    outputStr += category_fmt % "Classes" 
     233    for classes in [celltype_classes, other_classes, error_classes]: 
     234        classlist = classes.keys() 
     235        classlist.sort() 
     236        for classname in classlist: 
     237            outputStr += class_fmt % classname 
     238            docstr = eval('common.%s.__doc__' % classname) 
     239            if docstr: 
     240                outputStr += docstr_fmt % _(docstr) 
     241            for methodname in classes[classname]['methods']: 
     242                methodinst = eval('common.%s.%s' % (classname,methodname)) 
     243                fs = func_sig(methodinst, default_arg_fmt, func_sig_fmt) 
     244                if fs: 
     245                    outputStr += method_fmt % fs 
     246                    if methodinst.__doc__: 
     247                        outputStr += docstr_fmt % _(methodinst.__doc__.strip()) 
     248            for methodname in classes[classname]['staticmethods']: 
     249                methodinst = eval('common.%s.%s' % (classname,methodname)) 
     250                fs = func_sig(methodinst, default_arg_fmt, func_sig_fmt) 
     251                if fs: 
     252                    outputStr += staticmethod_fmt % fs 
     253                    if methodinst.__doc__: 
     254                        outputStr += docstr_fmt % _(methodinst.__doc__.strip()) 
     255            for element in classes[classname]['data']: 
     256                instance = eval('common.%s.%s' % (classname,element)) 
     257                if type(instance) == types.DictType: 
     258                    outputStr += dict_fmt % element 
     259                    if len(instance) > 0: 
     260                        outputStr += table_begin 
     261                        for k,v in instance.items(): 
     262                            if output == 'latex': 
     263                                v = str(v).replace('{',' $\\lbrace$').replace('}',' $\\rbrace$') 
     264                                outputStr += table_row_fmt % (k,v) 
     265                            elif output == 'wiki': 
     266                                outputStr += table_row_fmt % ('&quot;%s&quot;' % k,v) 
     267                            elif output == 'trac': 
     268                                outputStr += table_row_fmt % ("'%s'" % k,v) 
     269                            elif output == 'reportlab_xml': 
     270                                outputStr += table_row_fmt % ("'%s'" % k,v) 
     271                        outputStr += table_end 
     272                    outputStr += dict_fmt_end 
     273                else: 
     274                    outputStr +=  data_element_fmt % (element, instance) 
     275                     
     276            outputStr += horiz_line 
    177277     
    178278    logging.info("==== DATA ====") 
     
    192292            outputStr +=  data_element_fmt % (element, instance) 
    193293         
    194     logging.info("==== FUNCTIONS ====") 
    195     outputStr += category_fmt % "Functions" 
    196     for funcname in functions: 
    197         funcinst = eval('common.%s' % funcname) 
    198         outputStr += function_fmt % func_sig(funcinst, default_arg_fmt, func_sig_fmt) 
    199         if funcinst.__doc__: 
    200             outputStr += _(funcinst.__doc__.strip()) 
    201         
    202     logging.info("==== CLASSES ====") 
    203     # sort classes by type: 
    204     error_classes = {} 
    205     celltype_classes = {} 
    206     other_classes = {} 
    207     for classname in classes.keys(): 
    208         if classname.find('Error') > -1: 
    209             error_classes[classname] = classes[classname] 
    210         elif issubclass(eval('common.%s' % classname),common.StandardCellType): 
    211             celltype_classes[classname] = classes[classname] 
    212         else: 
    213             other_classes[classname] = classes[classname] 
    214      
    215     logging.info('Sorting classes...') 
    216     logging.info('Error classes:    %s' % ', '.join(error_classes.keys())) 
    217     logging.info('Celltype classes: %s' % ', '.join(celltype_classes.keys())) 
    218     logging.info('Other classes:    %s' % ', '.join(other_classes.keys())) 
    219      
    220     # Now iterate through the classes 
    221     outputStr += category_fmt % "Classes" 
    222     for classes in [celltype_classes, other_classes, error_classes]: 
    223         classlist = classes.keys() 
    224         classlist.sort() 
    225         for classname in classlist: 
    226             outputStr += class_fmt % classname 
    227             docstr = eval('common.%s.__doc__' % classname) 
    228             if docstr: 
    229                 outputStr += _(docstr) 
    230             for methodname in classes[classname]['methods']: 
    231                 methodinst = eval('common.%s.%s' % (classname,methodname)) 
    232                 fs = func_sig(methodinst, default_arg_fmt, func_sig_fmt) 
    233                 if fs: 
    234                     outputStr += method_fmt % fs 
    235                     if methodinst.__doc__: 
    236                         outputStr += _(methodinst.__doc__.strip()) 
    237             for methodname in classes[classname]['staticmethods']: 
    238                 methodinst = eval('common.%s.%s' % (classname,methodname)) 
    239                 fs = func_sig(methodinst, default_arg_fmt, func_sig_fmt) 
    240                 if fs: 
    241                     outputStr += staticmethod_fmt % fs 
    242                     if methodinst.__doc__: 
    243                         outputStr += _(methodinst.__doc__.strip()) 
    244             for element in classes[classname]['data']: 
    245                 instance = eval('common.%s.%s' % (classname,element)) 
    246                 if type(instance) == types.DictType: 
    247                     outputStr += dict_fmt % element 
    248                     if len(instance) > 0: 
    249                         outputStr += table_begin 
    250                         for k,v in instance.items(): 
    251                             if output == 'latex': 
    252                                 v = str(v).replace('{',' $\\lbrace$').replace('}',' $\\rbrace$') 
    253                                 outputStr += table_row_fmt % (k,v) 
    254                             elif output == 'wiki': 
    255                                 outputStr += table_row_fmt % ('&quot;%s&quot;' % k,v) 
    256                             elif output == 'trac': 
    257                                 outputStr += table_row_fmt % ("'%s'" % k,v) 
    258                         outputStr += table_end 
    259                     outputStr += dict_fmt_end 
    260                 else: 
    261                     outputStr +=  data_element_fmt % (element, instance) 
    262                      
    263             outputStr += horiz_line 
    264          
    265294    if output == 'latex': 
    266295        outputStr = outputStr.replace('_','\_')