Running sage scripts noninteractively (possible bug)

58 views
Skip to first unread message

Watson Ladd

unread,
Mar 3, 2017, 3:26:13 PM3/3/17
to sage-support
Dear all,

I have a file with some commands that loads some other files and runs just fine from within an interactive sage session. But when I try to run it via sage filename on the command line I get errors of the form 'Integer undefined in file$junk.py'. where file.sage is one of the imported files.

Adding in the necessary import statements according to import_statements()  to file.sage doesn't seem to fix this, nor the code loading it. Looking at the generated python it appears that the constant definitions are getting moved up beyond the import statements, and thus break the script.  (There is an inserted massive import statement at the right place of sage.cmdline_all.*, but it doesn't seem to include Integer). I will try to make a minimal test-case to see if this is indeed happening.

I hope I don't need to resort to expect to get this code to run without my personal intervention. It's very likely I am doing something badly wrong, and if so would appreciate knowing how to do this right. (Documentation was not much help)

Sincerely,
Watson Ladd

Jeroen Demeyer

unread,
Mar 3, 2017, 3:54:17 PM3/3/17
to sage-s...@googlegroups.com
We need more details. In particular it would be useful to attach a
minimal testcase with the problematic .sage files.

Watson Ladd

unread,
Mar 5, 2017, 7:05:27 PM3/5/17
to sage-support


On Friday, March 3, 2017 at 12:54:17 PM UTC-8, Jeroen Demeyer wrote:
We need more details. In particular it would be useful to attach a
minimal testcase with the problematic .sage files.

Attached is a testcase which reveals the problem. 
sage_test.tgz

Jeroen Demeyer

unread,
Mar 6, 2017, 8:07:20 AM3/6/17
to sage-s...@googlegroups.com

Watson Ladd

unread,
Mar 6, 2017, 5:58:04 PM3/6/17
to sage-support

On Monday, March 6, 2017 at 5:07:20 AM UTC-8, Jeroen Demeyer wrote:
Confirmed: https://trac.sagemath.org/ticket/22527
 
Do you have any ideas for a workaround I can use, like compiling to python and importing? The workaround should also work for .spyx modules. The background is I interactively develop a library and want to use it for long-running batch computations. Or should I just change to load instead of attach?

Thanks once again for your assistance.

Sincerely,
Watson Ladd
 

Jeroen Demeyer

unread,
Mar 7, 2017, 4:19:36 AM3/7/17
to sage-s...@googlegroups.com
On 2017-03-06 23:58, Watson Ladd wrote:
> Or should I just change to load instead of attach?

The problem is limited to load(), so that would work.

Thinking about it, actually attach() only makes sense in interactive
sessions. So I see no reason to use it in scripts.

Jeroen Demeyer

unread,
Mar 7, 2017, 4:29:53 AM3/7/17
to sage-s...@googlegroups.com
On 2017-03-07 10:19, Jeroen Demeyer wrote:
> On 2017-03-06 23:58, Watson Ladd wrote:
>> Or should I just change to load instead of attach?
>
> The problem is limited to load(), so that would work.

Sorry: I meant to say: the problem is limited to attach(), so load()
should work.

Reply all
Reply to author
Forward
0 new messages