Home | History | Annotate | Download | only in Tools
      1 #! /usr/bin/env python
      2 
      3 # --------------------------------------------------------------------
      4 
      5 import re
      6 from epydoc import docstringparser as dsp
      7 
      8 CYTHON_SIGNATURE_RE = re.compile(
      9     # Class name (for builtin methods)
     10     r'^\s*((?P<class>\w+)\.)?' +
     11     # The function name
     12     r'(?P<func>\w+)' +
     13     # The parameters
     14     r'\(((?P<self>(?:self|cls|mcs)),?)?(?P<params>.*)\)' +
     15     # The return value (optional)
     16     r'(\s*(->)\s*(?P<return>\w+(?:\s*\w+)))?' +
     17     # The end marker
     18     r'\s*(?:\n|$)')
     19 
     20 parse_signature = dsp.parse_function_signature
     21 
     22 def parse_function_signature(func_doc, doc_source,
     23                              docformat, parse_errors):
     24     PYTHON_SIGNATURE_RE = dsp._SIGNATURE_RE
     25     assert PYTHON_SIGNATURE_RE is not CYTHON_SIGNATURE_RE
     26     try:
     27         dsp._SIGNATURE_RE = CYTHON_SIGNATURE_RE
     28         found = parse_signature(func_doc, doc_source,
     29                                 docformat, parse_errors)
     30         dsp._SIGNATURE_RE = PYTHON_SIGNATURE_RE
     31         if not found:
     32             found = parse_signature(func_doc, doc_source,
     33                                     docformat, parse_errors)
     34         return found
     35     finally:
     36         dsp._SIGNATURE_RE = PYTHON_SIGNATURE_RE
     37 
     38 dsp.parse_function_signature = parse_function_signature
     39 
     40 # --------------------------------------------------------------------
     41 
     42 from epydoc.cli import cli
     43 cli()
     44 
     45 # --------------------------------------------------------------------
     46