diff options
-rwxr-xr-x | exts/pip.find_deps | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/exts/pip.find_deps b/exts/pip.find_deps index d6bff0a..15465ed 100755 --- a/exts/pip.find_deps +++ b/exts/pip.find_deps @@ -72,20 +72,41 @@ def conflict(specs, spec): class Dependency(object): def __init__(self): - self.min = None - self.max = None + # non-inclusive boundaries + self.less_than = None + self.greater_than = None + self.absolute = None self.excludes = [] def is_unbounded(self): - return self.min == None and self.max == None + return self.less_than == None and self.greater_than == None + + def _in_less_than(self, version): + return True if self.less_than == None else version < self.less_than + + def _in_greater_than(self, version): + return True if self.greater_than == None else version > self.greater_than + + def in_bounds(self, version): + return self.is_unbounded() or (self._in_less_than(version) + and self._in_greater_than(version)) + + def get_bounds_conflict(self, version): + if not self._in_less_than(version): + return '< %f' % self.less_than + elif not self._in_greater_than(version): + return '> %f' % self.greater_than + else: + return None def is_unconstrained(self): - return self.is_unbounded() and self.excludes == [] + return (self.is_unbounded() and self.excludes == [] + and self.absolute == None) def set_absolute_version(self, version): - self.min = version - self.max = version + self.absolute = version + def find_build_deps(source, name, version=None): debug('source: %s' % source) @@ -127,34 +148,45 @@ def find_build_deps(source, name, version=None): if op == '==': if dep.is_unconstrained(): dep.set_absolute_version(version) - elif dep.is_unbounded() and version not in dep.excludes: - dep.set_absolute_version(version) - else: - error('conflict! == %f conflicts with %s%s' - % (version, - ('> %f' % dep.min) if dep.min else '', - ('< %f' % dep.max) if dep.max else '')) + elif version not in dep.excludes: + if dep.absolute in [version, None]: + if dep.in_bounds(version): + dep.set_absolute_version(version) + else: + error('conflict! == %f conflicts with %s' + % (version, + dep.get_bounds_conflict(version))) + else: + error('conflict! == %f conflicts with == %f' + % (version, dep.absolute)) + elif version > dep.less_than: + # conflict + error('conflict! == %f conflicts with < %f' + % (version, dep.less_than)) + elif version < dep.greater_than: # conflict + error('conflict! == %f conflicts with > %f' + % (version, dep.greater_than)) elif op == '!=': dep.excludes += version elif op == '<': if dep.is_unconstrained(): - dep.max = version - elif dep.min > version: + dep.less_than = version + elif dep.greater_than >= version: # conflict #(our minimum version is greater - # than this max version) + # than this greater_than version) error('conflict! > %f conflicts with < %f' - % (dep.min, version)) + % (dep.greater_than, version)) else: - dep.max = version + dep.less_than = version elif op == '>': if dep.is_unconstrained(): - dep.min = version - elif dep.max < version: + dep.greater_than = version + elif dep.less_than <= version: # conflict (our maximum version is less than this - # min version) + # less_than version) error('conflict! < %f conflicts with > %f' - % (dep.max, version)) + % (dep.less_than, version)) # Resolve versions #client = xmlrpclib.ServerProxy(PYPI_URL) @@ -171,5 +203,6 @@ if len(sys.argv) not in [3, 4]: # First, given a source return build dependencies in json from for name, dep in find_build_deps(*sys.argv[1:]).iteritems(): - print('%s min: %s max: %s excludes: %s' - % (name, str(dep.min), str(dep.max), dep.excludes))
\ No newline at end of file + print('%s less_than: %s greater_than: %s absolute: %s excludes: %s' + % (name, str(dep.less_than), str(dep.greater_than), + str(dep.absolute), dep.excludes))
\ No newline at end of file |