Skip to content

Commit c19ef50

Browse files
committed
Address a few minor points raised in review for spec.py
Fixed docstrings, raise instead of assert, don't inline a for loop to create a tuple
1 parent 455fd15 commit c19ef50

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lib/spack/spack/spec.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,7 @@ def __str__(self):
769769

770770
def _sort_by_dep_types(dspec):
771771
# Use negation since False < True for sorting
772-
return (
773-
'link' not in dspec.deptypes,
774-
'run' not in dspec.deptypes,
775-
'build' not in dspec.deptypes,
776-
'test' not in dspec.deptypes
777-
)
772+
return tuple(t not in dspec.deptypes for t in ("link", "run", "build", "test"))
778773

779774

780775
#: Enum for edge directions
@@ -786,7 +781,7 @@ class _EdgeMap(Mapping):
786781
"""Represent a collection of edges (DependencySpec objects) in the DAG.
787782
788783
Objects of this class are used in Specs to track edges that are
789-
outgoing towards direct dependencies, or edges that are ingoing
784+
outgoing towards direct dependencies, or edges that are incoming
790785
from direct dependents.
791786
792787
Edges are stored in a dictionary and keyed by package name.
@@ -856,9 +851,11 @@ def copy(self):
856851
return clone
857852

858853
def select_by(self, parent=None, child=None, dependency_types='all'):
859-
"""Return a list of edges selected by dependency types.
854+
"""Select a list of edges and return them.
860855
861-
If an edge has any of the dependency types passed as argument
856+
If an edge:
857+
- Has *any* of the dependency types passed as argument,
858+
- Matches the parent and/or child name, if passed
862859
then it is selected.
863860
864861
Args:
@@ -1308,8 +1305,9 @@ def _get_dependency(self, name):
13081305
# WARNING: using index 0 i.e. we assume that we have only
13091306
# WARNING: one edge from package "name"
13101307
deps = self.edges_to_dependencies(name=name)
1311-
err_msg = 'expected only 1 "{0}" dependency, but got {1}'
1312-
assert len(deps) == 1, err_msg.format(name, len(deps))
1308+
if len(deps) != 1:
1309+
err_msg = 'expected only 1 "{0}" dependency, but got {1}'
1310+
raise spack.error.SpecError(err_msg.format(name, len(deps)))
13131311
return deps[0]
13141312

13151313
def edges_from_dependents(self, name=None, deptype='all'):

0 commit comments

Comments
 (0)