summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhealther <healther@users.noreply.github.com>2017-11-28 22:32:21 +0100
committerscheibelp <scheibel1@llnl.gov>2017-11-28 13:32:21 -0800
commitdc8f587b613f3e2314d872ea8303b184eeba9ae4 (patch)
treeb325a5cd7d77f6f60e3b1d37572037794802874f
parentacd80b16a8a4faf8b73de44d14e83d49cfca51d1 (diff)
downloadspack-dc8f587b613f3e2314d872ea8303b184eeba9ae4.tar.gz
spack-dc8f587b613f3e2314d872ea8303b184eeba9ae4.tar.bz2
spack-dc8f587b613f3e2314d872ea8303b184eeba9ae4.tar.xz
spack-dc8f587b613f3e2314d872ea8303b184eeba9ae4.zip
add path to package.py in case of a syntax error (#6458)
-rw-r--r--lib/spack/spack/repository.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/spack/spack/repository.py b/lib/spack/spack/repository.py
index e38af165f9..c9111e9b3d 100644
--- a/lib/spack/spack/repository.py
+++ b/lib/spack/spack/repository.py
@@ -987,7 +987,14 @@ class Repo(object):
# 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