Opened 7 years ago

Closed 5 years ago

#15308 closed defect (fixed)

init.sage file is not read when starting the notebook

Reported by: jhpalmieri Owned by:
Priority: critical Milestone: sage-duplicate/invalid/wontfix
Component: notebook Keywords:
Cc: vbraun, ppurka, novoselt Merged in:
Authors: Reviewers: Karl-Dieter Crisman
Report Upstream: Completely fixed; Fix reported upstream Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

See http://ask.sagemath.org/question/3084/notebook-and-initsage. This problem seems to have been introduced in #14523.

Change History (14)

comment:1 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:2 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:3 Changed 6 years ago by RJBarker

An example of output caused by this bug is:

Traceback (most recent call last): #The OrthogonalCurvilinearOutput?.sage file will output the coefficients and differential operators defined

File "", line 1, in <module>

File "/tmp/tmpPnuBJt/_code_.py", line 7, in <module>

attach('CartesianCoord?.sage')

File "lazy_import.pyx", line 358, in sage.misc.lazy_import.LazyImport?.call (sage/misc/lazy_import.c:3000) File "/home/sagedev/sage/local/lib/python2.7/site-packages/sage/misc/attached_files.py", line 344, in attach

load(filename, globals(), attach=True)

File "/home/sagedev/sage/local/lib/python2.7/site-packages/sage/misc/preparser.py", line 1769, in load

execfile(preparse_file_named(fpath), globals)

File "/home/sagedev/.sage/temp/ubuntu/18360/CartesianCoord.sage6m7Baj.py", line 18, in <module>

var('q_1,q_2,q_3,x_1,x_2,x_3')

NameError?: name 'var' is not defined

comment:4 Changed 6 years ago by vbraun

Afaik attach doesn't work on the notebook.

Your problem seems to be that init.sage is evaluated before Sage is started. A workaround might be to use a .py file starting with from sage.all import *

comment:5 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:6 Changed 6 years ago by kcrisman

  • Component changed from misc to notebook
  • Report Upstream changed from N/A to Reported upstream. Developers acknowledge bug.

Upstream at https://github.com/sagemath/sagenb/issues/251 though I'm not sure if it's identical to the init.sage issue.

comment:7 Changed 6 years ago by kcrisman

I appear to have a fix upstream; comments welcome there. Somehow the change in #14523 in the definition of attach from

    import preparser 
        for filename in files: 
        preparser.load(filename, globals(), attach=True) 

to

    try:
        ipy = get_ipython()
    except NameError:
        ipy = None
    global attached
    for filename in files:
        if ipy:
            code = load_wrap(filename, attach=True)
            ipy.run_cell(code)
        else:
            load(filename, globals(), attach=True)

did this. Probably that should really be fixed in Sage, but I don't want to mess around with two fixes.

Can anyone think of why either adding that global (which one would think wouldn't clobber all globals, such as Integer?) or having the command-line code would be a problem? Really, neither one should in principle cause a problem. But it does.

comment:8 Changed 6 years ago by kcrisman

Indeed, a little more testing shows that globals() is definitely not the usual Sage globals at that point - it is just the globals for that module, including the things that were imported like os and the builtins. E.g.

'{\'load\': <function load at 0x1054cc488>, \'load_attach_path\': <function load_attach_path at 0x110d99e60>, \'reload_attached_files_if_modified\': <function reload_attached_files_if_modified at 0x110d9f2a8>, ...
 \'__doc__\': \'\\nKeep track of attached files\\n\\nTESTS::\\n\\n    sage: attach(\\\'http://wstein.org/loadtest.py\\\')\\n    Traceback (most recent call last):\\n    ...\\n    ...
 \'load_wrap\': <function load_wrap at 0x1054cc500>, \'load_attach_mode\': <function load_attach_mode at 0x110d99de8>, 
\'__builtins__\': {\'bytearray\': <type \'bytearray\'>, \'IndexError\': <type \'exceptions.IndexError\'>, ...}, 
...
\'os\': <module \'os\' from \'/Users/.../sage/local/lib/python/os.pyc\'>, \'modified_file_iterator\': <function modified_file_iterator at 0x110d9f230>}'

Zoinks!

comment:9 Changed 6 years ago by kcrisman

From the Python doc:

Remember that at module level, globals and locals are the same dictionary.

But on the other hand nothing really changed. Except maybe that it was in a Cython file, and now is in a Python file?

comment:10 Changed 6 years ago by kcrisman

  • Report Upstream changed from Reported upstream. Developers acknowledge bug. to Completely fixed; Fix reported upstream

comment:11 Changed 6 years ago by kcrisman

  • Cc ppurka novoselt added

This is 100% ready to go, just need a reviewer upstream!

comment:12 Changed 5 years ago by kcrisman

  • Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
  • Reviewers set to Karl-Dieter Crisman
  • Status changed from new to needs_review

This was fixed and is now in a merged package.

comment:13 Changed 5 years ago by kcrisman

  • Status changed from needs_review to positive_review

comment:14 Changed 5 years ago by vbraun

  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.