summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-06-17 15:47:59 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2017-08-01 17:40:54 -0700
commitbd94a1706684e135af6b2d5bb62d35e8b8263e79 (patch)
tree39411f366d6d0c8780eae7c115125ba7e165b033
parent43f576cf19c5fb3af83e39c21db802b2d2f254e8 (diff)
downloadspack-bd94a1706684e135af6b2d5bb62d35e8b8263e79.tar.gz
spack-bd94a1706684e135af6b2d5bb62d35e8b8263e79.tar.bz2
spack-bd94a1706684e135af6b2d5bb62d35e8b8263e79.tar.xz
spack-bd94a1706684e135af6b2d5bb62d35e8b8263e79.zip
Remove last vestiges of "special" deptypes.
- Remove `special_types` dict in spec.py, as only 'all' is still used - Still allow 'all' to be used as a deptype - Simplify `canonical_deptype` function - Clean up args in spack graph - Add tests
-rw-r--r--lib/spack/spack/cmd/graph.py3
-rw-r--r--lib/spack/spack/directives.py3
-rw-r--r--lib/spack/spack/spec.py41
-rw-r--r--lib/spack/spack/test/spec_dag.py53
4 files changed, 64 insertions, 36 deletions
diff --git a/lib/spack/spack/cmd/graph.py b/lib/spack/spack/cmd/graph.py
index e42e355f8f..e750e5a959 100644
--- a/lib/spack/spack/cmd/graph.py
+++ b/lib/spack/spack/cmd/graph.py
@@ -90,7 +90,8 @@ def graph(parser, args):
deptype = alldeps
if args.deptype:
deptype = tuple(args.deptype.split(','))
- validate_deptype(deptype)
+ if deptype == ('all',):
+ deptype = 'all'
deptype = canonical_deptype(deptype)
if args.dot: # Dot graph only if asked for.
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py
index 52e4b83dce..2e8b32e5af 100644
--- a/lib/spack/spack/directives.py
+++ b/lib/spack/spack/directives.py
@@ -241,8 +241,7 @@ def _depends_on(pkg, spec, when=None, type=None):
# but is most backwards-compatible.
type = ('build', 'link')
- if isinstance(type, str):
- type = spack.spec.special_types.get(type, (type,))
+ type = spack.spec.canonical_deptype(type)
for deptype in type:
if deptype not in spack.spec.alldeps:
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 992930da65..71d9f4aac1 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -137,7 +137,6 @@ __all__ = [
'Spec',
'alldeps',
'canonical_deptype',
- 'validate_deptype',
'parse',
'parse_anonymous_spec',
'SpecError',
@@ -150,7 +149,6 @@ __all__ = [
'DuplicateArchitectureError',
'InconsistentSpecError',
'InvalidDependencyError',
- 'InvalidDependencyTypeError',
'NoProviderError',
'MultipleProviderError',
'UnsatisfiableSpecError',
@@ -197,44 +195,27 @@ _separators = '[%s]' % ''.join(color_formats.keys())
every time we call str()"""
_any_version = VersionList([':'])
-# Special types of dependencies.
+"""Types of dependencies that Spack understands."""
alldeps = ('build', 'link', 'run')
-norun = ('link', 'build')
-special_types = {
- 'alldeps': alldeps,
- 'all': alldeps, # allow "all" as string but not symbol.
- 'norun': norun,
-}
-
-legal_deps = tuple(special_types) + alldeps
"""Max integer helps avoid passing too large a value to cyaml."""
maxint = 2 ** (ctypes.sizeof(ctypes.c_int) * 8 - 1) - 1
-def validate_deptype(deptype):
- if isinstance(deptype, str):
- if deptype not in legal_deps:
- raise InvalidDependencyTypeError(
- "Invalid dependency type: %s" % deptype)
-
- elif isinstance(deptype, (list, tuple)):
- for t in deptype:
- validate_deptype(t)
-
- elif deptype is None:
- raise InvalidDependencyTypeError("deptype cannot be None!")
-
-
def canonical_deptype(deptype):
- if deptype is None:
+ if deptype in (None, 'all', all):
return alldeps
elif isinstance(deptype, string_types):
- return special_types.get(deptype, (deptype,))
+ if deptype not in alldeps:
+ raise ValueError('Invalid dependency type: %s' % deptype)
+ return (deptype,)
elif isinstance(deptype, (tuple, list)):
- return (sum((canonical_deptype(d) for d in deptype), ()))
+ invalid = next((d for d in deptype if d not in alldeps), None)
+ if invalid:
+ raise ValueError('Invalid dependency type: %s' % invalid)
+ return tuple(sorted(deptype))
return deptype
@@ -3338,10 +3319,6 @@ class InvalidDependencyError(SpecError):
of the package."""
-class InvalidDependencyTypeError(SpecError):
- """Raised when a dependency type is not a legal Spack dep type."""
-
-
class NoProviderError(SpecError):
"""Raised when there is no package that provides a particular
virtual dependency.
diff --git a/lib/spack/spack/test/spec_dag.py b/lib/spack/spack/test/spec_dag.py
index 07a9b72e09..c82365ad11 100644
--- a/lib/spack/spack/test/spec_dag.py
+++ b/lib/spack/spack/test/spec_dag.py
@@ -30,7 +30,7 @@ import spack
import spack.architecture
import spack.package
-from spack.spec import Spec
+from spack.spec import Spec, canonical_deptype, alldeps
def check_links(spec_to_check):
@@ -737,3 +737,54 @@ class TestSpecDag(object):
with pytest.raises(AttributeError):
q.libs
+
+ def test_canonical_deptype(self):
+ # special values
+ assert canonical_deptype(all) == alldeps
+ assert canonical_deptype('all') == alldeps
+ assert canonical_deptype(None) == alldeps
+
+ # everything in alldeps is canonical
+ for v in alldeps:
+ assert canonical_deptype(v) == (v,)
+
+ # tuples
+ assert canonical_deptype(('build',)) == ('build',)
+ assert canonical_deptype(
+ ('build', 'link', 'run')) == ('build', 'link', 'run')
+ assert canonical_deptype(
+ ('build', 'link')) == ('build', 'link')
+ assert canonical_deptype(
+ ('build', 'run')) == ('build', 'run')
+
+ # lists
+ assert canonical_deptype(
+ ['build', 'link', 'run']) == ('build', 'link', 'run')
+ assert canonical_deptype(
+ ['build', 'link']) == ('build', 'link')
+ assert canonical_deptype(
+ ['build', 'run']) == ('build', 'run')
+
+ # sorting
+ assert canonical_deptype(
+ ('run', 'build', 'link')) == ('build', 'link', 'run')
+ assert canonical_deptype(
+ ('run', 'link', 'build')) == ('build', 'link', 'run')
+ assert canonical_deptype(
+ ('run', 'link')) == ('link', 'run')
+ assert canonical_deptype(
+ ('link', 'build')) == ('build', 'link')
+
+ # can't put 'all' in tuple or list
+ with pytest.raises(ValueError):
+ canonical_deptype(['all'])
+ with pytest.raises(ValueError):
+ canonical_deptype(('all',))
+
+ # invalid values
+ with pytest.raises(ValueError):
+ canonical_deptype('foo')
+ with pytest.raises(ValueError):
+ canonical_deptype(('foo', 'bar'))
+ with pytest.raises(ValueError):
+ canonical_deptype(('foo',))