Commit 7b6a3085 authored by Jérome Perrin's avatar Jérome Perrin

default: interact with linecache for complete traceback

When using init or install option of slapos.recipe.build to
write python code, the traceback were hard to understand, because
the current line was not included in the traceback.

This put the script in linecache before compiling it, so that in
case of error the problematic line appears in traceback.

There is still the "problem" that the traceback line numbers starts
from the beginning of the script and not the actual line from
buildout profile, but this does not seem feasible to adjust the line
numbers, so let's ignore this.
parent 3b375acb
......@@ -106,7 +106,8 @@ In case of error, a proper traceback is displayed and nothing is installed
recipe being used:
Traceback (most recent call last):
...
File "<string>", line 3, in <module>
File "section-two", line 3, in <module>
print(1 / 0.) # this is an error !
ZeroDivisionError: float division by zero
>>> ls(sample_buildout, 'parts')
......
......@@ -25,6 +25,7 @@
#
##############################################################################
import errno
import linecache
import logging
import os
from platform import uname
......@@ -256,7 +257,15 @@ class Script(EnvironMixin):
g['location'] = options['location']
except KeyError:
pass
exec(script, g)
linecache.cache[self.name] = (
len(script),
None,
script.splitlines(),
self.name,
)
code = compile(script, self.name, 'exec')
exec(code, g)
def install(self):
if not self._install:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment