flake8 fixes

This commit is contained in:
Michael Kuhn 2016-07-13 23:05:08 +02:00
parent b7d9b58cc5
commit 5ffc50732b

View file

@ -26,8 +26,10 @@
import spack import spack
from spack.version import * from spack.version import *
class PreferredPackages(object): 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): def __init__(self):
self.preferred = spack.config.get_config('packages') 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 # Given a package name, sort component (e.g, version, compiler, ...), and
# a second_key (used by providers), return the list # 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] pkglist = [pkgname]
if test_all: if test_all:
pkglist.append('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 [str(s).strip() for s in order]
return [] return []
# A generic sorting function. Given a package name and sort # A generic sorting function. Given a package name and sort
# component, return less-than-0, 0, or greater-than-0 if # component, return less-than-0, 0, or greater-than-0 if
# a is respectively less-than, equal to, or greater than b. # 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: if a is None:
return -1 return -1
if b is None: if b is None:
@ -84,11 +87,11 @@ def _component_compare(self, pkgname, component, a, b, reverse_natural_compare,
else: else:
return 0 return 0
# A sorting function for specs. Similar to component_compare, but # A sorting function for specs. Similar to component_compare, but
# a and b are considered to match entries in the sorting list if they # a and b are considered to match entries in the sorting list if they
# satisfy the list component. # 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): if not a or (not a.concrete and not second_key):
return -1 return -1
if not b or (not b.concrete and not second_key): 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 b_index = None
reverse = -1 if reverse_natural_compare else 1 reverse = -1 if reverse_natural_compare else 1
for i, cspec in enumerate(specs): 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 a_index = i
if b_index: if b_index:
break 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 b_index = i
if a_index: if a_index:
break break
if a_index != None and b_index == None: return -1 if a_index is not None and b_index is None:
elif a_index == None and b_index != None: return 1 return -1
elif a_index != None and b_index == a_index: return -1 * cmp(a, b) elif a_index is None and b_index is not None:
elif a_index != None and b_index != None and a_index != b_index: return cmp(a_index, b_index) return 1
else: return cmp(a, b) * reverse 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 # Given a sort order specified by the pkgname/component/second_key, return
# a list of CompilerSpecs, VersionLists, or Specs for that sorting list. # a list of CompilerSpecs, VersionLists, or Specs for that sorting list.
def _spec_for_pkgname(self, pkgname, component, second_key): def _spec_for_pkgname(self, pkgname, component, second_key):
key = (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) pkglist = self._order_for_package(pkgname, component, second_key)
if not pkglist: if not pkglist:
if component in self._default_order: if component in self._default_order:
pkglist = self._default_order[component] pkglist = self._default_order[component]
if component == 'compiler': 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': 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: 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] return self._spec_for_pkgname_cache[key]
def provider_compare(self, pkgname, provider_str, a, b): 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 """Return less-than-0, 0, or greater than 0 if a is respecively
greater-than b. A and b are possible implementations of provider_str. less-than, equal-to, or greater-than b. A and b are possible
One provider is less-than another if it is preferred over the other. implementations of provider_str. One provider is less-than another
For example, provider_compare('scorep', 'mpi', 'mvapich', 'openmpi') would return -1 if if it is preferred over the other. For example,
mvapich should be preferred over openmpi for scorep.""" provider_compare('scorep', 'mpi', 'mvapich', 'openmpi') would
return self._spec_compare(pkgname, 'providers', a, b, False, provider_str) 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): def spec_has_preferred_provider(self, pkgname, provider_str):
"""Return True iff the named package has a list of preferred provider""" """Return True iff the named package has a list of preferred
return bool(self._order_for_package(pkgname, 'providers', provider_str, False)) providers"""
return bool(self._order_for_package(pkgname, 'providers',
provider_str, False))
def version_compare(self, pkgname, a, b): def version_compare(self, pkgname, a, b):
"""Return less-than-0, 0, or greater than 0 if version a of pkgname is """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. respectively less-than, equal-to, or greater-than version b of
One version is less-than another if it is preferred over the other.""" pkgname. One version is less-than another if it is preferred over
the other."""
return self._spec_compare(pkgname, 'version', a, b, True, None) return self._spec_compare(pkgname, 'version', a, b, True, None)
def variant_compare(self, pkgname, a, b): def variant_compare(self, pkgname, a, b):
"""Return less-than-0, 0, or greater than 0 if variant a of pkgname is """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. respectively less-than, equal-to, or greater-than variant b of
One variant is less-than another if it is preferred over the other.""" pkgname. One variant is less-than another if it is preferred over
the other."""
return self._component_compare(pkgname, 'variant', a, b, False, None) return self._component_compare(pkgname, 'variant', a, b, False, None)
def architecture_compare(self, pkgname, a, b): def architecture_compare(self, pkgname, a, b):
"""Return less-than-0, 0, or greater than 0 if architecture a of pkgname is """Return less-than-0, 0, or greater than 0 if architecture a of pkgname
respecively less-than, equal-to, or greater-than architecture b of pkgname. is respectively less-than, equal-to, or greater-than architecture b
One architecture is less-than another if it is preferred over the other.""" of pkgname. One architecture is less-than another if it is preferred
return self._component_compare(pkgname, 'architecture', a, b, False, None) over the other."""
return self._component_compare(pkgname, 'architecture', a, b,
False, None)
def compiler_compare(self, pkgname, a, b): def compiler_compare(self, pkgname, a, b):
"""Return less-than-0, 0, or greater than 0 if compiler a of pkgname is """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. respecively less-than, equal-to, or greater-than compiler b of
One compiler is less-than another if it is preferred over the other.""" pkgname. One compiler is less-than another if it is preferred over
the other."""
return self._spec_compare(pkgname, 'compiler', a, b, False, None) return self._spec_compare(pkgname, 'compiler', a, b, False, None)