diff --git a/src/rez/tests/test_version.py b/src/rez/tests/test_version.py index 3449e66daf..72c26b612d 100644 --- a/src/rez/tests/test_version.py +++ b/src/rez/tests/test_version.py @@ -32,12 +32,12 @@ def _test_strict_weak_ordering(self, a, b): self.assertTrue(a == a) self.assertTrue(b == b) - e = (a == b) - ne = (a != b) - lt = (a < b) - lte = (a <= b) - gt = (a > b) - gte = (a >= b) + e = (a == b) + ne = (a != b) + lt = (a < b) + lte = (a <= b) + gt = (a > b) + gte = (a >= b) _print('\n' + textwrap.dedent( """ @@ -69,7 +69,7 @@ def _test_strict_weak_ordering(self, a, b): def _test_ordered(self, items): def _test(fn, items_, op_str): for i, a in enumerate(items_): - for b in items_[i+1:]: + for b in items_[i + 1:]: _print("'%s' %s '%s'" % (a, op_str, b)) self.assertTrue(fn(a, b)) diff --git a/src/rez/version/__init__.py b/src/rez/version/__init__.py index 6be60ef812..7280b98532 100644 --- a/src/rez/version/__init__.py +++ b/src/rez/version/__init__.py @@ -2,9 +2,9 @@ # Copyright Contributors to the Rez Project -from rez.version._requirement import Requirement, RequirementList, VersionedObject -from rez.version._util import ParseException, VersionError -from rez.version._version import ( +from rez.version._requirement import Requirement, RequirementList, VersionedObject # noqa: F401 +from rez.version._util import ParseException, VersionError # noqa: F401 +from rez.version._version import ( # noqa: F401 AlphanumericVersionToken, NumericToken, Version, diff --git a/src/rez/version/_version.py b/src/rez/version/_version.py index edfdb3f918..25b6671845 100644 --- a/src/rez/version/_version.py +++ b/src/rez/version/_version.py @@ -448,6 +448,7 @@ def contains_version(self, version): return (version > self.version) \ or (self.inclusive and (version == self.version)) + _LowerBound.min = _LowerBound(Version(), True) @@ -480,6 +481,7 @@ def contains_version(self, version): return (version < self.version) \ or (self.inclusive and (version == self.version)) + _UpperBound.inf = _UpperBound(Version.inf, True) @@ -490,10 +492,13 @@ def __init__(self, lower=None, upper=None, invalid_bound_error=True): self.lower = lower or _LowerBound.min self.upper = upper or _UpperBound.inf - if (invalid_bound_error and - (self.lower.version > self.upper.version - or ((self.lower.version == self.upper.version) - and not (self.lower.inclusive and self.upper.inclusive)))): + if invalid_bound_error and ( + self.lower.version > self.upper.version + or ( + (self.lower.version == self.upper.version) + and not (self.lower.inclusive and self.upper.inclusive) + ) + ): raise VersionError("Invalid bound") def __str__(self): @@ -544,21 +549,22 @@ def intersects(self, other): lower = max(self.lower, other.lower) upper = min(self.upper, other.upper) - return (lower.version < upper.version) or \ - ((lower.version == upper.version) and - (lower.inclusive and upper.inclusive)) + return (lower.version < upper.version) or ( + (lower.version == upper.version) and (lower.inclusive and upper.inclusive) + ) def intersection(self, other): lower = max(self.lower, other.lower) upper = min(self.upper, other.upper) - if (lower.version < upper.version) or \ - ((lower.version == upper.version) and - (lower.inclusive and upper.inclusive)): + if (lower.version < upper.version) or ( + (lower.version == upper.version) and (lower.inclusive and upper.inclusive) + ): return _Bound(lower, upper) else: return None + _Bound.any = _Bound() @@ -597,7 +603,7 @@ class _VersionRangeParser(object): # Or match an inclusive bound (e.g. 1.0.0..2.0.0) " ^(?P" " (?P{version_group})?" - " \.\." # Required .. operator + r" \.\." # Required .. operator " (?P{version_group})?" " )$" "|" @@ -605,7 +611,7 @@ class _VersionRangeParser(object): " ^(?P" " (?P>|>=)?" # Bound is exclusive? " (?P{version_group})?" - " (?(lower_bound_prefix)|\+)" # + only if bound is not exclusive + r" (?(lower_bound_prefix)|\+)" # + only if bound is not exclusive " )$" "|" # Or match an upper bound (e.g. <=1.0.0) @@ -619,7 +625,7 @@ class _VersionRangeParser(object): " (?P" " (?P>|>=)?" # Lower bound is exclusive? " (?P{version_group})?" - " (?(range_lower_asc_prefix)|\+)?" # + only if lower bound is not exclusive + r" (?(range_lower_asc_prefix)|\+)?" # + only if lower bound is not exclusive " )(?P" " (?(range_lower_asc_version),?|)" # , only if lower bound is found " (?P<(?={version_group})|<=)" # <= only if followed by a version group @@ -632,10 +638,12 @@ class _VersionRangeParser(object): " (?P" " (?P<|<=)?" # Upper bound is exclusive? " (?P{version_group})?" - " (?(range_upper_desc_prefix)|\+)?" # + only if upper bound is not exclusive + r" (?(range_upper_desc_prefix)|\+)?" # + only if upper bound is not exclusive " )(?P" - " (?(range_upper_desc_version),|)" # Comma is not optional because we don't want to recognize something like "<4>3" - " (?P<(?={version_group})|>=?)" # >= or > only if followed by a version group + " (?(range_upper_desc_version),|)" # Comma is not optional because we don't want + # to recognize something like "<4>3" + " (?P<(?={version_group})|>=?)" # >= or > only if followed + # by a version group " (?P{version_group})?" " )" " )$" @@ -1131,8 +1139,9 @@ def iter_intersecting(self, iterable, key=None, descending=False): Returns: An iterator that returns items from `iterable` that intersect. """ - return _ContainsVersionIterator(self, iterable, key, descending, - mode=_ContainsVersionIterator.MODE_INTERSECTING) + return _ContainsVersionIterator( + self, iterable, key, descending, mode=_ContainsVersionIterator.MODE_INTERSECTING + ) def iter_non_intersecting(self, iterable, key=None, descending=False): """Like `iter_intersect_test`, but returns non-intersections only. @@ -1140,8 +1149,9 @@ def iter_non_intersecting(self, iterable, key=None, descending=False): Returns: An iterator that returns items from `iterable` that don't intersect. """ - return _ContainsVersionIterator(self, iterable, key, descending, - mode=_ContainsVersionIterator.MODE_NON_INTERSECTING) + return _ContainsVersionIterator( + self, iterable, key, descending, mode=_ContainsVersionIterator.MODE_NON_INTERSECTING + ) def span(self): """Return a contiguous range that is a superset of this range. @@ -1352,7 +1362,7 @@ def __init__(self, range_, iterable, key=None, descending=False, mode=MODE_ALL): self.fn = self._descending if descending else self._ascending self.it = iter(iterable) if key is None: - key = lambda x: x + key = lambda x: x # noqa: E731 self.keyfunc = key if mode == self.MODE_ALL: