Bug#733489: python-apt: Improve 'Dependency' and 'BaseDependency' to get target package versions that satisfy dependencies
Awesome! My first patch in Debian. ^^
Thanks for all your patience so far...
Next thing on the agenda is the relation handling in BaseDependency. I'm
wondering if I'm the only one trying to use this but the relation
handling seems to be totally broken at the moment. There is a huge
difference between the Debian manual (what I should get) and the actual
results from python-apt...
According to the Debian Manual [1] the only allowed relations are "<<,
<=, =, >= and >>". Back in the days there have been "<" which maps to
"<=" and ">" which maps to ">=". "<" and ">" have been deprecated
because they "were confusingly used".
python-apt on the other side behaves totally different:
-------------------
#!/usr/bin/python
import apt
cache = apt.cache.Cache()
relations = set()
for pkg in cache: # apt.package.Package
ver = pkg.candidate # apt.package.Version
or_deps = ver.get_dependencies("PreDepends", "Depends", "Recommends")
for or_dep in or_deps: # apt.package.Dependency
for dep in or_dep: # apt.package.BaseDependency
relations.add(dep.relation)
print relations
-------------------
Output: set(['', '>=', '<=', '=', '<', '>'])
Looking a bit deeper this behaviour is already present in apt_pkg:
-------------------
#!/usr/bin/python
import apt
cache = apt.cache.Cache()
relations = set()
for pkg in cache: # apt.package.Package
ver = pkg.candidate # apt.package.Version
_ver = ver._cand # apt_pkg.Version
dep_dict = _ver.depends_list
pre_deps = dep_dict.get('PreDepends', [])
deps = dep_dict.get('Depends', [])
recs = dep_dict.get('Recommends', [])
for or_dep in pre_deps:
for dep in or_dep: # apt_pkg.Dependency
relations.add(dep.comp_type)
for or_dep in deps:
for dep in or_dep: # apt_pkg.Dependency
relations.add(dep.comp_type)
for or_dep in recs:
for dep in or_dep: # apt_pkg.Dependency
relations.add(dep.comp_type)
print relations
-------------------
Output: set(['', '>=', '<=', '=', '<', '>'])
The documentation of apt_pkg.Dependency.comp_type reads like this:
.. attribute:: comp_type
The type of comparison (>=, ==, >>, <=), as string.
dpkg seems to be only adhering to what is written in the Debian Manual:
$ egrep -o '\(< |\(<< |\(<= |\(> |\(>> |\(>= |\(= |\(== '
/var/lib/dpkg/status | tr -d '(' | sort | uniq
<<
<=
=
>=
>>
I hope you are confused too, so can we fix this in python-apt?
I know that this would break compatibility but the current
implementation is plain wrong IMHO. Also the question would be where
this needs fixing... (libapt-pkg, apt_pkg.Dependency or
apt.Package.BaseDependency)
[1] http://www.debian.org/doc/debian-policy/ch-relationships.html
Reply to: