meta_package_manager.managers.apt module¶

class meta_package_manager.managers.apt.APT[source]¶

Bases: PackageManager

Base class for Debian’s apt front-end and its variants.

Command equivalences with other managers are listed in Pacman/Rosetta.

mpm drives the high-level apt binary, not apt-get or apt-cache, over system-wide packages. Mutations escalate through sudo and force --yes to stay non-interactive. APT_Mint retargets Linux Mint’s same-named but differently-behaved apt.

Initialize cli_errors list.

name: str = 'Debian apt'¶

Return package manager’s common name.

Default value is based on class name.

homepage_url: str | None = 'https://wiki.debian.org/AptCLI'¶

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.

documentation_url: str | None = 'https://manpages.debian.org/unstable/apt/apt.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/apt'¶

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/APT_(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.

keywords: tuple[str, ...] = ('debian', 'dpkg', 'ubuntu')¶

Well-known names for this manager that its id does not already carry.

Merged into the PyPI keywords of pyproject.toml by update_keywords() of docs/docs_update.py, alongside every manager ID and the globally curated KEYWORDS_EXTRAS. Declare an alias here rather than in that tuple whenever it names this manager: an alias living beside the class it describes cannot outlive it, where a central entry silently rots once the manager is renamed or dropped.

Reserve KEYWORDS_EXTRAS for terms belonging to no manager in particular, like cyclonedx or package manager. Documentation-only: no CLI output reads it.

Each keyword also becomes a content rule of the issue labeller, so its precision bar applies here: see generate_content_rules(). A subclass inherits the terms of its parent without claiming them, since test_manager_keywords_have_one_owner reads what a class declares itself.

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¶

Built-in escalation default, used when sudo is None.

False on the base: most managers install into user-writable trees and never need root. The system package managers whose privileged operations require root (apt, dnf, pacman, zypper, …) set this to True so their build_cli(..., sudo=True) operations escalate out of the box, while staying switchable off through sudo (--no-sudo or config) for rootless setups.

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 = '>=1.0.0'¶

Version requirement specifier.

Supports a comma-separated range of constraints (e.g. ">=1.20.0,<2.0.0"). A bare version string like "1.20.0" is treated as >=1.20.0.

Parsed by meta_package_manager.version.VersionRange.

Defaults to None, which deactivates version check entirely.

pre_args: tuple[str, ...] = ('--quiet',)¶
version_regexes: tuple[str, ...] = ('apt\\s+(?P<version>\\S+)',)¶
$ apt --version
apt 2.0.6 (amd64)
property installed: Iterator[Package]¶

Fetch installed packages.

$ apt --quiet list --installed
Listing...
adduser/xenial,now 3.113+nmu3ubuntu4 all [installed]
bc/xenial,now 1.06.95-9build1 amd64 [installed]
bsdmainutils/xenial,now 9.0.6ubuntu3 amd64 [installed,automatic]
ca-certificates/xenial,now 20160104ubuntu1 all [installed]
cron/xenial,now 3.0pl1-128ubuntu2 amd64 [installed]
debconf/xenial,now 1.5.58ubuntu1 all [installed]
debianutils/xenial,now 4.7 amd64 [installed]
diffutils/xenial,now 1:3.3-3 amd64 [installed]
e2fsprogs/xenial,now 1.42.13-1ubuntu1 amd64 [installed]
ethstatus/xenial,now 0.4.3ubuntu2 amd64 [installed]
file/xenial,now 1:5.25-2ubuntu1 amd64 [installed]
findutils/xenial,now 4.6.0+git+20160126-2 amd64 [installed]
libidn2-0/jammy,now 2.3.2-2build1 amd64 [installed,automatic]
libidn2-0/jammy,now 2.3.2-2build1 i386 [installed,automatic]
property outdated: Iterator[Package]¶

Fetch outdated packages.

$ apt --quiet list --upgradable
Listing...
apt/xenial-updates 1.2.19 amd64 [upgradable from: 1.2.15ubuntu0.2]
nano/xenial-updates 2.5.3-2ubuntu2 amd64 [upgradable from: 2.5.3-2]
property orphans: Iterator[Package]¶

Fetch packages installed as dependencies that nothing requires anymore.

--simulate turns autoremove into a read-only report of the would-be-removed packages, printed as Remv <name> [<version>] lines. It needs no root: apt only prints a notice that the run is a simulation.

$ apt --quiet autoremove --simulate
NOTE: This is only a simulation!
      apt needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  libx11-dev libxcb1-dev
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
Remv libx11-dev [2:1.8.7-1]
Remv libxcb1-dev [1.15-1]
search(query, extended, exact)[source]¶

Fetch matching packages.

$ apt --quiet search abc --names-only
Sorting...
Full Text Search...
abcde/xenial 2.7.1-1 all
  A Better CD Encoder

abcmidi/xenial 20160103-1 amd64
  converter from ABC to MIDI format and back

berkeley-abc/xenial 1.01+20150706hgc3698e0+dfsg-2 amd64
  ABC - A System for Sequential Synthesis and Verification

fuse-overlayfs/jammy,now 1.7.1-1 amd64 [installed]
  implementation of overlay+shiftfs in FUSE for rootless containers

grabcd-rip/xenial 0009-1 all
  rip and encode audio CDs - ripper

libakonadi-kabc4/xenial 4:4.14.10-1ubuntu2 amd64
  Akonadi address book access library
$ apt --quiet search ^sed$ --names-only
Sorting...
Full Text Search...
sed/xenial 2.1.9-3 all
  Blah blah blah
$ apt --quiet search abc --full
Sorting...
Full Text Search...
abcde/xenial 2.7.1-1 all
  This package contains the essential basic system utilities.
  .
  Specifically, this package includes:
  basename cat chgrp chmod chown chroot cksum comm cp csplit cut
  dircolors dirname du echo env expand expr factor false fmt
  hostid id install join link ln logname ls md5sum mkdir mkfifo
  nohup od paste pathchk pinky pr printenv printf ptx pwd
  sha1sum seq shred sleep sort split stat stty sum sync tac tail
  tr true tsort tty uname unexpand uniq unlink users vdir wc who

(...)

midi/xenial 20160103-1 amd64
  converter from ABC to MIDI format and back
Return type:

Iterator[Package]

install(package_id, version=None)[source]¶

Install one package.

$ sudo apt --quiet --yes install git
Return type:

str

mark_explicit(package_id)[source]¶

Mark an installed package as manually installed.

apt install already does this for a package at its candidate version. When the install upgrades a package that another one still requires, a reading of depcache.cc shows that apt keeps it automatic. The command goes through the apt-mark sibling, as apt has no such verb.

$ sudo apt-mark --quiet manual git
Return type:

str

upgrade_all_cli()[source]¶

Generates the CLI to upgrade all outdated packages.

$ sudo apt --quiet --yes upgrade
Return type:

tuple[str, ...]

upgrade_one_cli(package_id, version=None)[source]¶

Generates the CLI to upgrade the provided package.

$ sudo apt --quiet --yes install --only-upgrade git
Return type:

tuple[str, ...]

remove(package_id)[source]¶

Remove one package.

$ sudo apt --quiet --yes remove git
Return type:

str

remove_orphan(package_id)[source]¶

Remove one package, then drop dependencies it alone pulled in.

--auto-remove clears the packages that were installed as dependencies and are no longer needed after the removal.

$ sudo apt --quiet --yes remove --auto-remove git
Return type:

str

sync()[source]¶

Sync package metadata.

$ sudo apt --quiet --yes update
Hit:1 http://archive.ubuntu.com xenial InRelease
Get:2 http://archive.ubuntu.com xenial-updates InRelease [102 kB]
Get:3 http://archive.ubuntu.com xenial-security InRelease [102 kB]
Get:4 http://archive.ubuntu.com xenial/main Translation-en [568 kB]
Fetched 6,868 kB in 2s (2,680 kB/s)
Reading package lists...
Building dependency tree...
Reading state information...
Return type:

None

cleanup_orphan()[source]¶

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

$ sudo apt --quiet --yes autoremove
Return type:

None

cleanup_cache()[source]¶

Clear out the local repository of retrieved package files.

$ sudo apt --quiet --yes clean
Return type:

None

doctor_cli()[source]¶

Generates the CLI running the native self-diagnosis.

apt itself has no stable check verb, so the diagnosis goes through the apt-get sibling: check verifies the package cache and dependency integrity, prints the broken state and exits non-zero on problems. Runs unprivileged.

$ apt-get --quiet check
Return type:

tuple[str, ...]

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

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).

id: str = 'apt'¶

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.

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.

class meta_package_manager.managers.apt.APT_Mint[source]¶

Bases: APT

Linux Mint’s apt, a wrapper script that shadows Debian’s apt.

Mint ships its own apt command reusing the name but not the behavior of APT, so only version probing and search parsing are overridden here; every other operation is inherited.

Note

Mint’s apt --version prints no apt <version> line, so the version is read from apt version apt: the version of the apt package itself.

Caution

Search rows are <status> <name> - <description> with no version column and no --full mode, so extended matching is unsupported and results carry no version.

Initialize cli_errors list.

name: str = 'Linux Mint apt'¶

Return package manager’s common name.

Default value is based on class name.

homepage_url: str | None = 'https://github.com/kdeldycke/meta-package-manager/issues/52'¶

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.

documentation_url: str | None = 'https://manpages.debian.org/unstable/apt/apt.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.

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.

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

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).

id: str = 'apt-mint'¶

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.

repository_url: str | None = None¶

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.

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.

wikipedia_url: str | None = None¶

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.

version_cli_options: tuple[str, ...] = ('version', 'apt')¶
$ apt version apt
1.6.11
search(query, extended, exact)[source]¶

Fetch matching packages.

Caution

Search does not supports extended matching.

$ /usr/local/bin/apt --quiet search sed
v   librust-slog-2.5+erased-serde-dev  -
p   python3-blessed                    - Practical wrapper
i   sed                                - GNU stream editor
p   sed:i386                           - GNU stream editor
$ /usr/local/bin/apt --quiet search ^sed$
i   sed              - GNU stream editor
p   sed:i386         - GNU stream editor
Return type:

Iterator[Package]