Got Architecture class working the way i wanted to. Next to write tests

This commit is contained in:
Mario Melara 2015-10-20 13:33:21 -07:00
parent fec197ccac
commit 3ba2842b53

View file

@ -34,47 +34,50 @@
class InvalidSysTypeError(serr.SpackError): class InvalidSysTypeError(serr.SpackError):
def __init__(self, sys_type): def __init__(self, sys_type):
super(InvalidSysTypeError, self).__init__( super(InvalidSysTypeError, self).__init__("Invalid sys_type value for Spack: " + sys_type)
"Invalid sys_type value for Spack: " + sys_type)
class NoSysTypeError(serr.SpackError): class NoSysTypeError(serr.SpackError):
def __init__(self): def __init__(self):
super(NoSysTypeError, self).__init__( super(NoSysTypeError, self).__init__("Could not determine sys_type for this machine.")
"Could not determine sys_type for this machine.")
class Architecture(object): class Architecture(object):
def __init__(self, *arch_name): """ Architecture class that contains a dictionary of architecture name and compiler search strategy methods.
The idea is to create an object that Spack can interact with and know how to search for the compiler
""" Constructor for the architecture class. Should return a dictionary of name (grabbed from uname) and a strategy for If it is on a Cray architecture it should look in modules. If it is anything else search $PATH.
searching for that architecture's compiler. The target passed to it should be a dictionary of names and strategies.
""" """
self.arch_dict = {}
self.arch_name = arch_name
def add_arch_strategy(self): def __init__(self, front=None, back=None):
""" Create a dictionary using the tuples of arch_names"""
for n in self.arch_name: """ Constructor for the architecture class. Should return a dictionary of name (grabbed from uname)
and a strategy for searching for that architecture's compiler.
The target passed to it should be a dictionary of names and strategies.
"""
names = []
names.append(front)
names.append(back)
def add_compiler_strategy(names):
""" Create a dictionary of {'arch-name': 'strategy'}
This will tell Spack whether to look in the $PATH
or $MODULES location for compilers
"""
d = {}
for n in names:
if n:
if 'cray' in n.lower(): if 'cray' in n.lower():
self.arch_dict[n] = "MODULES" d[n] = "MODULES"
elif 'linux' in n.lower() or 'x86_64' in n.lower(): elif 'linux' in n.lower():
self.arch_dict[n] = "PATH" d[n] = "PATH"
else: else:
self.arch_dict[n] = "" d[n] = 'No Strategy'
return d
def get_arch_dict(self): self.arch_dict = add_compiler_strategy(names)
""" Grab the dictionary from the Architecture class, rather than access the internal Architecture attributes """
return self.arch_dict
def __eq__(self, other): def get_sys_type_from_spack_globals(): #TODO: Figure out how this function works
if self.arch_dict != {} and other.arch_dict != {}: """Return the SYS_TYPE from spack globals, or None if it isn't set."""
return self.arch_dict == other.arch_dict
else:
return self.arch_name == self.arch_name
def get_sys_type_from_spack_globals():
"""Return the SYS_TYPE from spack globals, or None if it isn't set. Front-end"""
if not hasattr(spack, "sys_type"): if not hasattr(spack, "sys_type"):
return None return None
elif hasattr(spack.sys_type, "__call__"): elif hasattr(spack.sys_type, "__call__"):
@ -104,7 +107,7 @@ def get_sys_type_from_uname():
""" Returns a sys_type from the uname argument """ Returns a sys_type from the uname argument
Front-end config Front-end config
""" """
return Architecture(os.uname()[0] + " " + os.uname()[-1]) return Architecture(os.uname()[0])
def get_sys_type_from_config_file(): def get_sys_type_from_config_file():
@ -149,6 +152,7 @@ def sys_type(): # This function is going to give me issues isn't it??
for func in functions: for func in functions:
sys_type = None sys_type = None
sys_type = func() sys_type = func()
if sys_type: if sys_type:
break break