On Thu, Jan 10, 2019 at 4:47 AM Nathan Dunfield <nat...@dunfield.info> wrote: > > I am a developer of the Python package "snappy" which acquires extra features > when imported inside of Sage. Some of our Linux users have recently reported > difficulties with SnapPy on machines where Sage was installed by the standard > package manger making use of the system libraries and in particular the > system python. I have reproduced the problem on Debian Sid but it also > manifests itself on Fedora 28 [1]. The root of our problem is that in this > situation: > > python -c "import sage.all" > > results the error: > > Traceback (most recent call last): > File "<string>", line 1, in <module> > File "/usr/lib/python2.7/dist-packages/sage/all.py", line 71, in <module> > from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, > DOT_SAGE, SAGE_ENV > File "/usr/lib/python2.7/dist-packages/sage/env.py", line 123, in <module> > _add_variable_or_fallback('SAGE_ETC', opj('$SAGE_LOCAL', 'etc')) > File "/usr/lib/python2.7/dist-packages/sage/env.py", line 103, in > _add_variable_or_fallback > value = sep.join(components) > TypeError: sequence item 0: expected string, NoneType found > > whereas > > sage -python -c "import sage.all" > > works as expected. Currently, our Python package tests for whether it is > running in SageMath by: > > _within_sage = False > try: > import sage.all > _within_sage = True > except ImportError: > pass > > One solution for us (I think) would be to simply catch and ignore all types > of exceptions in the above block, but I was wondering if the current behavior > of 'python -c "import sage.all"' was expected or is this possibly a bug? Or > perhaps there is a work-around of some kind?
It's expected (see my previous reply) but obviously not great. For now I would just rewrite your above test to catch Exception, instead of just ImportError. This is a nitpick but instead of _within_sage I would name that variable something like "_have_sage" instead: It's just a test whether or not sage can be imported. If you want to look-before-you-leap you could also check if `SAGE_ROOT` and `SAGE_LOCAL` are set to something reasonable in `os.environ`. Those are the two environment variables that currently need to be set at a minimum for that module to work properly. But even with that it would still be wise to catch exceptions anyways. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.