fix get_package_context check whether in a package file

This commit is contained in:
Gregory Becker
2020-03-27 17:18:46 -07:00
committed by Tamara Dahlgren
parent d92f52ae02
commit fdb8a59bae

View File

@@ -987,11 +987,15 @@ def make_stack(tb, stack=None):
# Package files are named `package.py` and are not in the lib/spack/spack
# Package files have a line added at import time, so we adjust the lineno
# when we are getting context from a package file instead of a base class
# We have to remove the file extension because it can be .py and can be
# .pyc depending on context, and can differ between the files
filename = inspect.getfile(frame.f_code)
packagebase_filename = inspect.getfile(spack.package.PackageBase)
in_package = (filename != packagebase_filename and
os.path.basename(filename) == 'package.py')
adjust = 0 if in_package else 1
filename_noext = os.path.splitext(filename)[0]
packagebase_filename_noext = os.path.splitext(
inspect.getfile(spack.package.PackageBase))[0]
in_package = (filename_noext != packagebase_filename_noext and
os.path.basename(filename_noext) == 'package')
adjust = 1 if in_package else 0
# We found obj, the Package implementation we care about.
# Point out the location in the install method where we failed.