Commit 63492dfc authored by Julian Andres Klode's avatar Julian Andres Klode

Accept Version objects in apt_pkg.Policy.get_priority(), deprecate Package

Per-package pins are a remnant of the old policy implementation,
the new one uses per-version pins.
parent c11bdab4
......@@ -1151,9 +1151,15 @@ Package Pinning with :class:`Policy`
Get a version for the package.
.. method:: get_priority(package: apt_pkg.Package) -> int
.. method:: get_priority(package: Union[apt_pkg.Package, apt_pkg.Version, apt_pkg.PackageFile]) -> int
Get the pin priority of the package given by *package*.
Get the pin priority of the package, version, or package file
given by *package*.
.. versionchanged:: 1.7
Introduce support for per-version pins. Deprecated support
for :class:`apt_pkg.Package`.
.. method:: read_pindir(dirname: str) -> bool
......
......@@ -8,6 +8,10 @@ Changed
is :class:`apt_pkg.CacheMismatchError`, and :class:`apt.cache.Cache` will
automatically remap open packages and versions to a new cache.
* :meth:`apt_pkg.Policy.get_priority()` now accepts :class:`apt_pkg.Version`
objects in addition to :class:`apt_pkg.Package` and :class:`apt_pkg.PackageFile`
ones.
Added
------
* The class :class:`apt_pkg.PackageRecords` can now lookup custom fields
......@@ -19,3 +23,9 @@ Added
necessary.
* A new method :meth:`apt.cache.Cache.fix_broken` has been added.
Deprecated
----------
* :meth:`apt_pkg.Policy.get_priority()` accepting :class:`apt_pkg.Package`
is deprecated.
......@@ -38,14 +38,19 @@ static PyObject *policy_new(PyTypeObject *type,PyObject *Args,
}
static char *policy_get_priority_doc =
"get_priority(package: apt_pkg.Package) -> int\n\n"
"get_priority(package: Union[apt_pkg.Package, apt_pkg.Version, apt_pkg.PackageFile]) -> int\n\n"
"Return the priority of the package.";
PyObject *policy_get_priority(PyObject *self, PyObject *arg) {
pkgPolicy *policy = GetCpp<pkgPolicy *>(self);
if (PyObject_TypeCheck(arg, &PyPackage_Type)) {
if (PyErr_WarnEx(PyExc_DeprecationWarning, "Passing apt_pkg.Package to Policy.get_priority() is deprecated, pass a version instead.", 1) == -1)
return NULL;
pkgCache::PkgIterator pkg = GetCpp<pkgCache::PkgIterator>(arg);
return MkPyNumber(policy->GetPriority(pkg));
} else if (PyObject_TypeCheck(arg, &PyVersion_Type)) {
auto ver = GetCpp<pkgCache::VerIterator>(arg);
return MkPyNumber(policy->GetPriority(ver));
} else if (PyObject_TypeCheck(arg, &PyPackageFile_Type)) {
pkgCache::PkgFileIterator pkgfile = GetCpp<pkgCache::PkgFileIterator>(arg);
return MkPyNumber(policy->GetPriority(pkgfile));
......
......@@ -290,7 +290,7 @@ class DepCache():
def fix_broken(self) -> bool: ...
class Policy():
def get_priority(self, pkg: Union[Package, PackageFile]) -> int: ...
def get_priority(self, pkg: Union[Package, PackageFile, Version]) -> int: ...
class SystemLock():
def __enter__(self) -> None: ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment