I'm trying to switch to a more software-development-like approach for one of my projects. To this end I'll be writing several files, and I'll be trying to keep imports to a minimum to speed up module loading.
At first I started with a file foo.sage
and a Makefile
which preparses this using sage -min -preparse foo.sage
. But the resulting foo.sage.py
still starts with from sage.all_cmdline import *
. I thought the point of the -min
switch was to avoid just that. Am I missing something here?
Next I tried to write Python code instead. But there I got problems, apparently because I was loading modules in the wrong order. Take for example a file foo.py
containing just the line from sage.rings.integer_ring import ZZ
. My Sage 7.4 on Gentoo will print the following when running said file as sage foo.py
:
Traceback (most recent call last):
File "foo.py", line 1, in <module>
from sage.rings.integer_ring import ZZ
File "sage/rings/integer.pxd", line 7, in init sage.rings.integer_ring (…/rings/integer_ring.c:14426)
File "sage/rings/rational.pxd", line 8, in init sage.rings.integer (…/rings/integer.c:49048)
File "sage/rings/fast_arith.pxd", line 3, in init sage.rings.rational (…/rings/rational.c:36533)
File "sage/libs/pari/gen.pxd", line 5, in init sage.rings.fast_arith (…/rings/fast_arith.c:8139)
File "sage/libs/pari/gen.pyx", line 91, in init sage.libs.pari.gen (…/libs/pari/gen.c:135191)
File "/usr/lib64/python2.7/site-packages/sage/rings/infinity.py", line 228, in <module>
from sage.rings.integer_ring import ZZ
ImportError: cannot import name ZZ
Is there a way to reasonably import things like this without too much experimentation, and without importing far more than I actually need here?