add path to package.py in case of a syntax error (#6458)

This commit is contained in:
healther 2017-11-28 22:32:21 +01:00 committed by scheibelp
parent acd80b16a8
commit dc8f587b61

View File

@ -987,7 +987,14 @@ def _get_pkg_module(self, pkg_name):
# e.g., spack.pkg.builtin.mpich
fullname = "%s.%s" % (self.full_namespace, pkg_name)
module = imp.load_source(fullname, file_path)
try:
module = imp.load_source(fullname, file_path)
except SyntaxError as e:
# SyntaxError strips the path from the filename so we need to
# manually construct the error message in order to give the
# user the correct package.py where the syntax error is located
raise SyntaxError('invalid syntax in {0:}, line {1:}'
''.format(file_path, e.lineno))
module.__package__ = self.full_namespace
module.__loader__ = self
self._modules[pkg_name] = module