Reputation: 29
AttributeError: 'str' object has no attribute 'build_system_class'
I am getting this error when attempting to run this code. Does anyone know what is wrong?
import spack.cmd.info
import sys
pkg = sys.argv[1]
spack.cmd.info.print_text_info(pkg)
Upvotes: 0
Views: 139
Reputation: 370
From what I have seen from your question and the documentation, I assume the following:
The problem you have has nothing to do with Spack but rather with Python or object-oriented programming. You are fetching a string, sys.argv[1], representing a package name provided in the command-line and giving it to a method, print_text_info, which expects an object of PackageBase type, or its inheritances, e.g., AutotoolsPackage.
Python calls the method using string and calls a member of PackageBase type which doesn't exist for a string, resulting in the aforementioned error.
If you check the info.py of spack, you can see that it fails the first time it tries to call a method build_system_class.
def print_text_info(pkg):
"""Print out a plain text description of a package."""
header = section_title(
'{0}: '
).format(pkg.build_system_class) + pkg.name
color.cprint(header)
If you look at the info()
method (which implements the spack info
command) in spack.cmd.info
, you can see how names are looked up to get package instances:
def info(parser, args):
pkg = spack.repo.get(args.package)
print_text_info(pkg)
So, to get the PacakgeBase
instance to pass to print_text_info()
, you just need to import spack.repo
and call spack.repo.get(name)
as above.
Upvotes: 1