meta_package_manager.bar_plugin module¶
SwiftBar and Xbar plugin for Meta Package Manager (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.SWIFTBAR_MIN_VERSION = (2, 1, 0)¶
SwiftBar
2.1.0fixes an issue with multiple parameters in the font strings.The fix was first handed out as a
2.1.2-labelled test build, a number that never reached a release: the public train renumbered it down to2.1.0. Requiring the build we validated on would lock the plugin out of every released SwiftBar.
- meta_package_manager.bar_plugin.XBAR_MIN_VERSION = (2, 1, 7)¶
Xbar v2.1.7-beta is the latest version available on Homebrew.
- 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.
- meta_package_manager.bar_plugin.INSTALL_ARGV = ('uv', 'tool', 'install', '--upgrade', 'meta-package-manager')¶
Bootstrap command offered when no runnable
mpmis found.A global uv tool install, the primary method of the installation page: it puts
mpmon thePATHof every shell, where apip installwould have buried it in whichever interpreter happened to run this plugin.--upgrademakes the same command serve the outdated-mpmcase, so nothing pins the specifier toMPM_MIN_VERSION: the latest release always satisfies it, and Xbar mangles a quoted>=specifier anyway (see matryer/xbar#831).The GNOME Shell extension offers the same command from its own missing-
mpmmenu, andtests/test_gnome_extension.pyholds the two in sync.
- meta_package_manager.bar_plugin.INSTALL_DOCS_URL = 'https://mpm.run/install/'¶
Installation page, offered beside
INSTALL_ARGV.uvmay itself be missing, and is not the right answer everywhere: a distribution package, Homebrew or a standalone binary all installmpmtoo.
- meta_package_manager.bar_plugin.MPM_TIMEOUT = 60¶
Maximum duration in seconds the plugin lets any single
mpmcall run.Passed as
--timeoutto everympminvocation so the plugin is never at the mercy of mpm’s own per-operation defaults, which are tuned for interactive CLI use and far too long for a background menubar refresh (120s for read-only queries, 500s for state-changing operations likesync). A wedged package manager then fails the whole refresh in a minute instead of freezing the menubar for several.
- class meta_package_manager.bar_plugin.MPMPlugin[source]¶
Bases:
objectImplements the minimal code necessary to locate and call the
mpmCLI on the system.Once
mpmis 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.
- Return type:
- static normalize_params(font_string, valid_ids=None)[source]¶
Parse a multi-parameters string and return a normalized string.
The string is expected to be a space-separated list of parameters, each parameter being a key/value pair separated by an equal sign.
Only keeps the parameters that are in the
valid_idsset and ignores the rest. By default, onlycolor,fontandsizeare kept.Multiple values for the same parameter will be deduplicated, and the last one will be kept.
Available parameters are documented by both hosts:
- Return type:
- static str_to_version(version_string)[source]¶
Transforms a string into a tuple of integers representing a version.
- static version_to_str(version_tuple)[source]¶
Transforms a tuple of integers representing a version into a string.
- Return type:
- property table_rendering: bool[source]¶
Aligns package names and versions, like a table, for easier visual parsing.
If
True, will aligns all items using a fixed-width font.
- property hide_when_up_to_date: bool[source]¶
Remove the menu bar icon entirely while there is nothing to report.
SwiftBar hides a plugin whose run produces no output, so rendering nothing is how the icon is made to disappear. That forces the plugin to tell a deliberate silence from a broken
mpmcall, which is whyprint_menu()only tolerates an empty output when this is set.Xbar has no such behavior, hence the SwiftBar-only declaration.
Value is sourced from the
VAR_HIDE_WHEN_UP_TO_DATEenvironment variable.
- property monospace_font: str[source]¶
Make it easier to change font, sizes and colors of the output.
- property error_font: str[source]¶
Error font is the monospace font, in red.
It carries no size of its own. A smaller string is still laid out in a row the menu sizes for the larger font, and both hosts leave the surplus under the text instead of splitting it: at
size=10, an error line ended up with 15 pixels of space below it where every other row leaves 9.
- static search_venv(folder)[source]¶
Search for signs of a virtual env in the provided folder.
Returns CLI arguments that can be used to run
mpmfrom the virtualenv context, orNoneif the folder is not a venv.Inspired by autoswitch_virtualenv.plugin.zsh and uv’s get_interpreter_info.py.
- search_mpm()[source]¶
Iterate over possible CLI commands to execute
mpm.Should be able to produce the full spectrum of alternative commands we can use to invoke
mpmover 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]][source]¶
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_mpmis respected.
- property best_mpm: tuple[tuple[str, ...], bool, bool, tuple[int, ...] | None, str | Exception | None][source]¶
- static pp(label, *args)[source]¶
Print one menu-line with the SwiftBar/Xbar 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. A
Noneparameter renders nothing, so a package without an upgrade CLI still gets its label-only menu line.- 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: