Package: python3-apt
Version: 3.1.0
Severity: wishlist
The python binding to libapt-pkg does not offer any way to do the rough
equivalent of apt-get's "upgrade --with-new-pkgs".
The Cache.upgade method allows doing a "full/dist upgrade" or a
"partial/safe upgrade":
Cache.upgrade(self, dist_upgrade: bool = False) -> None
That forwards the call to apt_pkg.DepCache.upgrade which is implemented
by PkgDepCacheUpgrade:
static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args)
{
[...]
char distUpgrade=0;
if (PyArg_ParseTuple(Args,"|b",&distUpgrade) == 0)
return 0;
[...]
if (distUpgrade)
res = APT::Upgrade::Upgrade(*depcache, 0);
else
res = APT::Upgrade::Upgrade(*depcache,
APT::Upgrade::FORBID_REMOVE_PACKAGES |
APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES);
[...]
}
What's missing is allowing python to call Upgrade with
FORBID_REMOVE_PACKAGES but without FORBID_INSTALL_NEW_PACKAGES
(pseudocode):
int mode_flags = (upgrade_mode == FULL)
? 0
: (upgrade_mode == WITH_NEW_PKGS)
? APT::Upgrade::FORBID_REMOVE_PACKAGES
: APT::Upgrade::FORBID_REMOVE_PACKAGES |
APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES;
res = APT::Upgrade::Upgrade(*depcache, mode_flags);
Plus the API adjustments to expose this feature.
-- System Information:
Debian Release: forky/sid
APT prefers stable-security
APT policy: (500, 'stable-security'), (500, 'unstable'), (500, 'testing'),
(500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 6.12.101+deb13-amd64 (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8),
LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages python3-apt depends on:
ii distro-info-data 2026.07.30-1
ii libapt-pkg7.0 3.3.3
ii libc6 2.43-3
ii libgcc-s1 16.2.0-1
ii libstdc++6 16.2.0-1
ii python-apt-common 3.1.0
ii python3 3.14.6-1
Versions of packages python3-apt recommends:
ii iso-codes 4.20.1-1
ii lsb-release 12.1-2
Versions of packages python3-apt suggests:
ii apt 3.3.3
pn python-apt-doc <none>
-- no debconf information