Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#14066 closed defect (fixed)

FIx IPython 0.13 issues

Reported by: Jason Grout Owned by: William Stein
Priority: blocker Milestone: sage-5.7
Component: user interface Keywords:
Cc: Volker Braun Merged in: sage-5.7.rc0
Authors: Jason Grout Reviewers: Volker Braun, Jeroen Demeyer
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:

Attachments (2)

trac_14066-startup.patch (787 bytes) - added by Jason Grout 10 years ago.
trac_14066-quitexit.patch (650 bytes) - added by Jason Grout 10 years ago.

Download all attachments as: .zip

Change History (25)

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

comment:15 Changed 10 years ago by Chris Berg

I've noticed that attach no longer works. It says it's been deprecated and to use %attach, but then this appears to have a bug.

If I have a file "test.py" which contains one line

print "hello"

then when I attach:

%attach 'test.py'

then it prints hello. But if I rewrite the line to:

print "hey"

and then hit enter on sage, it doesn't print anything.

comment:16 Changed 10 years ago by John Palmieri

I think that %attach sort of works, maybe even mostly works, but printing does not. If my file contains the line a=3:

sage: %attach test.py
sage: a
3
sage: # now I edit test.py to say a=12.0
sage: a
12.0

Function definitions get updated just fine, but as you point out, print statements don't seem to work right. What else needs to be tested to know if print statements are the only issue?

Note that if I attach a file with print statements, then change it, then attach it again, the print statements appear twice. So I think the change is being detected, but the output isn't showing up when it should.

comment:17 in reply to:  15 Changed 10 years ago by Jeroen Demeyer

Replying to chrisjamesberg:

and then hit enter on sage, it doesn't print anything.

I don't quite understand what the problem is. Is it a problem that simply hitting ENTER doesn't reload the file, that the file is only reloaded before executing an actual command?

Because other than that, I find that %attach works fine. So, I'm willing to give this positive_review.

comment:18 Changed 10 years ago by Jason Grout

Regarding attach, I suppose that is a difference between the old and new. In the old, the attach expressions were run after every enter press (i.e., before the prompt was displayed). Now they are run just before any code is executed. I guess the issue is that blank lines in some sense "don't count" because of a shortcut. Let me see if I can add an option for attached files to run there as well.

comment:19 Changed 10 years ago by Jason Grout

It's going to be a bit tricky to execute attached files on empty input (i.e., just pressing enter) because, by default, IPython ignores attempts to execute empty strings. Do we really need this?

Last edited 10 years ago by Jason Grout (previous) (diff)

comment:20 Changed 10 years ago by Volker Braun

I don't think its necessary. I'm sure it'll break somebody's workflow (http://xkcd.com/1172/) but there are better solutions to "reload when saved" that don't involve sending non-commands.

comment:21 Changed 10 years ago by Volker Braun

Authors: Jason Grout
Reviewers: Volker Braun, Jeroen Demeyer
Status: needs_reviewpositive_review

Since nobody complained I set this to positive review ;-)

comment:22 Changed 10 years ago by Jeroen Demeyer

Merged in: sage-5.7.rc0
Resolution: fixed
Status: positive_reviewclosed

comment:23 Changed 10 years ago by John Palmieri

See #14144 for another one.

Note: See TracTickets for help on using tickets.