If MMA is run in an environment that is not associated with a terminal, it crashes with a weird error.
For example, when using Emacs, edit t.mma and then M-x compile RET mma -n t.mma RET .
Traceback (most recent call last):
File "/home/jv/bin/mma", line 78, in <module>
import MMA.main
File "/home/jv/lib/mma/MMA/main.py", line 157, in <module>
MMA.parse.parseFile(f)
File "/home/jv/lib/mma/MMA/parse.py", line 91, in parseFile
parse(f)
File "/home/jv/lib/mma/MMA/parse.py", line 161, in parse
simpleFuncs[action](l[1:])
File "/home/jv/lib/mma/MMA/grooves.py", line 463, in allgrooves
error("AllGrooves: '%s' cannot be applied like this." % action)
File "/home/jv/lib/mma/MMA/common.py", line 94, in error
prettyPrint("Error: %s %s %s" % (linno, file, msg))
File "/home/jv/lib/mma/MMA/common.py", line 74, in prettyPrint
for a in wrap(msg, termwidth, initial_indent='', subsequent_indent=' '):
File "/usr/lib64/python2.7/textwrap.py", line 354, in wrap
return w.wrap(text)
File "/usr/lib64/python2.7/textwrap.py", line 329, in wrap
return self._wrap_chunks(chunks)
File "/usr/lib64/python2.7/textwrap.py", line 258, in _wrap_chunks
raise ValueError("invalid width %r (must be > 0)" % self.width)
ValueError: invalid width -1 (must be > 0)
It took me some time to find the cause of the problem. In "common.py", lines 46-47
from MMA.termsize import getTerminalSize
termwidth = getTerminalSize()[0]-1
Apparently this can fail and will set termwidth to -1, causing the pretty printing to crash.
Even though this is a weird case, I'd suggest to add a safety net, e.g.
# having the term width is nice for pretty print error/warning
from MMA.termsize import getTerminalSize
termwidth = getTerminalSize()[0]-1
if termwidth < 0:
termwidth = 80