Skip to content

Commit

Permalink
Fix flake8 warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Oct 28, 2023
1 parent dc04cf5 commit 62da43f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
14 changes: 7 additions & 7 deletions src/rez/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions src/rez/version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 31 additions & 21 deletions src/rez/version/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand All @@ -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):
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -597,15 +603,15 @@ class _VersionRangeParser(object):
# Or match an inclusive bound (e.g. 1.0.0..2.0.0)
" ^(?P<inclusive_bound>"
" (?P<inclusive_lower_version>{version_group})?"
" \.\." # Required .. operator
r" \.\." # Required .. operator
" (?P<inclusive_upper_version>{version_group})?"
" )$"
"|"
# Or match a lower bound (e.g. 1.0.0+)
" ^(?P<lower_bound>"
" (?P<lower_bound_prefix>>|>=)?" # Bound is exclusive?
" (?P<lower_version>{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)
Expand All @@ -619,7 +625,7 @@ class _VersionRangeParser(object):
" (?P<range_lower_asc>"
" (?P<range_lower_asc_prefix>>|>=)?" # Lower bound is exclusive?
" (?P<range_lower_asc_version>{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_upper_asc>"
" (?(range_lower_asc_version),?|)" # , only if lower bound is found
" (?P<range_upper_asc_prefix><(?={version_group})|<=)" # <= only if followed by a version group
Expand All @@ -632,10 +638,12 @@ class _VersionRangeParser(object):
" (?P<range_upper_desc>"
" (?P<range_upper_desc_prefix><|<=)?" # Upper bound is exclusive?
" (?P<range_upper_desc_version>{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_lower_desc>"
" (?(range_upper_desc_version),|)" # Comma is not optional because we don't want to recognize something like "<4>3"
" (?P<range_lower_desc_prefix><(?={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<range_lower_desc_prefix><(?={version_group})|>=?)" # >= or > only if followed
# by a version group
" (?P<range_lower_desc_version>{version_group})?"
" )"
" )$"
Expand Down Expand Up @@ -1131,17 +1139,19 @@ 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.
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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 62da43f

Please sign in to comment.