meta_package_manager packageΒΆ
Expose package-wide elements.
SubpackagesΒΆ
- meta_package_manager.managers package
- Submodules
- meta_package_manager.managers.apm module
- meta_package_manager.managers.apt module
- meta_package_manager.managers.cargo module
- meta_package_manager.managers.chocolatey module
- meta_package_manager.managers.composer module
Composer
Composer.name
Composer.homepage_url
Composer.platforms
Composer.requirement
Composer.pre_args
Composer.version_regex
Composer.installed
Composer.outdated
Composer.search()
Composer.install()
Composer.upgrade_all_cli()
Composer.upgrade_one_cli()
Composer.cleanup()
Composer.cli_names
Composer.id
Composer.virtual
Composer.cli_errors
- meta_package_manager.managers.dnf module
- meta_package_manager.managers.emerge module
- meta_package_manager.managers.eopkg module
EOPKG
EOPKG.name
EOPKG.homepage_url
EOPKG.platforms
EOPKG.requirement
EOPKG.pre_args
EOPKG.version_regex
EOPKG.installed
EOPKG.outdated
EOPKG.search()
EOPKG.install()
EOPKG.upgrade_all_cli()
EOPKG.upgrade_one_cli()
EOPKG.remove()
EOPKG.sync()
EOPKG.cleanup()
EOPKG.cli_names
EOPKG.id
EOPKG.virtual
EOPKG.cli_errors
- meta_package_manager.managers.flatpak module
- meta_package_manager.managers.fwupd module
- meta_package_manager.managers.gem module
- meta_package_manager.managers.homebrew module
Homebrew
Homebrew.platforms
Homebrew.requirement
Homebrew.virtual
Homebrew.extra_env
Homebrew.version_regex
Homebrew.installed
Homebrew.outdated
Homebrew.search()
Homebrew.install()
Homebrew.upgrade_all_cli()
Homebrew.upgrade_one_cli()
Homebrew.remove()
Homebrew.sync()
Homebrew.cleanup()
Homebrew.cli_names
Homebrew.id
Homebrew.name
Homebrew.cli_errors
Brew
Cask
- meta_package_manager.managers.mas module
- meta_package_manager.managers.npm module
- meta_package_manager.managers.opkg module
- meta_package_manager.managers.pacman module
Pacman
Pacman.homepage_url
Pacman.platforms
Pacman.requirement
Pacman.pre_args
Pacman.version_regex
Pacman.installed
Pacman.outdated
Pacman.search()
Pacman.install()
Pacman.upgrade_all_cli()
Pacman.upgrade_one_cli()
Pacman.remove()
Pacman.sync()
Pacman.cleanup()
Pacman.cli_names
Pacman.id
Pacman.name
Pacman.virtual
Pacman.cli_errors
Pacaur
Paru
Yay
- meta_package_manager.managers.pip module
- meta_package_manager.managers.pipx module
- meta_package_manager.managers.pkg module
- meta_package_manager.managers.scoop module
Scoop
Scoop.name
Scoop.homepage_url
Scoop.platforms
Scoop.requirement
Scoop.version_regex
Scoop.remove_headers()
Scoop.installed
Scoop.outdated
Scoop.search()
Scoop.install()
Scoop.upgrade_all_cli()
Scoop.upgrade_one_cli()
Scoop.remove()
Scoop.sync()
Scoop.cleanup()
Scoop.cli_names
Scoop.id
Scoop.virtual
Scoop.cli_errors
- meta_package_manager.managers.snap module
- meta_package_manager.managers.steamcmd module
- meta_package_manager.managers.uv module
- meta_package_manager.managers.vscode module
- meta_package_manager.managers.winget module
- meta_package_manager.managers.yarn module
- meta_package_manager.managers.zypper module
Zypper
Zypper.homepage_url
Zypper.platforms
Zypper.requirement
Zypper.pre_args
Zypper.version_regex
Zypper.SearchResult
Zypper.installed
Zypper.outdated
Zypper.search()
Zypper.install()
Zypper.upgrade_all_cli()
Zypper.upgrade_one_cli()
Zypper.sync()
Zypper.cleanup()
Zypper.cli_names
Zypper.id
Zypper.name
Zypper.virtual
Zypper.cli_errors
SubmodulesΒΆ
meta_package_manager.bar_plugin moduleΒΆ
Xbar and SwiftBar plugin for Meta Package Manager (i.e. the mpm CLI).
Default update cycle should be set to several hours so we have a chance to get userβs attention once a day. Higher frequency might ruin the system as all checks are quite resource intensive, and Homebrew might hit GitHubβs API calls quota.
Xbar automatically bridge plugin options between its UI and environment variable on script execution.
This is in progress for SwiftBar.
- meta_package_manager.bar_plugin.PYTHON_MIN_VERSION = (3, 8, 0)ΒΆ
Minimal requirement is aligned to mpm.
- meta_package_manager.bar_plugin.MPM_MIN_VERSION = (5, 0, 0)ΒΆ
Mpm v5.0.0 was the first version taking care of the complete layout rendering.
- class meta_package_manager.bar_plugin.Venv(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)ΒΆ
Bases:
Enum
Type of virtualenv we are capable of detecting.
- PIPENV = 1ΒΆ
- UV = 2ΒΆ
- POETRY = 3ΒΆ
- VIRTUALENV = 4ΒΆ
- class meta_package_manager.bar_plugin.MPMPlugin[source]ΒΆ
Bases:
object
Implements the minimal code necessary to locate and call the
mpm
CLI on the system.Once
mpm
is located, we can rely on it to produce the main output of the plugin.The output must supports both Xbar dialect and SwiftBar dialect.
- static getenv_str(var, default=None)[source]ΒΆ
Utility to get environment variables.
Note that all environment variables are strings. Always returns a lowered-case string.
- static getenv_bool(var, default=False)[source]ΒΆ
Utility to normalize boolean environment variables.
Relies on
configparser.RawConfigParser.BOOLEAN_STATES
to translate strings into boolean. See: https://github.com/python/cpython/blob/89192c4/Lib/configparser.py#L597-L599- Return type:
- static v_to_str(version_tuple)[source]ΒΆ
Transforms into a string a tuple of integers representing a version.
- Return type:
- property table_rendering: boolΒΆ
Aligns package names and versions, like a table, for easier visual parsing.
If
True
, will aligns all items using a fixed-width font.
- property all_pythons: list[str]ΒΆ
Search for any Python on the system.
Returns a generator of normalized and deduplicated
Path
to Python binaries.Filters out old Python interpreters.
We first try to locate Python by respecting the environment variables as-is, i.e. as defined by the user. Then we return the Python interpreter used to execute this script.
TODO: try to tweak the env vars to look for homebrew location etc?
- static search_venv(folder)[source]ΒΆ
Search for signs of a virtual env in the provided folder.
Returns the type of the detected venv and CLI arguments that can be used to run a command from the virtualenv context.
Returns
(None, None)
if the folder is not a venv.Inspired by autoswitch_virtualenv.plugin.zsh and `uv's get_interpreter_info.py https://github.com/astral-sh/uv/blob/f770b25/crates/uv-python/python/get_interpreter_info.py>`_.
- search_mpm()[source]ΒΆ
Iterare over possible CLI commands to execute
mpm
.Should be able to produce the full spectrum of alternative commands we can use to invoke
mpm
over different context.The order in which the candidates are returned by this method is conserved by the
ranked_mpm()
method below.We prioritize venv-based findings first, as theyβre more likely to have all dependencies installed and sorted out. Theyβre also our prime candidates in unittests.
Then we search for system-wide installation. And finally Python modules.
- property ranked_mpm: list[tuple[tuple[str, ...], bool, bool, tuple[int, ...] | None, str | Exception | None]]ΒΆ
Rank the mpm candidates we found on the system.
Sort them by: - runnability - up-to-date status - version number - error
On tie, the order from
search_mpm
is respected.
- property best_mpm: tuple[tuple[str, ...], bool, bool, tuple[int, ...] | None, str | Exception | None]ΒΆ
- static pp(label, *args)[source]ΒΆ
Print one menu-line with the Xbar/SwiftBar dialect.
First argument is the menu-line label, separated by a pipe to all other non- empty parameters, themselves separated by a space.
Skip printing of the line if label is empty.
- Return type:
- print_error(message, submenu='')[source]ΒΆ
Print a formatted error message line by line.
A red, fixed-width font is used to preserve traceback and exception layout. For compactness, the block message is dedented and empty lines are skipped.
Message is always casted to a string as we allow passing of exception objects and have them rendered.
- Return type:
Print the main menu.
- Return type:
meta_package_manager.base moduleΒΆ
- class meta_package_manager.base.Operations(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)ΒΆ
Bases:
Enum
Recognized operation IDs that are implemented by package manager with their specific CLI invocation.
Each operation has its own CLI subcommand.
- installed = 1ΒΆ
- outdated = 2ΒΆ
- search = 3ΒΆ
- install = 4ΒΆ
- upgrade = 5ΒΆ
- upgrade_all = 6ΒΆ
- remove = 7ΒΆ
- sync = 8ΒΆ
- cleanup = 9ΒΆ
- exception meta_package_manager.base.CLIError(code, output, error)[source]ΒΆ
Bases:
Exception
An error occurred when running package manager CLI.
The exception internally keeps the result of CLI execution.
- class meta_package_manager.base.Package(id, manager_id, name=None, description=None, installed_version=None, latest_version=None, arch=None)[source]ΒΆ
Bases:
object
Lightweight representation of a package and its metadata.
-
manager_id:
str
ΒΆ Handy to backtrack whose manager this package belongs to.
The manager ID is good enough and allows for no coupling with the parent manager object.
-
installed_version:
TokenizedString
|str
|None
= NoneΒΆ
-
latest_version:
TokenizedString
|str
|None
= NoneΒΆ Installed and latest versions are optional: theyβre not always provided by the package manager.
installed_version
andlatest_version
are allowed to temporarily be strings between__init__
and__post_init__
. Once they reach the later, theyβre parsed and normalized into eitherTokenizedString
or None. They canβt be strings beyond that point, i.e. after the Package instance has been fully instantiated. We donβt know how to declare this transient state with type hints, so weβre just going to allow string type.
- property purl: PackageURLΒΆ
Returns the packageβs pURL object.
-
manager_id:
- meta_package_manager.base.packages_asdict(packages, keep_fields)[source]ΒΆ
Returns a list of packages casted to a
dict
with only a subset of its fields.
- class meta_package_manager.base.MetaPackageManager(name, bases, dct)[source]ΒΆ
Bases:
type
Custom metaclass used as a class factory for package managers.
Sets some class defaults, but only if theyβre not redefined in the final manager class.
Also normalize list of platform, by ungrouping groups, deduplicate entries and freeze them into a set of unique platforms.
- meta_package_manager.base.highlight_cli_name(path, match_names)[source]ΒΆ
Highlight the binary name in the provided
path
.If
match_names
is provided, only highlight the start of the binary name that is in the list.Matching is insensitive to case on Windows and case-sensitive on other platforms, thanks to
os.path.normcase
.
- class meta_package_manager.base.PackageManager[source]ΒΆ
Bases:
object
Base class from which all package manager definitions inherits.
Initialize
cli_errors
list.-
deprecated:
bool
= FalseΒΆ A manager marked as deprecated will be hidden from all package selection by default.
You can still use it but need to explicitly call for it on the command line.
Implementation of a deprecated manager will be kept within mpm source code, but some of its features or total implementation are allowed to be scraped in the face of maintenance pain and adversity.
Integration tests and unittests for deprecated managers can be removed. We do not care if a deprecated manager is not 100% reliable. A flakky deprecated manager should not block a release due to flakky tests.
-
deprecation_url:
str
|None
= NoneΒΆ Announcement from the official project or evidence of abandonment of maintenance.
-
id:
str
= 'packagemanager'ΒΆ 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.
-
name:
str
= 'PackageManager'ΒΆ Return package managerβs common name.
Default value is based on class name.
-
homepage_url:
str
|None
= NoneΒΆ Home page of the project, only used in documentation for reference.
-
platforms:
Union
[Platform
,Group
,Iterable
[Union
[Platform
,Group
,Iterable
[_TNestedSources]]]] = frozenset({})ΒΆ List of platforms supported by the manager.
Allows for a mishmash of platforms and groups. Will be normalized into a frozenset of
Platform
instances at instantiation.
-
requirement:
str
|None
= NoneΒΆ Minimal required version.
Should be a string parseable by
meta_package_manager.version.parse_version
.Defaults to
None
, which deactivate version check entirely.
-
cli_names:
tuple
[str
,...
] = ('packagemanager',)ΒΆ 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. 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
orpython3
.By default, this propertyβs value is derived from the managerβs ID (see the
MetaPackageManager.__init__
method above).
-
virtual:
bool
= TrueΒΆ 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.
-
cli_search_path:
tuple
[str
,...
] = ()ΒΆ List of additional path to help mpm hunt down the package manager CLI.
Must be a list of strings whose order dictates the search sequence.
Most of the time unnecessary:
meta_package_manager.base.PackageManager.cli_path()
works well on all platforms.
-
extra_env:
Optional
[Mapping
[str
,Optional
[str
]]] = NoneΒΆ Additional environment variables to add to the current context.
Automatically applied on each
meta_package_manager.base.PackageManager.run_cli()
calls.
-
pre_cmds:
tuple
[str
,...
] = ()ΒΆ Global list of pre-commands to add before before invoked CLI.
Automatically added to each
meta_package_manager.base.PackageManager.run_cli()
call.Used to prepend sudo or other system utilities.
-
post_args:
tuple
[str
,...
] = ()ΒΆ Global list of options used before and after the invoked package manager CLI.
Automatically added to each
meta_package_manager.base.PackageManager.run_cli()
call.Essentially used to force silencing, low verbosity or no-color output.
-
version_cli_options:
tuple
[str
,...
] = ('--version',)ΒΆ List of options to get the version from the package manager CLI.
-
version_regex:
str
= '(?P<version>\\S+)'ΒΆ Regular expression used to extract the version number from the result of the CLI run with the options above. It doesnβt matter if the regex returns unsanitized and crappy string. The
meta_package_manager.base.PackageManager.version()
method will clean and normalized it.By default match the first part that is space-separated.
-
ignore_auto_updates:
bool
= TrueΒΆ Some managers can report or ignore packages which have their own auto-update mechanism.
- package(**kwargs)[source]ΒΆ
Instantiate a
Package
object from the manager.Sets its
manage_id
to the manager it belongs to.- Return type:
- classmethod implements(op)[source]ΒΆ
Inspect managerβs implementation to check for proper support of an operation.
- Return type:
- search_all_cli(cli_names, env=None)[source]ΒΆ
Search for all binary files matching the CLI names, in all environment path.
This is like our own implementation of
shutil.which()
, with the difference that it is capable of returning all the possible paths of the provided file names, in all environment path, not just the first one that match. And on Windows, prevents matching of CLI in the current directory, which takes precedence on other paths.Returns all files matching any
cli_names
, by iterating over all folders in this order:folders provided by
cli_search_path
,then in all the default places specified by the environment variable (i.e.
os.getenv("PATH")
).
Only returns files that exists and are not empty.
Caution
Symlinks are not resolved, because some manager like Homebrew on Linux relies on some sort of symlink-based trickery to set environment variables.
- property cli_path: Path | NoneΒΆ
Fully qualified path to the canonical package manager binary.
Try each CLI names provided by
cli_names
, in each system path provided bycli_search_path
. In that order. Then returns the first match.Executability of the CLI will be separately assessed later by the
meta_package_manager.base.PackageManager.executable()
method below.
- property version: TokenizedString | NoneΒΆ
Invoke the manager and extract its own reported version string.
Returns a parsed and normalized version in the form of a
meta_package_manager.version.TokenizedString
instance.
- property available: boolΒΆ
Is the package manager available and ready-to-use on the system?
Returns
True
only if the main CLI:
- run(*args, extra_env=None)[source]ΒΆ
Run a shell command, return the output and accumulate error messages.
args
is allowed to be a nested structure of iterables, in which case it will be recursively flatten, thenNone
will be discarded, and finally each item casted to strings.- Return type:
- Running commands with that method takes care of:
adding logs at the appropriate level
removing ANSI escape codes from
subprocess.CompletedProcess.stdout
andsubprocess.CompletedProcess.stderr
returning ready-to-use normalized strings (dedented and stripped)
letting
mpm --dry-run
andmpm --stop-on-error
have expected effect on execution
- build_cli(*args, auto_pre_cmds=True, auto_pre_args=True, auto_post_args=True, override_pre_cmds=None, override_cli_path=None, override_pre_args=None, override_post_args=None, sudo=False)[source]ΒΆ
Build the package manager CLI by combining the custom
*args
with the package managerβs global parameters.Returns a tuple of strings.
Helps the construction of CLIβs repeating patterns and makes the code easier to read. Just pass the specific
*args
and the full CLI string will be composed out of the globals, following this schema:$ [<pre_cmds>|sudo] <cli_path> <pre_args> <*args> <post_args>
self.pre_cmds
is added before the CLI path.self.cli_path
is used as the main binary to execute.self.pre_args
andself.post_args
globals are added before and after the provided*args
.
Each additional set of elements can be disabled with their respective flag:
auto_pre_cmds=False
to skip the automatic addition ofself.pre_cmds
auto_pre_args=False
to skip the automatic addition ofself.pre_args
auto_post_args=False
to skip the automatic addition ofself.post_args
Each global set of elements can be locally overridden with:
override_pre_cmds=tuple()
override_cli_path=str
override_pre_args=tuple()
override_post_args=tuple()
On linux, the command can be run with sudo if the parameter of the same name is set to
True
. In which case theoverride_pre_cmds
parameter is not allowed to be set and theauto_pre_cmds
parameter is forced toFalse
.
- run_cli(*args, auto_extra_env=True, auto_pre_cmds=True, auto_pre_args=True, auto_post_args=True, override_extra_env=None, override_pre_cmds=None, override_cli_path=None, override_pre_args=None, override_post_args=None, force_exec=False, sudo=False)[source]ΒΆ
Build and run the package manager CLI by combining the custom
*args
with the package managerβs global parameters.After the CLI is built with the
meta_package_manager.base.PackageManager.build_cli()
method, it is executed with themeta_package_manager.base.PackageManager.run()
method, augmented with environment variables fromself.extra_env
.All parameters are the same as
meta_package_manager.base.PackageManager.build_cli()
, plus: :rtype:str
auto_extra_env=False
to skip the automatic addition ofself.extra_env
override_extra_env=dict()
to locally overrides the laterforce_exec
ignores thempm --dry-run
andmpm --stop-on-error
options to force the execution and completion of the command.
- property installed: Iterator[Package]ΒΆ
List packages currently installed on the system.
Optional. Will be simply skipped by mpm if not implemented.
- property outdated: Iterator[Package]ΒΆ
List installed packages with available upgrades.
Optional. Will be simply skipped by mpm if not implemented.
- classmethod query_parts(query)[source]ΒΆ
Returns a set of all contiguous alphanumeric string segments.
Contrary to
meta_package_manager.version.TokenizedString
, do no splits on colated number/alphabetic junctions.
- search(query, extended, exact)[source]ΒΆ
Search packages available for install.
There is no need for this method to be perfect and sensitive to
extended
andexact
parameters. If the package manager is not supporting these kind of options out of the box, just returns the closest subset of matching package you can come up with. Finer refiltering will happens in themeta_package_manager.base.PackageManager.refiltered_search()
method below.Optional. Will be simply skipped by mpm if not implemented.
- refiltered_search(query, extended, exact)[source]ΒΆ
Returns search results with extra manual refiltering to refine gross matchings.
Some package managers returns unbounded results, and/or donβt support fine search criterions. In which case we use this method to manually refilters
meta_package_manager.base.PackageManager.search()
results to either exclude non-extended or non-exact matches.Returns a generator producing the same data as the
meta_package_manager.base.PackageManager.search()
method above. :rtype:Iterator
[Package
]Tip
If you are implementing a package manager definition, do not waste time to filter CLI results. Let this method do this job.
Instead, just implement the core
meta_package_manager.base.PackageManager.search()
method above and try to produce results as precise as possible using the native filtering capabilities of the package manager CLI.
- install(package_id, version=None)[source]ΒΆ
Install one package and one only.
Allows a specific
version
to be provided.- Return type:
- upgrade_all_cli()[source]ΒΆ
Returns the complete CLI to upgrade all outdated packages on the system.
- upgrade_one_cli(package_id, version=None)[source]ΒΆ
Returns the complete CLI to upgrade one package and one only.
Allows a specific
version
to be provided.
- upgrade(package_id=None, version=None)[source]ΒΆ
Perform an upgrade of either all or one package.
Executes the CLI provided by either
meta_package_manager.base.PackageManager.upgrade_all_cli()
ormeta_package_manager.base.PackageManager.upgrade_one_cli()
.If the manager doesnβt provides a full upgrade one-liner (i.e. if
meta_package_manager.base.PackageManager.upgrade_all_cli()
raisesNotImplementedError
), then the list of all outdated packages will be fetched (viameta_package_manager.base.PackageManager.outdated()
) and each package will be updated one by one by callingmeta_package_manager.base.PackageManager.upgrade_one_cli()
.See for example the case of
meta_package_manager.managers.pip.Pip.upgrade_one_cli()
.- Return type:
- remove(package_id)[source]ΒΆ
Remove one package and one only.
Optional. Will be simply skipped by mpm if not implemented.
- Return type:
-
deprecated:
meta_package_manager.capabilities moduleΒΆ
Utilities and helper to organize, inspect and audit the capabilities of mpm and package managers.
meta_package_manager.cli moduleΒΆ
- meta_package_manager.cli.XKCD_MANAGER_ORDER = ('pip', 'brew', 'npm', 'dnf', 'apt', 'steamcmd')ΒΆ
Sequence of package managers as defined by XKCD #1654: Universal Install Script.
See the corresponding implementation rationale in issue #10.
- meta_package_manager.cli.is_stdout(filepath)[source]ΒΆ
Check if a file path is set to stdout.
Prevents the creation of a
-
file in the current directory.- Return type:
- meta_package_manager.cli.prep_path(filepath)[source]ΒΆ
Prepare the output file parameter for Clickβs echo function.
- meta_package_manager.cli.update_manager_selection(ctx, param, value)[source]ΒΆ
Update global selection list of managers in the context.
Accumulate and merge all manager selectors to form the initial population enforced by the user.
- Return type:
- meta_package_manager.cli.single_manager_selectors()[source]ΒΆ
Dynamiccaly creates a dedicated flag selector alias for each manager.
- meta_package_manager.cli.bar_plugin_path(ctx, param, value)[source]ΒΆ
Print the location of the Xbar/SwiftBar plugin.
Returns the normalized path of the standalone bar_plugin.py script that is distributed with this Python module. This is made available under the
mpm --bar-plugin-path
option.Notice that the fully-qualified home directory get replaced by its shorthand (
~
) if applicable:the full
/home/user/.python/site-packages/mpm/bar_plugin.py
path is simplified to~/.python/site-packages/mpm/bar_plugin.py
,but
/usr/bin/python3.10/mpm/bar_plugin.py
is returned as-is.
meta_package_manager.inventory moduleΒΆ
Introspection utilities to produce feature inventory of all managers.
- meta_package_manager.inventory.MAIN_PLATFORMS: tuple[Group | Platform, ...] = (Group(id='bsd', name='BSD', platform_ids=frozenset({'netbsd', 'sunos', 'openbsd', 'midnightbsd', 'freebsd'})), Group(id='linux', name='Linux', platform_ids=frozenset({'opensuse', 'mageia', 'sles', 'centos', 'altlinux', 'raspbian', 'pidora', 'tuxedo', 'buildroot', 'rhel', 'oracle', 'parallels', 'debian', 'cloudlinux', 'slackware', 'android', 'exherbo', 'gentoo', 'ubuntu', 'scientific', 'guix', 'wsl2', 'kvmibm', 'linuxmint', 'fedora', 'rocky', 'unknown_linux', 'arch', 'xenserver', 'amzn', 'wsl1', 'ibm_powerkvm', 'mandriva'})), Platform(id='macos', name='macOS', current=False), Group(id='unix', name='Unix', platform_ids=frozenset({'aix', 'solaris', 'cygwin', 'hurd'})), Group(id='windows', name='Windows', platform_ids=frozenset({'windows'})))ΒΆ
Top-level classification of platforms.
This is the local reference used to classify the execution targets of
mpm
.Each entry of this list will have its own dedicated column in the matrix. This list is manually maintained with tweaked IDs and names to minimize the matrix verbosity and make it readable both in CLI and documentation.
The order of this list determine the order of the resulting columns.
- meta_package_manager.inventory.managers_sankey()[source]ΒΆ
Produce a sankey diagram to map
mpm
to all its supported managers.- Return type:
meta_package_manager.labels moduleΒΆ
Utilities to generate extra labels to use for GitHub issues and PRs.
- meta_package_manager.labels.generate_labels(all_labels, groups, prefix, color)[source]ΒΆ
Generate labels.
A dedicated label is produced for each entry of the
all_labels
parameter, unless it is part of agroup
. In which case a dedicated label for that group will be created.
- meta_package_manager.labels.MANAGER_LABEL_GROUPS: Dict[str, FrozenSet[str]] = {'dnf-based': frozenset({'dnf', 'dnf5', 'yum'}), 'dpkg-based': frozenset({'apt', 'apt-mint', 'opkg'}), 'homebrew': frozenset({'brew', 'cask'}), 'npm-based': frozenset({'npm', 'yarn'}), 'pacman-based': frozenset({'pacaur', 'pacman', 'paru', 'yay'}), 'pip-based': frozenset({'pip', 'pipx'}), 'vscode-based': frozenset({'vscode', 'vscodium'})}ΒΆ
Managers sharing some origin or implementation are grouped together under the same label.
- meta_package_manager.labels.all_manager_label_ids = frozenset({'apm', 'apt', 'apt-mint', 'brew', 'cargo', 'cask', 'choco', 'composer', 'dnf', 'dnf5', 'emerge', 'eopkg', 'flatpak', 'fwupd', 'gem', 'mas', 'mpm', 'npm', 'opkg', 'pacaur', 'pacman', 'paru', 'pip', 'pipx', 'pkg', 'scoop', 'snap', 'steamcmd', 'uv', 'vscode', 'vscodium', 'winget', 'yarn', 'yay', 'yum', 'zypper'})ΒΆ
Adds
mpm
as its own manager alongside all those implemented.
- meta_package_manager.labels.MANAGER_LABELS = {'apm': 'π¦ manager: apm', 'apt': 'π¦ manager: dpkg-based', 'apt-mint': 'π¦ manager: dpkg-based', 'brew': 'π¦ manager: homebrew', 'cargo': 'π¦ manager: cargo', 'cask': 'π¦ manager: homebrew', 'choco': 'π¦ manager: choco', 'composer': 'π¦ manager: composer', 'dnf': 'π¦ manager: dnf-based', 'dnf5': 'π¦ manager: dnf-based', 'emerge': 'π¦ manager: emerge', 'eopkg': 'π¦ manager: eopkg', 'flatpak': 'π¦ manager: flatpak', 'fwupd': 'π¦ manager: fwupd', 'gem': 'π¦ manager: gem', 'mas': 'π¦ manager: mas', 'mpm': 'π¦ manager: mpm', 'npm': 'π¦ manager: npm-based', 'opkg': 'π¦ manager: dpkg-based', 'pacaur': 'π¦ manager: pacman-based', 'pacman': 'π¦ manager: pacman-based', 'paru': 'π¦ manager: pacman-based', 'pip': 'π¦ manager: pip-based', 'pipx': 'π¦ manager: pip-based', 'pkg': 'π¦ manager: pkg', 'scoop': 'π¦ manager: scoop', 'snap': 'π¦ manager: snap', 'steamcmd': 'π¦ manager: steamcmd', 'uv': 'π¦ manager: uv', 'vscode': 'π¦ manager: vscode-based', 'vscodium': 'π¦ manager: vscode-based', 'winget': 'π¦ manager: winget', 'yarn': 'π¦ manager: npm-based', 'yay': 'π¦ manager: pacman-based', 'yum': 'π¦ manager: dnf-based', 'zypper': 'π¦ manager: zypper'}ΒΆ
Maps all manager IDs to their labels.
- meta_package_manager.labels.PLATFORM_LABELS = {'ALT Linux': 'π₯ platform: Linux', 'Amazon Linux': 'π₯ platform: Linux', 'Android': 'π₯ platform: Linux', 'Arch Linux': 'π₯ platform: Linux', 'Buildroot': 'π₯ platform: Linux', 'CentOS': 'π₯ platform: Linux', 'CloudLinux OS': 'π₯ platform: Linux', 'Cygwin': 'π₯ platform: Unix', 'Debian': 'π₯ platform: Linux', 'Exherbo Linux': 'π₯ platform: Linux', 'Fedora': 'π₯ platform: Linux', 'FreeBSD': 'π₯ platform: BSD', 'GNU/Hurd': 'π₯ platform: Unix', 'Gentoo Linux': 'π₯ platform: Linux', 'Guix System': 'π₯ platform: Linux', 'IBM AIX': 'π₯ platform: Unix', 'IBM PowerKVM': 'π₯ platform: Linux', 'KVM for IBM z Systems': 'π₯ platform: Linux', 'Linux Mint': 'π₯ platform: Linux', 'Mageia': 'π₯ platform: Linux', 'Mandriva Linux': 'π₯ platform: Linux', 'MidnightBSD': 'π₯ platform: BSD', 'NetBSD': 'π₯ platform: BSD', 'OpenBSD': 'π₯ platform: BSD', 'Oracle Linux': 'π₯ platform: Linux', 'Parallels': 'π₯ platform: Linux', 'Pidora': 'π₯ platform: Linux', 'Raspbian': 'π₯ platform: Linux', 'RedHat Enterprise Linux': 'π₯ platform: Linux', 'Rocky Linux': 'π₯ platform: Linux', 'SUSE Linux Enterprise Server': 'π₯ platform: Linux', 'Scientific Linux': 'π₯ platform: Linux', 'Slackware': 'π₯ platform: Linux', 'Solaris': 'π₯ platform: Unix', 'SunOS': 'π₯ platform: BSD', 'Tuxedo OS': 'π₯ platform: Linux', 'Ubuntu': 'π₯ platform: Linux', 'Unknown Linux': 'π₯ platform: Linux', 'Windows': 'π₯ platform: Windows', 'Windows Subsystem for Linux v1': 'π₯ platform: Linux', 'Windows Subsystem for Linux v2': 'π₯ platform: Linux', 'XenServer': 'π₯ platform: Linux', 'macOS': 'π₯ platform: macOS', 'openSUSE': 'π₯ platform: Linux'}ΒΆ
Maps all platform names to their labels.
- meta_package_manager.labels.LABELS: list[tuple[str, str, str]] = [('π¦ manager: apm', '#bfdadc', 'apm'), ('π¦ manager: cargo', '#bfdadc', 'cargo'), ('π¦ manager: choco', '#bfdadc', 'choco'), ('π¦ manager: composer', '#bfdadc', 'composer'), ('π¦ manager: dnf-based', '#bfdadc', 'dnf, dnf5, yum'), ('π¦ manager: dpkg-based', '#bfdadc', 'apt, apt-mint, opkg'), ('π¦ manager: emerge', '#bfdadc', 'emerge'), ('π¦ manager: eopkg', '#bfdadc', 'eopkg'), ('π¦ manager: flatpak', '#bfdadc', 'flatpak'), ('π¦ manager: fwupd', '#bfdadc', 'fwupd'), ('π¦ manager: gem', '#bfdadc', 'gem'), ('π¦ manager: homebrew', '#bfdadc', 'brew, cask'), ('π¦ manager: mas', '#bfdadc', 'mas'), ('π¦ manager: mpm', '#bfdadc', 'mpm'), ('π¦ manager: npm-based', '#bfdadc', 'npm, yarn'), ('π¦ manager: pacman-based', '#bfdadc', 'pacaur, pacman, paru, yay'), ('π¦ manager: pip-based', '#bfdadc', 'pip, pipx'), ('π¦ manager: pkg', '#bfdadc', 'pkg'), ('π¦ manager: scoop', '#bfdadc', 'scoop'), ('π¦ manager: snap', '#bfdadc', 'snap'), ('π¦ manager: steamcmd', '#bfdadc', 'steamcmd'), ('π¦ manager: uv', '#bfdadc', 'uv'), ('π¦ manager: vscode-based', '#bfdadc', 'vscode, vscodium'), ('π¦ manager: winget', '#bfdadc', 'winget'), ('π¦ manager: zypper', '#bfdadc', 'zypper'), ('π bar-plugin', '#fef2c0', 'Xbar/SwiftBar plugin code, documentation and features'), ('π₯ platform: BSD', '#bfd4f2', 'FreeBSD, MidnightBSD, NetBSD, OpenBSD, SunOS'), ('π₯ platform: Linux', '#bfd4f2', 'ALT Linux, Amazon Linux, Android, Arch Linux, Buildroot, CentOS, CloudLinux OS, Debian, β¦'), ('π₯ platform: macOS', '#bfd4f2', 'macOS'), ('π₯ platform: Unix', '#bfd4f2', 'Cygwin, GNU/Hurd, IBM AIX, Solaris'), ('π₯ platform: Windows', '#bfd4f2', 'Windows')]ΒΆ
Global registry of all labels used in the project.
Structure:
("label_name", "color", "optional_description")
meta_package_manager.output moduleΒΆ
Helpers and utilities to render and print content.
Todo
Some of these are good candidates for upstream contribution to click.extra
.
- meta_package_manager.output.SORTABLE_FIELDS = {'manager_id', 'manager_name', 'package_id', 'package_name', 'version'}ΒΆ
List of fields IDs allowed to be sorted.
- meta_package_manager.output.colored_diff(a, b, style_common=None, style_a=None, style_b=None)[source]ΒΆ
Highlight the most common left part between
a
andb
strings and their trailing differences.Always returns 2 strings.
- meta_package_manager.output.print_json(data)[source]ΒΆ
Pretty-print Python data to JSON and output results to
<stdout>
.Serialize
pathlib.Path
andmeta_package_manager.version.TokenizedString
objects.
- meta_package_manager.output.print_table(header_defs, rows, sort_key=None)[source]ΒΆ
Print a table.
header_defs
parameter is an ordered list of tuple whose first item is the columnβs label and the second the columnβs ID. Example:[ ("Column 1", "column1"), ("User's name", "name"), ("Package manager", "manager_id"), ..., ]
Rows can be sorted by providing the columnβs ID to
sort_key
parameter. By default,None
means the table will be sorted in the order of columns provided byheader_defs
.- Return type:
- meta_package_manager.output.print_stats(manager_stats)[source]ΒΆ
Prints statistics to
<stderr>
: total packages and a break down by package manager.Prints something like:
10 packages total (brew: 2, pip: 2, gem: 2, vscode: 2, npm: 2, composer: 0).
- Return type:
- class meta_package_manager.output.BarPluginRenderer[source]ΒΆ
Bases:
MPMPlugin
All utilities used to render output compatible with both Xbar and SwiftBar plugin dialect.
The minimal code to locate
mpm
, then call it and print its output resides in the plugin itself atmeta_package_manager.bar_plugin.MPMPlugin.best_mpm()
.All other stuff, especially the rendering code, is managed here, to allow for more complex layouts relying on external Python dependencies. This also limits the number of required updates on the plugin itself.
Group packages into manager sub-menus.
If
True
, will replace the default flat layout with an alternative structure where actions are grouped into submenus, one for each manager.Value is sourced from the
VAR_SUBMENU_LAYOUT
environment variable.
- property dark_mode: boolΒΆ
Detect dark mode by inspecting environment variables.
Value is sourced from two environment variables depending on the plugin:
OS_APPEARANCE
for SwiftBarXBARDarkMode
for XBar
- static render_cli(cmd_args)[source]ΒΆ
Return a formatted CLI compatible with Xbar and SwiftBar plugin format.
I.e. a string with this schema:
shell=cmd_args[0] param1=cmd_args[1] param2=cmd_args[2] ...
- Return type:
- print_cli_item(*args)[source]ΒΆ
Print two CLI entries: :rtype:
None
one that is silent
a second one that is the exact copy of the above but forces the execution by the way of a visible terminal
- print_upgrade_all_item(manager, submenu='')[source]ΒΆ
Print the menu entry to upgrade all outdated package of a manager.
- Return type:
- plain_table_format = (None, None, None, None, ('', ' ', ''), ('', ' ', ''), 0, None)ΒΆ
Simple rendering format with single-space separated columns used in the function below.
- static render_table(table_data)[source]ΒΆ
Renders a table data with pre-configured alignment centered around the third column.
Returns a list of strings, one item per line.
>>> table_data = [ ... ("xmlrpc", "0.3.1", "β", "0.4"), ... ("blockblock", "5.33,VHSDGataYCcV8xqv5TSZA", "β", "5.39"), ... ("sed", "2", "β", "2021.0328"), ... ] >>> print(render_table(table_data)) xmlrpc 0.3.1 β 0.4 blockblock 5.33,VHSDGataYCcV8xqv5TSZA β 5.39 sed 2 β 2021.0328
..todo:
Use upcoming ``tabulate.SEPARATING_LINE`` to produce the whole bar plugin table in one go and have all version numbers from all managers aligned. See: https://github.com/astanin/python-tabulate/commit/dab256d1f64da97720c1459478a3cc0a4ea7a91e
- render(outdated_data)[source]ΒΆ
Wraps the
meta_package_manager.output.BarPluginRenderer._render()
function above to capture allprint
statements.- Return type:
meta_package_manager.pool moduleΒΆ
Registration, indexing and caching of package manager supported by mpm
.
- meta_package_manager.pool.manager_classes = (<class 'meta_package_manager.managers.apm.APM'>, <class 'meta_package_manager.managers.apt.APT'>, <class 'meta_package_manager.managers.apt.APT_Mint'>, <class 'meta_package_manager.managers.homebrew.Brew'>, <class 'meta_package_manager.managers.cargo.Cargo'>, <class 'meta_package_manager.managers.homebrew.Cask'>, <class 'meta_package_manager.managers.chocolatey.Choco'>, <class 'meta_package_manager.managers.composer.Composer'>, <class 'meta_package_manager.managers.dnf.DNF'>, <class 'meta_package_manager.managers.dnf.DNF5'>, <class 'meta_package_manager.managers.emerge.Emerge'>, <class 'meta_package_manager.managers.eopkg.EOPKG'>, <class 'meta_package_manager.managers.flatpak.Flatpak'>, <class 'meta_package_manager.managers.fwupd.FWUPD'>, <class 'meta_package_manager.managers.gem.Gem'>, <class 'meta_package_manager.managers.mas.MAS'>, <class 'meta_package_manager.managers.npm.NPM'>, <class 'meta_package_manager.managers.opkg.OPKG'>, <class 'meta_package_manager.managers.pacman.Pacaur'>, <class 'meta_package_manager.managers.pacman.Pacman'>, <class 'meta_package_manager.managers.pacman.Paru'>, <class 'meta_package_manager.managers.pip.Pip'>, <class 'meta_package_manager.managers.pipx.Pipx'>, <class 'meta_package_manager.managers.pkg.PKG'>, <class 'meta_package_manager.managers.scoop.Scoop'>, <class 'meta_package_manager.managers.snap.Snap'>, <class 'meta_package_manager.managers.steamcmd.SteamCMD'>, <class 'meta_package_manager.managers.uv.UV'>, <class 'meta_package_manager.managers.vscode.VSCode'>, <class 'meta_package_manager.managers.vscode.VSCodium'>, <class 'meta_package_manager.managers.winget.WinGet'>, <class 'meta_package_manager.managers.yarn.Yarn'>, <class 'meta_package_manager.managers.pacman.Yay'>, <class 'meta_package_manager.managers.dnf.YUM'>, <class 'meta_package_manager.managers.zypper.Zypper'>)ΒΆ
The list of all classes implementing the specific package managers.
Is considered valid package manager, definitions classes which:
- are located in the :py:prop:`meta_package_manager.pool.ManagerPool.manager_subfolder`
subfolder, and
are sub-classes of
meta_package_manager.base.PackageManager
, and- are not :py:prop:`meta_package_manager.base.PackageManager.virtual` (i.e. have a
non-null :py:prop:`meta_package_manager.base.PackageManager.cli_names` property).
These properties are checked and enforced in unittests.
- class meta_package_manager.pool.ManagerPool[source]ΒΆ
Bases:
object
A dict-like register, instantiating all supported package managers.
-
ALLOWED_EXTRA_OPTION:
Final
= frozenset({'dry_run', 'ignore_auto_updates', 'stop_on_error', 'timeout'})ΒΆ List of extra options that are allowed to be set on managers during the use of the
meta_package_manager.pool.ManagerPool.select_managers()
helper below.
- property register: dict[str, PackageManager]ΒΆ
Instantiate all supported package managers.
- get(key)ΒΆ
- property all_manager_ids: tuple[str, ...]ΒΆ
All recognized manager IDs.
Returns a list of sorted items to provide consistency across all UI, and reproducibility in the order package managers are evaluated.
- property default_manager_ids: tuple[str, ...]ΒΆ
All manager IDs supported on the current platform and not deprecated.
Must keep the same order defined by :py:prop:`meta_package_manager.pool.ManagerPool.all_manager_ids`.
- property unsupported_manager_ids: tuple[str, ...]ΒΆ
All manager IDs unsupported on the current platform but still maintained.
Order is not important here as this list will be used to discard managers from selection sets.
-
ALLOWED_EXTRA_OPTION:
meta_package_manager.sbom moduleΒΆ
- class meta_package_manager.sbom.ExportFormat(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]ΒΆ
Bases:
Enum
A user-friendly version of
spdx_tools.spdx.formats.FileFormat
.- JSON = 'json'ΒΆ
- XML = 'xml'ΒΆ
- YAML = 'yaml'ΒΆ
- TAG_VALUE = 'tag'ΒΆ
- RDF_XML = 'rdf'ΒΆ
Map format to user-friendly IDs.
- class meta_package_manager.sbom.SBOM(export_format=ExportFormat.JSON)[source]ΒΆ
Bases:
object
Utilities shared by all SBOM classes.
Defaults to JSON export format.
- class meta_package_manager.sbom.SPDX(export_format=ExportFormat.JSON)[source]ΒΆ
Bases:
SBOM
Generates an SPDX document from a list of packages.
Defaults to JSON export format.
- DOC_ID = 'SPDXRef-DOCUMENT'ΒΆ
Document root ID.
-
document:
Document
ΒΆ
- classmethod normalize_spdx_id(str)[source]ΒΆ
SPDX IDs must only contain letters, numbers,
.
and-
.- Return type:
- init_doc()[source]ΒΆ
SPDX document metadata specifications.
- Return type:
- add_package(manager, package)[source]ΒΆ
SPDX package metadata specifications.
- Return type:
- class meta_package_manager.sbom.CycloneDX(export_format=ExportFormat.JSON)[source]ΒΆ
Bases:
SBOM
Generates a CycloneDX document from a list of packages.
Defaults to JSON export format.
-
document:
Bom
ΒΆ
- init_doc()[source]ΒΆ
CycloneDX document metadata specifications.
- Return type:
- add_package(manager, package)[source]ΒΆ
CycloneDX package metadata specifications.
- Return type:
-
document:
meta_package_manager.specifier moduleΒΆ
Utilities to manage and resolve constraints from a set of package specifiers.
- meta_package_manager.specifier.VERSION_SEP: Final = '@'ΒΆ
Separator used by
mpm
to split packageβs ID from its version:This has been chosen as a separator because it is shared by popular package managers and purls.
..code-block:
package_id@version
- class meta_package_manager.specifier.Specifier(raw_spec, package_id, manager_id=None, version=None)[source]ΒΆ
Bases:
object
Lightweight representation of a package specification.
Contains all parsed metadata to be used as constraints.
- classmethod parse_purl(spec_str)[source]ΒΆ
Parse a purl string.
Yields
Specifier
objects or returnsNone
.
- classmethod from_string(spec_str)[source]ΒΆ
Parse a string into a package specifier.
Supports various formats: - plain
package_id
- simple package ID with version:package_id@version
- purl:pkg:npm/left-pad@3.7
If a specifier resolves to multiple constraints (as it might be the case for purl), we produce and returns all variations. That way the
Solver
below has all necessary details to resolve the constraints.Returns a generator of
Specifier
.
- property parsed_version: TokenizedStringΒΆ
- exception meta_package_manager.specifier.EmptyReduction[source]ΒΆ
Bases:
Exception
Raised by the solver if no constraint canβt be met.
- class meta_package_manager.specifier.Solver(spec_strings=None, manager_priority=None)[source]ΒΆ
Bases:
object
Combine a set of
Specifier
and allow for the solving of the constraints they represent.- populate_from_strings(spec_strings)[source]ΒΆ
Populate the solver with package specifiers parsed from provided strings.
- top_priority_manager(keep_managers=None)[source]ΒΆ
Returns the top priority manager configured on the solver.
keep_managers
allows for filtering by discarding managers not in that list.
- reduce_specs(specs)[source]ΒΆ
Reduce a collection of
Specifier
to its essential, minimal and unique form.This method assumes that all provided
specs
are of the same package (likeresolve_package_specs()
does).The reduction process consist of several steps. At each step, as soon as we managed to reduce the constraints to one
Specifier
, we returns it.- Return type:
Filtering steps: 1. We remove all constraints tied to all by the top priority manager if
provided.
- If no manager priority is provided, we discard constraints not tied to a
manager.
We discard constraints not tied to a version.
We only keep constraints tied to the highest version.
If we ends up with more than one set of constraints after all this filtering, an error is raised to invite the developer to troubleshoot the situation and refine this process.
meta_package_manager.version moduleΒΆ
Helpers and utilities to parse and compare version numbers.
- class meta_package_manager.version.Token(value)[source]ΒΆ
Bases:
object
A token is a normalized word, persisting its lossless integer variant.
Support natural comparison with
str
andint
types.We mainly use them here to compare versions and package IDs.
Instantiates a
Token
from an alphanumeric string or a non-negative integer.
- class meta_package_manager.version.TokenizedString(value, separator='-')[source]ΒΆ
Bases:
object
Tokenize a string for user-friendly sorting.
Essentially a wrapper around a list of
Token
instances.Parse and tokenize the provided raw
value
.
- meta_package_manager.version.parse_version = functools.partial(<class 'meta_package_manager.version.TokenizedString'>, separator='.')ΒΆ
Utility method tweaking
TokenizedString
for dot-based serialization.