flake8 fixes
This commit is contained in:
parent
b7d9b58cc5
commit
5ffc50732b
1 changed files with 56 additions and 43 deletions
|
@ -26,8 +26,10 @@
|
|||
import spack
|
||||
from spack.version import *
|
||||
|
||||
|
||||
class PreferredPackages(object):
|
||||
_default_order = {'compiler' : [ 'gcc', 'intel', 'clang', 'pgi', 'xlc' ] } # Arbitrary, but consistent
|
||||
# Arbitrary, but consistent
|
||||
_default_order = {'compiler': ['gcc', 'intel', 'clang', 'pgi', 'xlc']}
|
||||
|
||||
def __init__(self):
|
||||
self.preferred = spack.config.get_config('packages')
|
||||
|
@ -35,7 +37,8 @@ def __init__(self):
|
|||
|
||||
# Given a package name, sort component (e.g, version, compiler, ...), and
|
||||
# a second_key (used by providers), return the list
|
||||
def _order_for_package(self, pkgname, component, second_key, test_all=True):
|
||||
def _order_for_package(self, pkgname, component, second_key,
|
||||
test_all=True):
|
||||
pkglist = [pkgname]
|
||||
if test_all:
|
||||
pkglist.append('all')
|
||||
|
@ -48,11 +51,11 @@ def _order_for_package(self, pkgname, component, second_key, test_all=True):
|
|||
return [str(s).strip() for s in order]
|
||||
return []
|
||||
|
||||
|
||||
# A generic sorting function. Given a package name and sort
|
||||
# component, return less-than-0, 0, or greater-than-0 if
|
||||
# a is respectively less-than, equal to, or greater than b.
|
||||
def _component_compare(self, pkgname, component, a, b, reverse_natural_compare, second_key):
|
||||
def _component_compare(self, pkgname, component, a, b,
|
||||
reverse_natural_compare, second_key):
|
||||
if a is None:
|
||||
return -1
|
||||
if b is None:
|
||||
|
@ -84,11 +87,11 @@ def _component_compare(self, pkgname, component, a, b, reverse_natural_compare,
|
|||
else:
|
||||
return 0
|
||||
|
||||
|
||||
# A sorting function for specs. Similar to component_compare, but
|
||||
# a and b are considered to match entries in the sorting list if they
|
||||
# satisfy the list component.
|
||||
def _spec_compare(self, pkgname, component, a, b, reverse_natural_compare, second_key):
|
||||
def _spec_compare(self, pkgname, component, a, b,
|
||||
reverse_natural_compare, second_key):
|
||||
if not a or (not a.concrete and not second_key):
|
||||
return -1
|
||||
if not b or (not b.concrete and not second_key):
|
||||
|
@ -98,78 +101,88 @@ def _spec_compare(self, pkgname, component, a, b, reverse_natural_compare, secon
|
|||
b_index = None
|
||||
reverse = -1 if reverse_natural_compare else 1
|
||||
for i, cspec in enumerate(specs):
|
||||
if a_index == None and (cspec.satisfies(a) or a.satisfies(cspec)):
|
||||
if a_index is None and (cspec.satisfies(a) or a.satisfies(cspec)):
|
||||
a_index = i
|
||||
if b_index:
|
||||
break
|
||||
if b_index == None and (cspec.satisfies(b) or b.satisfies(cspec)):
|
||||
if b_index is None and (cspec.satisfies(b) or b.satisfies(cspec)):
|
||||
b_index = i
|
||||
if a_index:
|
||||
break
|
||||
|
||||
if a_index != None and b_index == None: return -1
|
||||
elif a_index == None and b_index != None: return 1
|
||||
elif a_index != None and b_index == a_index: return -1 * cmp(a, b)
|
||||
elif a_index != None and b_index != None and a_index != b_index: return cmp(a_index, b_index)
|
||||
else: return cmp(a, b) * reverse
|
||||
|
||||
|
||||
if a_index is not None and b_index is None:
|
||||
return -1
|
||||
elif a_index is None and b_index is not None:
|
||||
return 1
|
||||
elif a_index is not None and b_index == a_index:
|
||||
return -1 * cmp(a, b)
|
||||
elif (a_index is not None and b_index is not None and
|
||||
a_index != b_index):
|
||||
return cmp(a_index, b_index)
|
||||
else:
|
||||
return cmp(a, b) * reverse
|
||||
|
||||
# Given a sort order specified by the pkgname/component/second_key, return
|
||||
# a list of CompilerSpecs, VersionLists, or Specs for that sorting list.
|
||||
def _spec_for_pkgname(self, pkgname, component, second_key):
|
||||
key = (pkgname, component, second_key)
|
||||
if not key in self._spec_for_pkgname_cache:
|
||||
if key not in self._spec_for_pkgname_cache:
|
||||
pkglist = self._order_for_package(pkgname, component, second_key)
|
||||
if not pkglist:
|
||||
if component in self._default_order:
|
||||
pkglist = self._default_order[component]
|
||||
if component == 'compiler':
|
||||
self._spec_for_pkgname_cache[key] = [spack.spec.CompilerSpec(s) for s in pkglist]
|
||||
self._spec_for_pkgname_cache[key] = \
|
||||
[spack.spec.CompilerSpec(s) for s in pkglist]
|
||||
elif component == 'version':
|
||||
self._spec_for_pkgname_cache[key] = [VersionList(s) for s in pkglist]
|
||||
self._spec_for_pkgname_cache[key] = \
|
||||
[VersionList(s) for s in pkglist]
|
||||
else:
|
||||
self._spec_for_pkgname_cache[key] = [spack.spec.Spec(s) for s in pkglist]
|
||||
self._spec_for_pkgname_cache[key] = \
|
||||
[spack.spec.Spec(s) for s in pkglist]
|
||||
return self._spec_for_pkgname_cache[key]
|
||||
|
||||
|
||||
def provider_compare(self, pkgname, provider_str, a, b):
|
||||
"""Return less-than-0, 0, or greater than 0 if a is respecively less-than, equal-to, or
|
||||
greater-than b. A and b are possible implementations of provider_str.
|
||||
One provider is less-than another if it is preferred over the other.
|
||||
For example, provider_compare('scorep', 'mpi', 'mvapich', 'openmpi') would return -1 if
|
||||
mvapich should be preferred over openmpi for scorep."""
|
||||
return self._spec_compare(pkgname, 'providers', a, b, False, provider_str)
|
||||
|
||||
"""Return less-than-0, 0, or greater than 0 if a is respecively
|
||||
less-than, equal-to, or greater-than b. A and b are possible
|
||||
implementations of provider_str. One provider is less-than another
|
||||
if it is preferred over the other. For example,
|
||||
provider_compare('scorep', 'mpi', 'mvapich', 'openmpi') would
|
||||
return -1 if mvapich should be preferred over openmpi for scorep."""
|
||||
return self._spec_compare(pkgname, 'providers', a, b, False,
|
||||
provider_str)
|
||||
|
||||
def spec_has_preferred_provider(self, pkgname, provider_str):
|
||||
"""Return True iff the named package has a list of preferred provider"""
|
||||
return bool(self._order_for_package(pkgname, 'providers', provider_str, False))
|
||||
|
||||
"""Return True iff the named package has a list of preferred
|
||||
providers"""
|
||||
return bool(self._order_for_package(pkgname, 'providers',
|
||||
provider_str, False))
|
||||
|
||||
def version_compare(self, pkgname, a, b):
|
||||
"""Return less-than-0, 0, or greater than 0 if version a of pkgname is
|
||||
respecively less-than, equal-to, or greater-than version b of pkgname.
|
||||
One version is less-than another if it is preferred over the other."""
|
||||
respectively less-than, equal-to, or greater-than version b of
|
||||
pkgname. One version is less-than another if it is preferred over
|
||||
the other."""
|
||||
return self._spec_compare(pkgname, 'version', a, b, True, None)
|
||||
|
||||
|
||||
def variant_compare(self, pkgname, a, b):
|
||||
"""Return less-than-0, 0, or greater than 0 if variant a of pkgname is
|
||||
respecively less-than, equal-to, or greater-than variant b of pkgname.
|
||||
One variant is less-than another if it is preferred over the other."""
|
||||
respectively less-than, equal-to, or greater-than variant b of
|
||||
pkgname. One variant is less-than another if it is preferred over
|
||||
the other."""
|
||||
return self._component_compare(pkgname, 'variant', a, b, False, None)
|
||||
|
||||
|
||||
def architecture_compare(self, pkgname, a, b):
|
||||
"""Return less-than-0, 0, or greater than 0 if architecture a of pkgname is
|
||||
respecively less-than, equal-to, or greater-than architecture b of pkgname.
|
||||
One architecture is less-than another if it is preferred over the other."""
|
||||
return self._component_compare(pkgname, 'architecture', a, b, False, None)
|
||||
|
||||
"""Return less-than-0, 0, or greater than 0 if architecture a of pkgname
|
||||
is respectively less-than, equal-to, or greater-than architecture b
|
||||
of pkgname. One architecture is less-than another if it is preferred
|
||||
over the other."""
|
||||
return self._component_compare(pkgname, 'architecture', a, b,
|
||||
False, None)
|
||||
|
||||
def compiler_compare(self, pkgname, a, b):
|
||||
"""Return less-than-0, 0, or greater than 0 if compiler a of pkgname is
|
||||
respecively less-than, equal-to, or greater-than compiler b of pkgname.
|
||||
One compiler is less-than another if it is preferred over the other."""
|
||||
respecively less-than, equal-to, or greater-than compiler b of
|
||||
pkgname. One compiler is less-than another if it is preferred over
|
||||
the other."""
|
||||
return self._spec_compare(pkgname, 'compiler', a, b, False, None)
|
||||
|
|
Loading…
Reference in a new issue