From 10cf352707550209e874c69331e49c70458f0130 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Mon, 10 Nov 2014 11:27:37 +0000 Subject: Add Bound objects --- exts/pip_find_deps.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/exts/pip_find_deps.py b/exts/pip_find_deps.py index 58fb2b0..2c5c364 100755 --- a/exts/pip_find_deps.py +++ b/exts/pip_find_deps.py @@ -70,6 +70,35 @@ def conflict(specs, spec): # ('<', '0.1') conflicts with ('>', '0.2') pass +class Bound(object): + def __init__(self, bound_type, value, inclusive=False): + self.value = value + self.inclusive = inclusive + self.bound_type = bound_type + + # TODO: quite sure there's a much nicer way to be doing this sort of thing + # probably by defining __lt__, __eq__, __gt__ ourselves + def __lt__(self, x): + return x <= self.value if self.inclusive else x < self.value + + def __gt__(self, x): + return x >= self.value if self.inclusive else x > self.value + + def _symbol(self): + return '' + + @property + def spec(self): + return (self._symbol(), self.value) + +class LowerBound(Bound): + def __init__(self, value, inclusive=False): + super(LowerBound, self).__init__('lower', value, inclusive) + +class UpperBound(Bound): + def __init__(self, value, inclusive=False): + super(UpperBound, self).__init__('upper', value, inclusive) + class Dependency(object): def __init__(self): # non-inclusive boundaries @@ -85,6 +114,7 @@ class Dependency(object): def is_unbounded(self): return self.less_than == None and self.greater_than == None + # TODO: This might be better done in Bound, not sure def _in_less_than(self, version): return True if self.less_than == None else version < self.less_than @@ -133,15 +163,20 @@ def check_eqs(dep, version): def check_lt(dep, version): if dep.is_unconstrained(): - dep.less_than = version + dep.less_than = LowerBound(version, inclusive=False) elif dep.is_unbounded(): if dep.absolute >= version: dep.conflicts.append((('==', dep.absolute), ('<', version))) elif dep.greater_than >= version: dep.conflicts.append((('>', dep.greater_than), ('<', version))) else: + dep.less_than = LowerBound(version, inclusive=False) + +def check_lt_eq(dep, version): + if dep.is_unconstrained(): dep.less_than = version + def check_gt(dep, version): if dep.is_unconstrained(): dep.greater_than = version -- cgit v1.2.1