@@ -1215,6 +1215,46 @@ def check_python_version():
12151215 return (python_maj_ver , python_min_ver )
12161216
12171217
1218+ def pick_system_specific_value (description , options_or_value , allow_none = False ):
1219+ """Pick an entry for the current system when the input has multiple options
1220+
1221+ :param description: Descriptive string about the value to be retrieved. Used for logging.
1222+ :param options_or_value: Either a dictionary with options to choose from or a value of any other type
1223+ :param allow_none: When True and no matching arch key was found, return None instead of an error
1224+
1225+ :return options_or_value when it is not a dictionary or the matching entry (if existing)
1226+ """
1227+ result = options_or_value
1228+ if isinstance (options_or_value , dict ):
1229+ if not options_or_value :
1230+ raise EasyBuildError ("Found empty dict as %s!" , description )
1231+ other_keys = [x for x in options_or_value .keys () if not x .startswith (ARCH_KEY_PREFIX )]
1232+ if other_keys :
1233+ other_keys = ',' .join (sorted (other_keys ))
1234+ raise EasyBuildError ("Unexpected keys in %s: %s (only '%s' keys are supported)" ,
1235+ description , other_keys , ARCH_KEY_PREFIX )
1236+ host_arch_key = ARCH_KEY_PREFIX + get_cpu_architecture ()
1237+ star_arch_key = ARCH_KEY_PREFIX + '*'
1238+ # check for specific 'arch=' key first
1239+ try :
1240+ result = options_or_value [host_arch_key ]
1241+ _log .info ("Selected %s from %s for %s (using key %s)" ,
1242+ result , options_or_value , description , host_arch_key )
1243+ except KeyError :
1244+ # fall back to 'arch=*'
1245+ try :
1246+ result = options_or_value [star_arch_key ]
1247+ _log .info ("Selected %s from %s for %s (using fallback key %s)" ,
1248+ result , options_or_value , description , star_arch_key )
1249+ except KeyError :
1250+ if allow_none :
1251+ result = None
1252+ else :
1253+ raise EasyBuildError ("No matches for %s in %s (looking for %s)" ,
1254+ description , options_or_value , host_arch_key )
1255+ return result
1256+
1257+
12181258def pick_dep_version (dep_version ):
12191259 """
12201260 Pick the correct dependency version to use for this system.
@@ -1224,39 +1264,14 @@ def pick_dep_version(dep_version):
12241264
12251265 Return value is the version to use.
12261266 """
1227- if isinstance (dep_version , string_type ):
1228- _log .debug ("Version is already a string ('%s'), OK" , dep_version )
1229- result = dep_version
1230-
1231- elif dep_version is None :
1267+ if dep_version is None :
12321268 _log .debug ("Version is None, OK" )
12331269 result = None
1234-
1235- elif isinstance (dep_version , dict ):
1236- arch_keys = [x for x in dep_version .keys () if x .startswith (ARCH_KEY_PREFIX )]
1237- other_keys = [x for x in dep_version .keys () if x not in arch_keys ]
1238- if other_keys :
1239- other_keys = ',' .join (sorted (other_keys ))
1240- raise EasyBuildError ("Unexpected keys in version: %s (only 'arch=' keys are supported)" , other_keys )
1241- if arch_keys :
1242- host_arch_key = ARCH_KEY_PREFIX + get_cpu_architecture ()
1243- star_arch_key = ARCH_KEY_PREFIX + '*'
1244- # check for specific 'arch=' key first
1245- if host_arch_key in dep_version :
1246- result = dep_version [host_arch_key ]
1247- _log .info ("Version selected from %s using key %s: %s" , dep_version , host_arch_key , result )
1248- # fall back to 'arch=*'
1249- elif star_arch_key in dep_version :
1250- result = dep_version [star_arch_key ]
1251- _log .info ("Version selected for %s using fallback key %s: %s" , dep_version , star_arch_key , result )
1252- else :
1253- raise EasyBuildError ("No matches for version in %s (looking for %s)" , dep_version , host_arch_key )
1254- else :
1255- raise EasyBuildError ("Found empty dict as version!" )
1256-
12571270 else :
1258- typ = type (dep_version )
1259- raise EasyBuildError ("Unknown value type for version: %s (%s), should be string value" , typ , dep_version )
1271+ result = pick_system_specific_value ("version" , dep_version )
1272+ if not isinstance (result , string_type ):
1273+ typ = type (dep_version )
1274+ raise EasyBuildError ("Unknown value type for version: %s (%s), should be string value" , typ , dep_version )
12601275
12611276 return result
12621277
0 commit comments