Bug#733489: python-apt: Improve 'Dependency' and 'BaseDependency' to get target package versions that satisfy dependencies
On Sat, Jan 25, 2014 at 04:10:54PM +0100, michael wrote:
> Those tests clearly look better! ^^
> When it comes to https://github.com/michael-schaller/python-apt/commit/ef6202e2f54dc2085e4d87a01aa2a66ff7c1a437 I would be already happy if you would include the updated docstring. The rest is really just readability. ;-)
>
OK, I merged the remaining stuff in that commit.
>
>
> What do you think of the second commit?
> https://github.com/michael-schaller/python-apt/commit/928814bbc43ed50ab956271a514baee49c7a452b
I think I prefer something that uses properties if we only
pass an apt_pkg.Dependency, like the following one; on the
grounds that this is more common in apt.*.
-- >8 --
>From 6233a7ce270971665e88bf38c28a09f2e75e5545 Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <jak@debian.org>
Date: Sat, 25 Jan 2014 17:02:10 +0100
Subject: [PATCH] apt/package.py: Pass an apt_pkg.Dependency to BaseDependency
Instead of passing the properties to __init__(), let's just pass
the apt_pkg.Dependency. Store that in a _dep attribute, and provide
properties to provide the API. The other classes do it this way
as well.
Reported-by: Michael Schaller <michael@5challer.de>
---
apt/package.py | 60 ++++++++++++++++++++++++++------------
doc/source/library/apt.package.rst | 23 ++-------------
2 files changed, 43 insertions(+), 40 deletions(-)
diff --git a/apt/package.py b/apt/package.py
index d1a7274..2703216 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -61,15 +61,7 @@ class FetchError(Exception):
class BaseDependency(object):
- """A single dependency.
-
- Attributes defined here:
- name - The name of the dependency
- relation - The relation (<,<=,=,!=,>=,>,)
- version - The version depended on
- rawtype - The type of the dependendy (e.g. 'Recommends')
- pre_depend - Boolean value whether this is a pre-dependency.
- """
+ """A single dependency."""
class __dstr(str):
"""Compare helper for compatibility with old third-party code.
@@ -95,12 +87,45 @@ class BaseDependency(object):
def __ne__(self, other):
return not self.__eq__(other)
- def __init__(self, name, rel, ver, pre, rawtype=None):
- self.name = name
- self.relation = self.__dstr(rel)
- self.version = ver
- self.pre_depend = pre
- self.rawtype = rawtype
+ def __init__(self, dep):
+ self._dep = dep # apt_pkg.Dependency
+
+ @property
+ def name(self):
+ """The name of the target package."""
+ return self._dep.target_pkg.name
+
+ @property
+ def relation(self):
+ """The relation (<, <=, !=, =, >=, >, ).
+
+ Note that the empty string is a valid string as well, if no version
+ is specified.
+ """
+ return self.__dstr(self._dep.comp_type)
+
+ @property
+ def version(self):
+ """The target version or None.
+
+ It is None if and only if relation is the empty string."""
+ return self._dep.target_ver
+
+ @property
+ def rawtype(self):
+ """Type of the dependency.
+
+ This should be one of 'Breaks', 'Conflicts', 'Depends', 'Enhances',
+ 'PreDepends', 'Recommends', 'Replaces', 'Suggests'.
+
+ Additional types might be added in the future.
+ """
+ return self._dep.dep_type_untranslated
+
+ @property
+ def pre_depend(self):
+ """Whether this is a PreDepends."""
+ return self._dep.dep_type_untranslated == 'PreDepends'
def __repr__(self):
return ('<BaseDependency: name:%r relation:%r version:%r preDepend:%r>'
@@ -433,10 +458,7 @@ class Version(object):
for dep_ver_list in depends[type_]:
base_deps = []
for dep_or in dep_ver_list:
- base_deps.append(BaseDependency(dep_or.target_pkg.name,
- dep_or.comp_type, dep_or.target_ver,
- (type_ == "PreDepends"),
- rawtype=type_))
+ base_deps.append(BaseDependency(dep_or))
depends_list.append(Dependency(base_deps))
except KeyError:
pass
diff --git a/doc/source/library/apt.package.rst b/doc/source/library/apt.package.rst
index 825bf3d..1a69c1e 100644
--- a/doc/source/library/apt.package.rst
+++ b/doc/source/library/apt.package.rst
@@ -23,27 +23,8 @@ The Version class
Dependency Information
----------------------
-.. class:: BaseDependency
-
- The :class:`BaseDependency` class defines various attributes for accessing
- the parts of a dependency. The attributes are as follows:
-
- .. attribute:: name
-
- The name of the dependency
-
- .. attribute:: relation
-
- The relation (<,<=,=,!=,>=,>,), as string. Note that the empty string
- is a valid string as well, if no version is specified.
-
- .. attribute:: version
-
- The version or None.
-
- .. attribute:: pre_depend
-
- Boolean value whether this is a pre-dependency.
+.. autoclass:: BaseDependency
+ :members:
.. class:: Dependency
--
1.8.5.2
--
Julian Andres Klode - Debian Developer, Ubuntu Member
See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.
Please do not top-post if possible.
Reply to: