summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-11-10 11:27:37 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-11-10 11:27:37 +0000
commit10cf352707550209e874c69331e49c70458f0130 (patch)
treee5139ef0c2304b535e23fa83fbec723519bcf803
parent1d43ec8fc6a63d6688c4a2f687a4bb19f87039c0 (diff)
downloadimport-10cf352707550209e874c69331e49c70458f0130.tar.gz
Add Bound objects
-rwxr-xr-xexts/pip_find_deps.py37
1 files changed, 36 insertions, 1 deletions
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