summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorbecker33 <becker33@llnl.gov>2016-07-18 16:47:08 -0700
committerGitHub <noreply@github.com>2016-07-18 16:47:08 -0700
commit013cfafe5751d73f350c9c4a86019a76d0f7e80d (patch)
treea343bfe28b7783c30d049bfeb6d037da0daefcde /lib
parent25a9181a1b51b0b1f8f5004b18a4f49b683d1536 (diff)
parent19df1ea79d5539986652de84782856bcc7a84037 (diff)
downloadspack-013cfafe5751d73f350c9c4a86019a76d0f7e80d.tar.gz
spack-013cfafe5751d73f350c9c4a86019a76d0f7e80d.tar.bz2
spack-013cfafe5751d73f350c9c4a86019a76d0f7e80d.tar.xz
spack-013cfafe5751d73f350c9c4a86019a76d0f7e80d.zip
Merge pull request #1229 from suraia/fix-preferred-providers
Fix preferred providers.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/preferred_packages.py105
-rw-r--r--lib/spack/spack/test/modules.py3
2 files changed, 60 insertions, 48 deletions
diff --git a/lib/spack/spack/preferred_packages.py b/lib/spack/spack/preferred_packages.py
index 4820584150..1b94f03de7 100644
--- a/lib/spack/spack/preferred_packages.py
+++ b/lib/spack/spack/preferred_packages.py
@@ -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,24 +37,25 @@ class PreferredPackages(object):
# 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')
for pkg in pkglist:
order = self.preferred.get(pkg, {}).get(component, {})
- if type(order) is dict:
+ if isinstance(order, dict) and second_key:
order = order.get(second_key, {})
if not order:
continue
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,92 +87,102 @@ class PreferredPackages(object):
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):
- if not a or not a.concrete:
+ 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:
+ if not b or (not b.concrete and not second_key):
return 1
specs = self._spec_for_pkgname(pkgname, component, second_key)
a_index = None
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)
diff --git a/lib/spack/spack/test/modules.py b/lib/spack/spack/test/modules.py
index 6d2e3705bd..135cd028e3 100644
--- a/lib/spack/spack/test/modules.py
+++ b/lib/spack/spack/test/modules.py
@@ -27,7 +27,6 @@ from contextlib import contextmanager
import StringIO
import spack.modules
-import unittest
from spack.test.mock_packages_test import MockPackagesTest
FILE_REGISTRY = collections.defaultdict(StringIO.StringIO)
@@ -266,7 +265,7 @@ class TclTests(MockPackagesTest):
def test_blacklist(self):
spack.modules.CONFIGURATION = configuration_blacklist
- spec = spack.spec.Spec('mpileaks')
+ spec = spack.spec.Spec('mpileaks ^zmpi')
content = self.get_modulefile_content(spec)
self.assertEqual(len([x for x in content if 'is-loaded' in x]), 1)
self.assertEqual(len([x for x in content if 'module load ' in x]), 1)