Ticket #13916: trac13916_inspect_interactive_cython.patch

File trac13916_inspect_interactive_cython.patch, 2.1 KB (added by SimonKing, 8 years ago)
  • sage/misc/sageinspect.py

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1357484683 -3600
    # Node ID b8f275268021057e5f1dd317955b4164967a6a85
    # Parent  719474c84b4af9a7124f30d8308099b026fc86a1
    #13916: Fix inspection of interactive Cython code
    
    diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
    a b  
    158158            obj.__class__.__module__ not in ('__builtin__', 'exceptions'))
    159159
    160160
    161 SAGE_ROOT = os.environ["SAGE_ROOT"]
    162    
     161SAGE_ROOT = os.environ['SAGE_ROOT']
     162
    163163import re
    164164# Parse strings of form "File: sage/rings/rational.pyx (starting at line 1080)"
    165165# "\ " protects a space in re.VERBOSE mode.
     
    185185       sage: import inspect
    186186       sage: _extract_embedded_position(inspect.getdoc(var))[1][-21:]
    187187       'sage/calculus/var.pyx'
    188        
     188
     189    The following has been fixed in :trac:`13916`::
     190
     191        sage: cython('''cpdef test_funct(x,y): return''')
     192        sage: print open(_extract_embedded_position(inspect.getdoc(test_funct))[1]).read()
     193        <BLANKLINE>
     194        include "interrupt.pxi"  # ctrl-c interrupt block support
     195        include "stdsage.pxi"  # ctrl-c interrupt block support
     196        <BLANKLINE>
     197        include "cdefs.pxi"
     198        cpdef test_funct(x,y): return
     199
    189200    AUTHORS:
    190201
    191202    - William Stein
    192203    - Extensions by Nick Alexander
     204    - Extension for interactive Cython code by Simon King
    193205    """
    194206    if docstring is None:
    195207        return None
    196208    res = __embedded_position_re.match(docstring)
    197209    if res is not None:
    198210        #filename = '%s/local/lib/python/site-packages/%s' % (SAGE_ROOT, res.group('FILENAME'))
    199         filename = '%s/devel/sage/%s' % (SAGE_ROOT, res.group('FILENAME'))
     211        raw_filename = res.group('FILENAME')
     212        filename = os.path.join(SAGE_ROOT, 'devel', 'sage', raw_filename)
     213        if not os.path.isfile(filename):
     214            from sage.misc.misc import SPYX_TMP
     215            filename = os.path.join(SPYX_TMP, '_'.join(raw_filename.split('_')[:-1]), raw_filename)
    200216        lineno = int(res.group('LINENO'))
    201217        original = res.group('ORIGINAL')
    202218        return (original, filename, lineno)