meta_package_manager.managers.aptitude module

meta_package_manager.managers.aptitude.NO_VERSION = '<none>'

Placeholder %v and %V render for a version that does not exist.

An uninstalled package has no current version, and a virtual one has no candidate. Both print this literal rather than an empty field, so it has to be mapped back to None instead of reaching a package record as a version string.

meta_package_manager.managers.aptitude.escape_pattern(query)[source]

Render query as a regex matching itself and nothing else.

Two layers read the string, and each needs a different treatment:

  • aptitude’s pattern parser splits a term at whitespace, so a two-word query becomes an implicit AND of two terms and matches nothing. A backslash cannot rescue it (the split happens first, leaving a trailing backslash the regex compiler rejects), so whitespace is rewritten as the [[:space:]] class, which carries no space to split on.

  • the regex compiler underneath, whose metacharacters are backslashed.

Quoting the term instead (~n"...") also survives whitespace, but the quote parser eats backslashes before the regex ever sees them, so the two mechanisms cannot be combined: ~n"^s\.d$" still matches sed.

Return type:

str

class meta_package_manager.managers.aptitude.Aptitude[source]

Bases: PackageManager

Front-end to Debian’s apt, with a resolver and a query language of its own.

Aptitude reaches the same archives apt does, over the same dpkg backend, and is wrapped on the same grounds as Nala: a distinct tool with a vocabulary of its own, rather than a translation layer over another CLI. It shares dpkg’s lock with the rest of that family, so mpm runs it serially against them.

Initialize cli_errors list.

name: str = 'aptitude'

Return package manager’s common name.

Default value is based on class name.

documentation_url: str | None = 'https://manpages.debian.org/unstable/aptitude/aptitude.8.en.html'

Entry point of the project’s own documentation, or None when it has none.

The manual, the documentation site, or the man page of the CLI mpm drives: whichever page a user reads to learn the commands this manager wraps. Listed between homepage_url and repository_url in the links of the manager’s page, so a reader reaching for the tool’s reference finds it in the box of facts rather than in the prose below it.

Left unset where a link would state a fact twice or invent one: a tool documenting itself in its repository alone, whose README repository_url already reaches. A page about the ecosystem rather than the tool does not qualify either.

Where a project’s only site is its manual, that address belongs here and homepage_url stays unset: the slot names what the page is, and a reader reaching for the reference looks under the documentation link.

Never inherited, like every other link: the AUR helpers extending pacman each document themselves.

repository_url: str | None = 'https://salsa.debian.org/apt-team/aptitude'

Repository holding the project’s code, or None when it has no public one.

Linked from the manager’s documentation page. Also what the weekly metrics sample reads: docs/docs_update.py writes it into the [tool.repomatic.metrics] subjects of pyproject.toml when its forge answers the sampler, through a mirror for a forge that does not.

Never inherited, for the same reason as wikipedia_url: the AUR helpers extending pacman each live in a repository of their own.

wikipedia_url: str | None = 'https://en.wikipedia.org/wiki/Aptitude_(software)'

English Wikipedia article about the project, or None when it has none.

Listed last in the links of the manager’s documentation page. The article covers the project that home page names, or is a redirect Wikipedia keeps under the project’s name, landing on the part of a broader article that describes it: Cargo_(software) opens the Cargo section of the Rust article. An article that merely mentions the project does not count, nor does one about a related subject: lazy is a Neovim plugin manager, and the Neovim article is not about it.

Never inherited: the metaclass resets it to None on any class not declaring its own. A subclass often wraps a distinct project, like the six AUR helpers extending pacman, and would otherwise present pacman’s article as its own. Documentation-only, like homepage_url.

Slug of the brand mark standing for this manager in the documentation.

Names an SVG vendored under docs/assets/managers/, whose provenance and license are recorded in docs/assets/managers/logos.yaml. Inlined at the top of the manager’s page by meta_package_manager._docs; a manager leaving it unset keeps the page’s default package glyph.

Several managers legitimately share one slug, either because they wrap the same upstream (brew and cask) or because the tool has no mark of its own and its ecosystem’s stands in (apt under Debian’s swirl, cargo under Rust’s gear). Documentation-only, like homepage_url: no CLI output reads it.

platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='aix', name='IBM AIX'), Platform(id='almalinux', name='AlmaLinux'), Platform(id='alpine', name='Alpine Linux'), Platform(id='altlinux', name='ALT Linux'), Platform(id='amzn', name='Amazon Linux'), Platform(id='android', name='Android'), Platform(id='arch', name='Arch Linux'), Platform(id='buildroot', name='Buildroot'), Platform(id='cachyos', name='CachyOS'), Platform(id='centos', name='CentOS'), Platform(id='chromeos', name='ChromeOS'), Platform(id='clearlinux', name='Clear Linux OS'), Platform(id='cloudlinux', name='CloudLinux OS'), Platform(id='crux', name='CRUX'), Platform(id='cygwin', name='Cygwin'), Platform(id='debian', name='Debian'), Platform(id='dragonfly_bsd', name='DragonFly BSD'), Platform(id='endeavouros', name='EndeavourOS'), Platform(id='exherbo', name='Exherbo Linux'), Platform(id='fedora', name='Fedora'), Platform(id='freebsd', name='FreeBSD'), Platform(id='generic_linux', name='Generic Linux'), Platform(id='gentoo', name='Gentoo Linux'), Platform(id='guix', name='Guix System'), Platform(id='haiku', name='Haiku'), Platform(id='hurd', name='GNU/Hurd'), Platform(id='ibm_powerkvm', name='IBM PowerKVM'), Platform(id='illumos', name='illumos'), Platform(id='kali', name='Kali Linux'), Platform(id='kvmibm', name='KVM for IBM z Systems'), Platform(id='linuxmint', name='Linux Mint'), Platform(id='mageia', name='Mageia'), Platform(id='mandriva', name='Mandriva Linux'), Platform(id='manjaro', name='Manjaro Linux'), Platform(id='midnightbsd', name='MidnightBSD'), Platform(id='netbsd', name='NetBSD'), Platform(id='nixos', name='NixOS'), Platform(id='nobara', name='Nobara'), Platform(id='nutyx', name='NuTyX'), Platform(id='openbsd', name='OpenBSD'), Platform(id='opensuse', name='openSUSE'), Platform(id='openwrt', name='OpenWrt'), Platform(id='oracle', name='Oracle Linux'), Platform(id='os400', name='IBM i'), Platform(id='parallels', name='Parallels'), Platform(id='pidora', name='Pidora'), Platform(id='pikaos', name='PikaOS'), Platform(id='raspbian', name='Raspbian'), Platform(id='rhel', name='RedHat Enterprise Linux'), Platform(id='rocky', name='Rocky Linux'), Platform(id='scientific', name='Scientific Linux'), Platform(id='slackware', name='Slackware'), Platform(id='sles', name='SUSE Linux Enterprise Server'), Platform(id='slitaz', name='SliTaz GNU/Linux'), Platform(id='solaris', name='Solaris'), Platform(id='solus', name='Solus'), Platform(id='sourcemage', name='Source Mage GNU/Linux'), Platform(id='sunos', name='SunOS'), Platform(id='tuxedo', name='Tuxedo OS'), Platform(id='ubuntu', name='Ubuntu'), Platform(id='ultramarine', name='Ultramarine'), Platform(id='void', name='Void Linux'), Platform(id='wsl1', name='Windows Subsystem for Linux v1'), Platform(id='wsl2', name='Windows Subsystem for Linux v2'), Platform(id='xenserver', name='XenServer')})

List of platforms supported by the manager.

Allows for a mishmash of platforms and groups of platforms. Will be normalized into a frozenset of Platform instances at instantiation.

default_sudo: bool = True

Aptitude reports are you root? and exits rather than escalating on its own, so mpm supplies the privilege for the operations that mutate.

privileged_operations: ClassVar[frozenset[str]] = frozenset({'cleanup', 'install', 'remove', 'sync', 'upgrade', 'upgrade_all'})

Operations with at least one command this manager marks privileged.

Keyed by the Operations member name, like operation_notes. An operation belongs here when a method implementing it passes sudo=True to run_cli() or build_cli(), with the method-to-operation map of METHOD_OPERATIONS. Those commands are the only ones the escalation policy (sudo, else default_sudo) wraps in the escalator. A definition derives the set from the operations it marks sudo = true.

prime_sudo() reads it to prompt only for the managers that escalate a command of the current run. With [mpm.overrides.gem] sudo = true, mpm sync asks for no password: the gem sources --update command of sync carries no marker. test_privileged_operations holds the set to the markers in the method bodies.

requirement: str | None = '>=0.4.11.4'

The release adding --disable-columns, announced in aptitude’s own NEWS as a new search option. Every other option and pattern this class passes predates it, and every currently shipped distribution is far above it.

pre_args: tuple[str, ...] = ('--quiet', '--disable-columns')

--quiet drops the incremental progress indicators aptitude draws on a terminal; --disable-columns asks for unpadded, untruncated output.

Source: aptitude(8) options.

version_regexes: tuple[str, ...] = ('aptitude\\s+(?P<version>\\S+)',)
$ aptitude --version
aptitude 0.8.13
Compiler: g++ 14.2.0
Compiled against:
  apt version 7.0.0
  NCurses version 6.5
  libsigc++ version: 2.12.1
  Gtk+ support disabled.
  Qt support disabled.

Current library versions:
  NCurses version: ncurses 6.5.20250216
  cwidget version: 0.5.18
  Apt version: 7.0.0
property installed: Iterator[Package]

Fetch installed packages.

$ aptitude --quiet --disable-columns search ~i --display-format %p,%v
adduser,3.152
apparmor,4.1.0-1
apt,3.0.3
apt-utils,3.0.3
aptitude,0.8.13-7
aptitude-common,0.8.13-7
base-files,13.8+deb13u6
base-passwd,3.6.7
bash,5.2.37-2+b9
bash-completion,1:2.16.0-7
bsdutils,1:2.41-5
busybox,1:1.37.0-6+b8
bzip2,1.0.8-6
ca-certificates,20250419
property outdated: Iterator[Package]

Fetch outdated packages.

~U matches an installed package having a newer candidate, so %v and %V are both populated and always differ.

$ aptitude --quiet --disable-columns search ~U --display-format %p,%v,%V
bsdutils,1:2.41-5,1:2.41.5-0+deb13u1
eject,2.41-5,2.41.5-0+deb13u1
fdisk,2.41-5,2.41.5-0+deb13u1
libblkid1,2.41-5,2.41.5-0+deb13u1
libexpat1,2.7.1-2,2.8.3-1~deb13u1
libfdisk1,2.41-5,2.41.5-0+deb13u1
liblastlog2-2,2.41-5,2.41.5-0+deb13u1
libmount1,2.41-5,2.41.5-0+deb13u1
libpython3.13-minimal,3.13.5-2+deb13u3,3.13.5-2+deb13u4
libpython3.13-stdlib,3.13.5-2+deb13u3,3.13.5-2+deb13u4
property orphans: Iterator[Package]

Fetch packages installed as dependencies that nothing requires anymore.

~g matches aptitude’s garbage set, which also covers packages that are not installed at all, so it is intersected with ~i. The result is the set apt autoremove would remove.

$ aptitude --quiet --disable-columns search ~i~g --display-format %p,%v
nyancat,1.5.2-0.3+b1
search(query, extended, exact)[source]

Fetch matching packages.

~n matches the name and ~d the description, so an extended search is the union of the two and a plain one is the name term alone. An exact query anchors that term at both ends.

A package with no candidate version renders %V as <none>: virtual packages match a name search and carry neither a version nor a description.

$ aptitude --quiet --disable-columns search ~nabc --display-format %p,%V,%d
abcde,2.9.3-1,A Better CD Encoder
abcl,1.9.2-2,Common Lisp implementation in the Java Virtual Machine
abcm2ps,8.14.17-2,Translates ABC music description files to PostScript
abcmidi,20250216+ds-1,converter from ABC to MIDI format and back
grabc,1.1+git20210125.b9e4316-2+b1,simple program to determine the color string in hex by clicking on a pixel
libghc-directory-tree-dev-0.12.1-9dabc,<none>,
libghc-directory-tree-prof-0.12.1-9dabc,<none>,
node-lodash.kebabcase,<none>,
node-types-lodash.kebabcase,<none>,
python3-sabctools,8.2.3-2+b4,C implementations of functions for use within SABnzbd
$ aptitude --quiet --disable-columns search ~n^sed$ --display-format %p,%V,%d
sed,4.9-2+deb13u1,GNU stream editor for filtering/transforming text
$ aptitude --quiet --disable-columns search ~nnyancat|~dnyancat --display-format %p,%V,%d
nyancat,1.5.2-0.3+b1,Animated terminal Nyancat
nyancat-server,1.5.2-0.3,Animated terminal Nyancat server configurations
$ aptitude --quiet --disable-columns search ~n^libsigc\+\+-2\.0-0v5$ --display-format %p,%V,%d
libsigc++-2.0-0v5,2.12.1-3,type-safe Signal Framework for C++ - runtime
Return type:

Iterator[Package]

install(package_id, version=None)[source]

Install one package.

$ sudo aptitude --quiet --disable-columns --assume-yes install nyancat
$ sudo aptitude --quiet --disable-columns --assume-yes install nyancat=1.5.2-0.3+b1
Return type:

str

cli_names: tuple[str, ...] = ('aptitude',)

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

homepage_url: str | None = None

Home page of the project, only used in documentation for reference.

Left unset when the home page is the project’s repository, which repository_url names on its own, and when it is the project’s manual, which documentation_url names. Never inherited, like the other links.

id: str = 'aptitude'

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

mark_explicit(package_id)[source]

Mark an installed package as manually installed.

aptitude install restores the automatic flag a package had before, so an automatically installed package stays automatic: aptcache.cc.

$ sudo aptitude --quiet --disable-columns unmarkauto nyancat
Return type:

str

virtual: bool = False

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

upgrade_all_cli()[source]

Generates the CLI to upgrade all outdated packages.

safe-upgrade never removes an installed package to resolve an upgrade, which is the conservatism apt upgrade has and full-upgrade drops.

$ sudo aptitude --quiet --disable-columns --assume-yes safe-upgrade
Return type:

tuple[str, ...]

upgrade_one_cli(package_id, version=None)[source]

Generates the CLI to upgrade the provided package.

Routed through install, which moves an already-installed package to the requested version, since naming a package on safe-upgrade still drags in every other member of its dependency cluster.

$ sudo aptitude --quiet --disable-columns --assume-yes install eject
Return type:

tuple[str, ...]

remove(package_id)[source]

Remove one package.

$ sudo aptitude --quiet --disable-columns --assume-yes remove nyancat
Return type:

str

sync()[source]

Sync package metadata.

$ sudo aptitude --quiet --disable-columns update
Return type:

None

cleanup_orphan()[source]

Remove every package installed as a dependency and no longer required.

Aptitude has no autoremove verb: the garbage set is named as a pattern on remove, the same one orphans() reports.

$ sudo aptitude --quiet --disable-columns --assume-yes remove ~i~g
Return type:

None

cleanup_cache()[source]

Erase the downloaded package files.

$ sudo aptitude --quiet --disable-columns --assume-yes clean
Return type:

None