Ticket #3685: sage-3685.patch

File sage-3685.patch, 10.0 KB (added by was, 12 years ago)
  • sage/all.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1216568849 -7200
    # Node ID ddedee018cff19240af7665af7fdce01e181f212
    # Parent  717c10d9cd4a6f693add3b39365e1238b768b961
    trac #3685 -- make damned sure that "import sage.all" doesn't import ipython
    
    diff -r 717c10d9cd4a -r ddedee018cff sage/all.py
    a b  
    11"""
    22all.py -- much of sage is imported into this module, so you don't
    33          have to import everything individually.
     4
     5TESTS:
     6
     7Check that IPython is *not* imported by default when sage.all is imported.
     8    sage: os.system('sage -startuptime|grep IPython')
     9    256
    410"""
    511
    612from __future__ import with_statement
    def quit_sage(verbose=True): 
    236242    from sage.libs.all import symmetrica
    237243    symmetrica.end()
    238244       
    239 def _quit_sage_(self):
    240     import sage.misc.preparser_ipython
    241     if sage.misc.preparser_ipython.interface != None:
    242         sage.misc.preparser_ipython.switch_interface('sage')
    243         self.exit_now = False
    244         return
    245    
    246     from IPython.genutils import ask_yes_no
    247     if self.rc.confirm_exit:
    248         if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
    249             self.exit_now = True
    250     else:
    251         self.exit_now = True
    252     if self.exit_now:
    253         quit_sage()
    254         self.exit_now = True
    255 
    256     return self.exit_now
    257 
    258 from IPython.iplib import InteractiveShell
    259 InteractiveShell.exit = _quit_sage_
    260 
    261245from sage.ext.interactive_constructors_c import inject_on, inject_off
    262246
    263247#from catalogue.all import new
  • sage/interfaces/gap.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/interfaces/gap.py
    a b import expect 
    148148import expect
    149149from expect import Expect, ExpectElement, FunctionElement, ExpectFunction
    150150from sage.misc.misc import SAGE_ROOT, DOT_SAGE, is_64_bit
    151 from IPython.genutils import page
    152151import re
    153152import os
    154153import pexpect
    class Gap(Expect): 
    334333                self._get_tmpfile()
    335334            F = open(self._local_tmpfile(),"r")
    336335            if pager:
     336                from IPython.genutils import page
    337337                page(F.read(), start = int(sline)-1)
    338338            else:
    339339                return F.read()
  • sage/misc/all.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/misc/all.py
    a b from mathml import mathml 
    6060
    6161from defaults import set_default_variable_name
    6262
     63# the order of the following two imports matters!
    6364from preparser import preparse, implicit_multiplication
    6465
    65 from interpreter import preparser
     66from interpreter2 import preparser
    6667
    6768from sage_eval import sage_eval, sageobj
    6869
  • sage/misc/interpreter.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/misc/interpreter.py
    a b def embedded(): 
    419419    return sage.server.support.EMBEDDED_MODE
    420420
    421421ipython_prefilter = InteractiveShell.prefilter
    422 do_preparse=True
    423 def preparser(on=True):
    424     """
    425     Turn on or off the SAGE preparser.
    426 
    427     NOTE: This only works on the command line.  To turn off preparsing
    428     in the notebook, switch to python mode.
    429 
    430     INPUT:
    431         on -- bool (default: True) if True turn on preparsing; if False, turn it off.
    432 
    433     EXAMPLES:
    434         sage: 2/3
    435         2/3
    436         sage: preparser(False)
    437         sage: 2/3
    438         0
    439         sage: preparser(True)
    440         sage: 2^3
    441         8
    442     """
    443     global do_preparse
    444     if on:
    445         do_preparse = True
    446         InteractiveShell.prefilter = sage_prefilter
    447     else:
    448         do_preparse = False       
    449         InteractiveShell.prefilter = ipython_prefilter
    450 
    451422
    452423import sagedoc
    453424import IPython.OInspect
    454425IPython.OInspect.getdoc = sagedoc.my_getdoc
    455426IPython.OInspect.getsource = sagedoc.my_getsource
    456 
    457427
    458428import __builtin__
    459429_prompt = 'sage'
    def sage_prompt(): 
    468438
    469439__builtin__.sage_prompt = sage_prompt
    470440
     441from interpreter2 import preparser
    471442
     443def _quit_sage_(self):
     444    import sage.misc.preparser_ipython
     445    if sage.misc.preparser_ipython.interface != None:
     446        sage.misc.preparser_ipython.switch_interface('sage')
     447        self.exit_now = False
     448        return
     449
     450    from IPython.genutils import ask_yes_no
     451    if self.rc.confirm_exit:
     452        if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
     453            self.exit_now = True
     454    else:
     455        self.exit_now = True
     456
     457    if self.exit_now:
     458        from sage.all import quit_sage
     459        quit_sage()
     460        self.exit_now = True
     461
     462    return self.exit_now
     463
     464from IPython.iplib import InteractiveShell
     465InteractiveShell.exit = _quit_sage_
     466
  • new file sage/misc/interpreter2.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/misc/interpreter2.py
    - +  
     1do_preparse=True
     2def preparser(on=True):
     3    """
     4    Turn on or off the Sage preparser.
     5
     6    NOTE: This only works on the command line.  To turn off preparsing
     7    in the notebook, switch to python mode.
     8
     9    INPUT:
     10        on -- bool (default: True) if True turn on preparsing; if False, turn it off.
     11
     12    EXAMPLES:
     13        sage: 2/3
     14        2/3
     15        sage: preparser(False)
     16        sage: 2/3   # not tested -- impossible to test from doctest system since uses IPython
     17        0
     18        sage: preparser(True)
     19        sage: 2^3
     20        8
     21    """
     22    global do_preparse
     23    import interpreter
     24    if on:
     25        do_preparse = True
     26        interpreter.InteractiveShell.prefilter = interpreter.sage_prefilter
     27    else:
     28        do_preparse = False
     29        interpreter.InteractiveShell.prefilter = interpreter.ipython_prefilter
  • sage/misc/log.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/misc/log.py
    a b import os 
    5454import os
    5555import time
    5656
    57 import interpreter
    5857import latex
    5958import misc
    6059
    from sage.misc.viewer import browser, 
    6463
    6564offset = 0
    6665loggers = []
     66
     67def prompt():
     68    import interpreter
     69    return interpreter._prompt
    6770
    6871def update():
    6972    for X in loggers:
    class log_html(Log): 
    240243        if n >= len(self._input):
    241244            return
    242245        return """<font color=darkblue>     %s %s:</font> %s"""%(
    243             n, interpreter._prompt, self._input[n])
     246            n, prompt(), self._input[n])
    244247   
    245248    def _get_output(self, n):
    246249        x = self._output[n]
    class log_dvi(Log): 
    354357            self._in_verbatim = True
    355358        I = self._input[n]
    356359        #print('input: %s' % I)
    357         s += "%s %s: %s"%(n,  interpreter._prompt, I)
     360        s += "%s %s: %s"%(n,  prompt(), I)
    358361        s += '\\end{verbatim}'
    359362        if followed_by_output:
    360363            self._in_verbatim = False
    class log_text(Log): 
    445448        if n >= len(self._input):
    446449            return
    447450        else:
    448             return "%s %s: %s"%(n, interpreter._prompt, self._input[n])
     451            return "%s %s: %s"%(n, prompt(), self._input[n])
    449452   
    450453    def _get_output(self, n):
    451454        return '\n  ' + str(self._output[n]) + '\n\n'
  • sage/misc/preparser.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/misc/preparser.py
    a b def _strip_quotes(s): 
    10501050    if s[-1] in ["'", '"']:
    10511051        s = s[:-1]
    10521052    return s
     1053
     1054
  • sage/misc/sage_timeit.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/misc/sage_timeit.py
    a b AUTHOR: 
    99    -- William Stein, based on code copied from Fernand Perez's Ipython
    1010"""
    1111
    12 import timeit as timeit_, time, math, preparser, interpreter
     12import timeit as timeit_, time, math, preparser
    1313
    1414def sage_timeit(stmt, globals, preparse=None,
    1515                   number = 0, repeat = 3, precision = 3):
    def sage_timeit(stmt, globals, preparse= 
    4242    repeat=int(repeat)
    4343    precision=int(precision)
    4444    if preparse is None:
    45         preparse = interpreter.do_preparse
     45        import interpreter2
     46        preparse = interpreter2.do_preparse
    4647    if preparse:
    4748        stmt = preparser.preparse(stmt)
    4849    if stmt == "":
  • sage/server/notebook/cell.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/server/notebook/cell.py
    a b class Cell_generic: 
    5353        class.
    5454
    5555        EXAMPLES:
    56         This function just raises a NotImplementedError, since it most be defined
    57         in derived class.
     56
     57        This function just raises a NotImplementedError, since it most
     58        be defined in derived class.
     59       
    5860            sage: C = sage.server.notebook.cell.Cell_generic()
    5961            sage: C.delete_output()
    6062            Traceback (most recent call last):
  • sage/server/notebook/worksheet.py

    diff -r 717c10d9cd4a -r ddedee018cff sage/server/notebook/worksheet.py
    a b import crypt 
    3333import crypt
    3434import bz2
    3535import re
     36import sage.misc.interpreter2
    3637
    3738# A library that we ship with sage
    3839import pexpect
    from sage.structure.sage_object impor 
    4344from   sage.structure.sage_object  import load, save
    4445from   sage.interfaces.sage0 import Sage
    4546from   sage.misc.preparser   import preparse_file
    46 import sage.misc.interpreter
    4747from   sage.misc.misc        import alarm, cancel_alarm, verbose, DOT_SAGE, walltime
    4848import sage.server.support   as support
    4949
    class Worksheet: 
    30943094        return support.get_rightmost_identifier(s)
    30953095
    30963096    def preparse(self, s):
    3097         if sage.misc.interpreter.do_preparse:
     3097        if sage.misc.interpreter2.do_preparse:
    30983098            s = preparse_file(s, magic=False, do_time=True,
    30993099                              ignore_prompts=False)
    31003100        return s