From dc8f587b613f3e2314d872ea8303b184eeba9ae4 Mon Sep 17 00:00:00 2001 From: healther Date: Tue, 28 Nov 2017 22:32:21 +0100 Subject: add path to package.py in case of a syntax error (#6458) --- lib/spack/spack/repository.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3-70-g09d2