@@ -1257,48 +1257,63 @@ def check_python_version():
12571257 return (python_maj_ver , python_min_ver )
12581258
12591259
1260+ def pick_system_specific_value (description , options_or_value , allow_none = False ):
1261+ """Pick an entry for the current system when the input has multiple options
1262+
1263+ :param description: Descriptive string about the value to be retrieved. Used for logging.
1264+ :param options_or_value: Either a dictionary with options to choose from or a value of any other type
1265+ :param allow_none: When True and no matching arch key was found, return None instead of an error
1266+
1267+ :return options_or_value when it is not a dictionary or the matching entry (if existing)
1268+ """
1269+ result = options_or_value
1270+ if isinstance (options_or_value , dict ):
1271+ if not options_or_value :
1272+ raise EasyBuildError ("Found empty dict as %s!" , description )
1273+ other_keys = [x for x in options_or_value .keys () if not x .startswith (ARCH_KEY_PREFIX )]
1274+ if other_keys :
1275+ other_keys = ',' .join (sorted (other_keys ))
1276+ raise EasyBuildError ("Unexpected keys in %s: %s (only '%s' keys are supported)" ,
1277+ description , other_keys , ARCH_KEY_PREFIX )
1278+ host_arch_key = ARCH_KEY_PREFIX + get_cpu_architecture ()
1279+ star_arch_key = ARCH_KEY_PREFIX + '*'
1280+ # check for specific 'arch=' key first
1281+ try :
1282+ result = options_or_value [host_arch_key ]
1283+ _log .info ("Selected %s from %s for %s (using key %s)" ,
1284+ result , options_or_value , description , host_arch_key )
1285+ except KeyError :
1286+ # fall back to 'arch=*'
1287+ try :
1288+ result = options_or_value [star_arch_key ]
1289+ _log .info ("Selected %s from %s for %s (using fallback key %s)" ,
1290+ result , options_or_value , description , star_arch_key )
1291+ except KeyError :
1292+ if allow_none :
1293+ result = None
1294+ else :
1295+ raise EasyBuildError ("No matches for %s in %s (looking for %s)" ,
1296+ description , options_or_value , host_arch_key )
1297+ return result
1298+
1299+
12601300def pick_dep_version (dep_version ):
12611301 """
12621302 Pick the correct dependency version to use for this system.
12631303 Input can either be:
12641304 * a string value (or None)
12651305 * a dict with options to choose from
12661306
1267- Return value is the version to use.
1307+ Return value is the version to use or False to skip this dependency .
12681308 """
1269- if isinstance (dep_version , string_type ):
1270- _log .debug ("Version is already a string ('%s'), OK" , dep_version )
1271- result = dep_version
1272-
1273- elif dep_version is None :
1309+ if dep_version is None :
12741310 _log .debug ("Version is None, OK" )
12751311 result = None
1276-
1277- elif isinstance (dep_version , dict ):
1278- arch_keys = [x for x in dep_version .keys () if x .startswith (ARCH_KEY_PREFIX )]
1279- other_keys = [x for x in dep_version .keys () if x not in arch_keys ]
1280- if other_keys :
1281- other_keys = ',' .join (sorted (other_keys ))
1282- raise EasyBuildError ("Unexpected keys in version: %s (only 'arch=' keys are supported)" , other_keys )
1283- if arch_keys :
1284- host_arch_key = ARCH_KEY_PREFIX + get_cpu_architecture ()
1285- star_arch_key = ARCH_KEY_PREFIX + '*'
1286- # check for specific 'arch=' key first
1287- if host_arch_key in dep_version :
1288- result = dep_version [host_arch_key ]
1289- _log .info ("Version selected from %s using key %s: %s" , dep_version , host_arch_key , result )
1290- # fall back to 'arch=*'
1291- elif star_arch_key in dep_version :
1292- result = dep_version [star_arch_key ]
1293- _log .info ("Version selected for %s using fallback key %s: %s" , dep_version , star_arch_key , result )
1294- else :
1295- raise EasyBuildError ("No matches for version in %s (looking for %s)" , dep_version , host_arch_key )
1296- else :
1297- raise EasyBuildError ("Found empty dict as version!" )
1298-
12991312 else :
1300- typ = type (dep_version )
1301- raise EasyBuildError ("Unknown value type for version: %s (%s), should be string value" , typ , dep_version )
1313+ result = pick_system_specific_value ("version" , dep_version )
1314+ if not isinstance (result , string_type ) and result is not False :
1315+ typ = type (dep_version )
1316+ raise EasyBuildError ("Unknown value type for version: %s (%s), should be string value" , typ , dep_version )
13021317
13031318 return result
13041319
0 commit comments