Started created the Architecture class for Spack to use
This commit is contained in:
		| @@ -30,7 +30,7 @@ | |||||||
| import spack | import spack | ||||||
| import spack.error as serr | import spack.error as serr | ||||||
| from spack.version import Version | from spack.version import Version | ||||||
|  | from external import yaml | ||||||
|  |  | ||||||
| class InvalidSysTypeError(serr.SpackError): | class InvalidSysTypeError(serr.SpackError): | ||||||
|     def __init__(self, sys_type): |     def __init__(self, sys_type): | ||||||
| @@ -43,41 +43,81 @@ 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): | ||||||
|  |     def __init__(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. | ||||||
|  |         """ | ||||||
|  |         self.arch_dict = {} | ||||||
|  |         self.arch_name = arch_name | ||||||
|  |  | ||||||
|  |     def add_arch_strategy(self): | ||||||
|  |         """ Create a dictionary using the tuples of arch_names""" | ||||||
|  |         for n in self.arch_name: | ||||||
|  |             if 'cray' in n.lower(): | ||||||
|  |                 self.arch_dict[n] = "MODULES" | ||||||
|  |             if 'linux' in n.lower() or 'x86_64' in n.lower(): | ||||||
|  |                 self.arch_dict[n] = "PATH" | ||||||
|  |             else: | ||||||
|  |                 self.arch_dict[n] = None  | ||||||
|  |  | ||||||
| def get_sys_type_from_spack_globals(): | 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__"): | ||||||
|         return spack.sys_type() |         return Architecture(spack.sys_type()) | ||||||
|     else: |     else: | ||||||
|         return spack.sys_type |         return Architecture(spack.sys_type) | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_sys_type_from_environment(): |  | ||||||
|     """Return $SYS_TYPE or None if it's not defined.""" |  | ||||||
|     return os.environ.get('SYS_TYPE') |  | ||||||
|  |  | ||||||
|  | # This is livermore dependent. Hard coded for livermore | ||||||
|  | #def get_sys_type_from_environment(): | ||||||
|  | #    """Return $SYS_TYPE or None if it's not defined.""" | ||||||
|  | #    return os.environ.get('SYS_TYPE') | ||||||
|  |  | ||||||
| def get_mac_sys_type(): | def get_mac_sys_type(): | ||||||
|     """Return a Mac OS SYS_TYPE or None if this isn't a mac.""" |     """Return a Mac OS SYS_TYPE or None if this isn't a mac. | ||||||
|  |        Front-end config | ||||||
|  |     """ | ||||||
|  |  | ||||||
|     mac_ver = py_platform.mac_ver()[0] |     mac_ver = py_platform.mac_ver()[0] | ||||||
|     if not mac_ver: |     if not mac_ver: | ||||||
|         return None |         return None | ||||||
|  |  | ||||||
|     return "macosx_%s_%s" % ( |     return Architecture("macosx_%s_%s" % (Version(mac_ver).up_to(2), py_platform.machine())) | ||||||
|         Version(mac_ver).up_to(2), py_platform.machine()) |  | ||||||
|  |  | ||||||
|  | def get_sys_type_from_uname(): | ||||||
|  |     """ Returns a sys_type from the uname argument  | ||||||
|  |         Front-end config | ||||||
|  |     """ | ||||||
|  |     return Architecture(os.uname()[0] + " " + os.uname()[-1]) | ||||||
|  |  | ||||||
|  | def get_sys_type_from_config_file(): | ||||||
|  |     """ Should read in a sys_type from the config yaml file. This should be the first thing looked at since | ||||||
|  |         The user can specify that the architecture is a cray-xc40 | ||||||
|  |     """ | ||||||
|  |        | ||||||
|  |     home_dir = os.environ["HOME"]    | ||||||
|  |     yaml_file = os.path.join(home_dir, ".spack/architecture.yaml") | ||||||
|  |     if os.path.isfile(yaml_file): | ||||||
|  |         with open(yaml_file) as config: | ||||||
|  |             config_dict = config['architecture'] | ||||||
|  |             front_end = config_dict['front']             | ||||||
|  |             back_end = config_dict['back'] | ||||||
|  |     return Architecture(front_end) | ||||||
|  |  | ||||||
| @memoized | @memoized | ||||||
| def sys_type(): | def sys_type(): | ||||||
|     """Returns a SysType for the current machine.""" |     """Returns a SysType for the current machine. Should return output to an  | ||||||
|  |        Architecture class | ||||||
|  |     """ | ||||||
|     methods = [get_sys_type_from_spack_globals, |     methods = [get_sys_type_from_spack_globals, | ||||||
|                get_sys_type_from_environment, |                get_sys_type_from_environment, | ||||||
|                get_mac_sys_type] |                get_mac_sys_type] | ||||||
|  |  | ||||||
|     # search for a method that doesn't return None |     # search for a method that doesn't return None | ||||||
|     sys_type = None |     sys_type = (None,None) | ||||||
|     for method in methods: |     for method in methods: | ||||||
|         sys_type = method() |         sys_type = method() | ||||||
|         if sys_type: break |         if sys_type: break | ||||||
| @@ -90,3 +130,4 @@ def sys_type(): | |||||||
|         raise InvalidSysTypeError(sys_type) |         raise InvalidSysTypeError(sys_type) | ||||||
|  |  | ||||||
|     return sys_type |     return sys_type | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Mario Melara
					Mario Melara