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
If it is on a Cray architecture it should look in modules. If it is anything else search $PATH.
"""
def __init__(self, front=None, back=None):
""" Constructor for the architecture class. Should return a dictionary of name (grabbed from uname) and a strategy for """ Constructor for the architecture class. Should return a dictionary of name (grabbed from uname)
searching for that architecture's compiler. The target passed to it should be a dictionary of names and strategies. and a strategy for searching for that architecture's compiler.
The target passed to it should be a dictionary of names and strategies.
""" """
self.arch_dict = {} names = []
self.arch_name = arch_name names.append(front)
names.append(back)
def add_arch_strategy(self): def add_compiler_strategy(names):
""" Create a dictionary using the tuples of arch_names""" """ Create a dictionary of {'arch-name': 'strategy'}
for n in self.arch_name: This will tell Spack whether to look in the $PATH
if 'cray' in n.lower(): or $MODULES location for compilers
self.arch_dict[n] = "MODULES" """
elif 'linux' in n.lower() or 'x86_64' in n.lower(): d = {}
self.arch_dict[n] = "PATH" for n in names:
else: if n:
self.arch_dict[n] = "" if 'cray' in n.lower():
d[n] = "MODULES"
def get_arch_dict(self): elif 'linux' in n.lower():
""" Grab the dictionary from the Architecture class, rather than access the internal Architecture attributes """ d[n] = "PATH"
return self.arch_dict else:
d[n] = 'No Strategy'
def __eq__(self, other): return d
if self.arch_dict != {} and other.arch_dict != {}:
return self.arch_dict == other.arch_dict self.arch_dict = add_compiler_strategy(names)
else:
return self.arch_name == self.arch_name
def get_sys_type_from_spack_globals(): #TODO: Figure out how this function works
def get_sys_type_from_spack_globals(): """Return the SYS_TYPE from spack globals, or None if it isn't set."""
"""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