summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2022-02-25 13:53:26 +0100
committerMassimiliano Culpo <massimiliano.culpo@gmail.com>2022-04-14 11:08:17 +0200
commit9d8e411d76d43c4a1a86cfd3fd29cc8bc235700c (patch)
tree6634840d909bfe033d85baa2619d682cde5540ae
parentfbdcd7cbf178e1dc6ec597c1a35944d527026dda (diff)
downloadspack-9d8e411d76d43c4a1a86cfd3fd29cc8bc235700c.tar.gz
spack-9d8e411d76d43c4a1a86cfd3fd29cc8bc235700c.tar.bz2
spack-9d8e411d76d43c4a1a86cfd3fd29cc8bc235700c.tar.xz
spack-9d8e411d76d43c4a1a86cfd3fd29cc8bc235700c.zip
VersionRange.satisfies should test non-empty intersection
-rw-r--r--lib/spack/spack/version.py38
1 files changed, 13 insertions, 25 deletions
diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py
index b943550240..515ce329f3 100644
--- a/lib/spack/spack/version.py
+++ b/lib/spack/spack/version.py
@@ -586,35 +586,23 @@ class VersionRange(object):
@coerced
def satisfies(self, other):
- """A VersionRange satisfies another if some version in this range
- would satisfy some version in the other range. To do this it must
- either:
-
- a) Overlap with the other range
- b) The start of this range satisfies the end of the other range.
-
- This is essentially the same as overlaps(), but overlaps assumes
- that its arguments are specific. That is, 4.7 is interpreted as
- 4.7.0.0.0.0... . This function assumes that 4.7 would be satisfied
- by 4.7.3.5, etc.
-
- Rationale:
+ """
+ x.satisfies(y) in general means that x and y have a
+ non-zero intersection. For VersionRange this means they overlap.
- If a user asks for gcc@4.5:4.7, and a package is only compatible with
- gcc@4.7.3:4.8, then that package should be able to build under the
- constraints. Just using overlaps() would not work here.
+ `satisfies` is a commutative binary operator, meaning that
+ x.satisfies(y) if and only if y.satisfies(x).
- Note that we don't need to check whether the end of this range
- would satisfy the start of the other range, because overlaps()
- already covers that case.
+ Note: in some cases we have the keyword x.satisfies(y, strict=True)
+ to mean strict set inclusion, which is not commutative. However, this
+ lacks in VersionRange for unknown reasons.
- Note further that overlaps() is a symmetric operation, while
- satisfies() is not.
+ Examples
+ - 1:3 satisfies 2:4, as their intersection is 2:3.
+ - 1:2 does not satisfy 3:4, as their intersection is empty.
+ - 4.5:4.7 satisfies 4.7.2:4.8, as their intersection is 4.7.2:4.7
"""
- return (self.overlaps(other) or
- # if either self.start or other.end are None, then this can't
- # satisfy, or overlaps() would've taken care of it.
- self.start and other.end and self.start.satisfies(other.end))
+ return self.overlaps(other)
@coerced
def overlaps(self, other):