Opened 10 years ago

Last modified 10 years ago

#14066 closed defect

FIx IPython 0.13 issues — at Version 14

Reported by: Jason Grout Owned by: William Stein
Priority: blocker Milestone: sage-5.7
Component: user interface Keywords:
Cc: Volker Braun Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Jason Grout)

Can we keep this ticket open to track all the remaining IPython issues left over from #12719?

Still outstanding:

From Kannappan Sampath:

  1. I am unable to exit by typing "exit", but Ctrl+D however works!
  2. The following (from #12719)
    jec@fermat%./sage
    ----------------------------------------------------------------------
    | Sage Version 5.7.beta1, Release Date: 2013-01-26                   |
    | Type "notebook()" for the browser-based notebook interface.        |
    | Type "help()" for help.                                            |
    ----------------------------------------------------------------------
    **********************************************************************
    *                                                                    *
    * Warning: this is a prerelease version, and it may be unstable.     *
    *                                                                    *
    **********************************************************************
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    /home/jec/sage-5.7.beta1/local/lib/python2.7/site-packages/IPython/utils/py3compat.pyc
    in execfile(fname, *where)
        176             else:
        177                 filename = fname
    --> 178             __builtin__.execfile(filename, *where)
    
    /home/jec/.sage/init.sage in <module>()
    ----> 1 load /home/jec/sage/ecdb.py
    
    NameError: name 'load' is not defined
    

apply:

Change History (16)

comment:1 Changed 10 years ago by Jason Grout

Description: modified (diff)

comment:2 Changed 10 years ago by Jason Grout

Description: modified (diff)

Another

comment:3 Changed 10 years ago by Jason Grout

Description: modified (diff)

comment:4 Changed 10 years ago by Jason Grout

Regarding (3), loading a sage file (i.e., %runfile init.sage) certainly works with sage syntax like load. So the problem appears to be that the %runfile code isn't being used to run init.sage.

comment:5 Changed 10 years ago by Jeroen Demeyer

Description: modified (diff)

(2) is certainly not related to IPython.

comment:6 Changed 10 years ago by Jeroen Demeyer

Component: PLEASE CHANGEuser interface
Owner: changed from tbd to William Stein

comment:7 Changed 10 years ago by Jeroen Demeyer

Description: modified (diff)
Priority: majorblocker

comment:8 Changed 10 years ago by Jason Grout

For (1): In devel/sage/sage/all.py, we find this code at the very top:

# Error message that matches the Sage/IPython defaults
quit = "Use Ctrl-D (i.e. EOF), %Exit, or %Quit to exit without confirmation."
exit = quit

Who put that there? Deleting those lines restores exit and quit to act just as expected.

comment:9 Changed 10 years ago by Jason Grout

It looks like William put it there in 2006, so apparently it is a leftover from the old system. I wonder how exit and quit worked before; clearly they didn't just print the string!

comment:10 Changed 10 years ago by John Palmieri

So issue (1) seems to have a solution. Here's an idea for (2):

  • sage/misc/sage_extension.py

    diff --git a/sage/misc/sage_extension.py b/sage/misc/sage_extension.py
    a b  
    453453        """
    454454        startup_file = os.environ.get('SAGE_STARTUP_FILE', '')
    455455        if os.path.exists(startup_file):
    456             self.shell.run_cell('%%run %r'%startup_file)
     456            with open(startup_file, 'r') as f:
     457                self.shell.run_cell(f.read())
    457458
    458459    def init_inspector(self):
    459460        # Ideally, these would just be methods of the Inspector class

(That is, call run_cell on the contents of the init file, instead of calling run_cell(%%run ...) on the init file itself.)

comment:11 Changed 10 years ago by Jeroen Demeyer

I don't know much about this IPython stuff, but it would be good to resolve these issues as this is the only remaining blocker for sage-5.7.

comment:12 Changed 10 years ago by Jason Grout

John, that fix seems reasonable. Looking at the IPython source, the default for the %run magic is to run using the python execfile function, so that explains why sage-specific things didn't work. run_cell should apply the sage-specific things.

But I would change the call to run_cell(f.read(), silent=True) (and then check to make sure tracebacks still work; if not, then use run_cell(f.read(), store_history=False))

comment:13 Changed 10 years ago by Jason Grout

To be consistent with shell.runfile_ipy, I just use store_history=False...

Changed 10 years ago by Jason Grout

Attachment: trac_14066-startup.patch added

Changed 10 years ago by Jason Grout

Attachment: trac_14066-quitexit.patch added

comment:14 Changed 10 years ago by Jason Grout

Description: modified (diff)
Status: newneeds_review
Note: See TracTickets for help on using tickets.