meta_package_manager.tables module¶

Table-output vocabulary and rendering plumbing shared by the subcommands.

The mpm subcommands render heterogeneous tables (different columns per command) but share the same output machinery. This module owns all of it:

  • SortableField, the vocabulary of the global mpm --sort-by selector. The selector itself is click-extra’s field-vocabulary SortByOption, and the per-table resolution (sort by the selected fields the table carries, keep the original row order when it carries none) happens inside click_extra.table.print_table(), from the field each header pairs with its column in the registries below.

  • The per-command column registries, each pairing a click-extra ColumnSpec (whose ID addresses the column from --columns) with the SortableField the column carries (None for a column that cannot drive the sort). A registry is the single source of truth for its command: the same tuple feeds the @columns_option declaration (which validates the user selection) and print_projected_table() (which projects headers and rows before rendering).

  • print_projected_table() and print_serialized_and_exit(), the human-friendly and machine-friendly rendering paths every table-producing subcommand goes through.

class meta_package_manager.tables.SortableField(*values)[source]¶

Bases: StrEnum

Fields IDs allowed to be sorted.

MANAGER_ID = 'manager_id'¶
MANAGER_NAME = 'manager_name'¶
PACKAGE_ID = 'package_id'¶
PACKAGE_NAME = 'package_name'¶
VERSION = 'version'¶
meta_package_manager.tables.MANAGERS_COLUMNS: tuple[tuple[ColumnSpec, SortableField | None], ...] = ((ColumnSpec(id='manager_id', label='Manager ID', description="Manager's identifier.", max_width=None), SortableField.MANAGER_ID), (ColumnSpec(id='manager_name', label='Name', description="Manager's common name.", max_width=None), SortableField.MANAGER_NAME), (ColumnSpec(id='supported', label='Supported', description='Support status on the current platform.', max_width='auto'), None), (ColumnSpec(id='cli', label='CLI', description="Location of the manager's binary on the system.", max_width='auto'), None), (ColumnSpec(id='executable', label='Executable', description='Whether the binary is executable.', max_width=None), None), (ColumnSpec(id='version', label='Version', description="Manager's self-reported version, and the unsatisfied requirement when stale.", max_width=None), SortableField.VERSION))¶

Columns of the mpm managers table.

supported and cli are the two whose content no manager bounds: the first enumerates every platform a manager runs on when they do not collapse to a group name, the second holds a filesystem path. Both take AUTO_WIDTH so they share whatever the fixed columns leave on the terminal and wrap inside their own cell, instead of stretching the table past the edge and mangling every border.

meta_package_manager.tables.MANAGERS_DETECTED_COLUMNS: tuple[str, ...] = ('manager_id', 'manager_name', 'cli', 'version')¶

Columns kept by the default, detected-only view of the mpm managers table.

A detected manager is by definition supported on this platform, found and executable, so supported and executable render the same âś“ on every row and carry no information. Both come back in the wider views, where an unsupported platform or a missing binary makes them vary again. Only the default selection narrows: --columns still addresses every column of MANAGERS_COLUMNS.

meta_package_manager.tables.INSTALLED_COLUMNS: tuple[tuple[ColumnSpec, SortableField | None], ...] = ((ColumnSpec(id='package_id', label='Package ID', description="Package's identifier.", max_width=None), SortableField.PACKAGE_ID), (ColumnSpec(id='package_name', label='Name', description="Package's common name.", max_width='auto'), SortableField.PACKAGE_NAME), (ColumnSpec(id='manager_id', label='Manager', description='Manager reporting the package.', max_width=None), SortableField.MANAGER_ID), (ColumnSpec(id='installed_version', label='Installed version', description='Version currently installed.', max_width='auto'), SortableField.VERSION))¶

Columns of the mpm installed table.

Important

package_id is deliberately the one column of every package table left uncapped, and the rule holds wherever these specs are reused. It is the value the user copies back into an mpm install, mpm remove or mpm upgrade invocation, and a cell wrapped over two lines cannot be selected in one go. So it never wraps, and the shrinking falls on its neighbors instead: the name is free prose, and a version is read rather than retyped.

The trade is explicit. A package ID wider than the terminal on its own still pushes the table past the edge, because the alternative is handing the user a broken identifier. Both halves of the trade are real here: vim-pack names its plugins by GitHub URL (50 characters), and Homebrew Cask reports versions like 1.26832.0,056ee2be623b207f6a4d24dfb1b2fb5a82db0ecf.

meta_package_manager.tables.OUTDATED_COLUMNS: tuple[tuple[ColumnSpec, SortableField | None], ...] = ((ColumnSpec(id='package_id', label='Package ID', description="Package's identifier.", max_width=None), SortableField.PACKAGE_ID), (ColumnSpec(id='package_name', label='Name', description="Package's common name.", max_width='auto'), SortableField.PACKAGE_NAME), (ColumnSpec(id='manager_id', label='Manager', description='Manager reporting the package.', max_width=None), SortableField.MANAGER_ID), (ColumnSpec(id='installed_version', label='Installed version', description='Version currently installed.', max_width='auto'), SortableField.VERSION), (ColumnSpec(id='latest_version', label='Latest version', description='Version available for upgrade.', max_width='auto'), None))¶

Columns of the mpm outdated table.

Inherits the width policy documented on INSTALLED_COLUMNS: the second version column wraps like the first, package_id still does not.

meta_package_manager.tables.SEARCH_COLUMNS: tuple[tuple[ColumnSpec, SortableField | None], ...] = ((ColumnSpec(id='package_id', label='Package ID', description="Package's identifier.", max_width=None), SortableField.PACKAGE_ID), (ColumnSpec(id='package_name', label='Name', description="Package's common name.", max_width='auto'), SortableField.PACKAGE_NAME), (ColumnSpec(id='manager_id', label='Manager', description='Manager reporting the match.', max_width=None), SortableField.MANAGER_ID), (ColumnSpec(id='latest_version', label='Latest version', description='Latest version available.', max_width='auto'), SortableField.VERSION), (ColumnSpec(id='description', label='Description', description='Package description, for managers that provide one. Out of the default selection: select it explicitly or pass --description.', max_width='auto'), None))¶

Columns of the mpm search table.

The description column exists in the registry (so --columns can select it) but stays out of the default selection unless --description (or --extended, which searches descriptions) is passed.

It is the column holding the longest free prose, of a length no manager bounds: a single verbose match used to stretch the table far past the terminal and wrap every row at the edge, mangling the borders. AUTO_WIDTH caps it at whatever the other columns leave on the terminal, so the description wraps inside its own cell. The name and version columns share that treatment, and package_id is exempt from it, per the width policy documented on INSTALLED_COLUMNS.

meta_package_manager.tables.WHICH_COLUMNS: tuple[tuple[ColumnSpec, SortableField | None], ...] = ((ColumnSpec(id='manager_id', label='Manager ID', description='Manager whose search path found the binary.', max_width=None), SortableField.MANAGER_ID), (ColumnSpec(id='priority', label='Priority', description="Rank of the match in the manager's search path.", max_width=None), None), (ColumnSpec(id='cli_path', label='CLI path', description='Location of the matched binary.', max_width=None), None), (ColumnSpec(id='symlink', label='Symlink destination', description='Resolved target when the match is a symlink.', max_width=None), None))¶

Columns of the mpm which table.

meta_package_manager.tables.column_specs(columns)[source]¶

Extract the bare ColumnSpec tuple from a column registry.

Return type:

tuple[ColumnSpec, ...]

meta_package_manager.tables.print_projected_table(ctx, columns, rows, default_ids=None)[source]¶

Render dict rows as a table projected through --columns.

The --columns selection restricts and reorders the rendering, SQL-SELECT-style; click-extra’s ColumnsOption already validated it against the same columns registry, so unknown IDs never reach this point. default_ids is the selection applied when the user passed none (search uses it to hide the description column unless --description); None keeps every column in canonical order.

Sorting stays on mpm’s global --sort-by: each header pairs its label with the sortable field the column carries, and click-extra’s print_table() reads the selection (with the --table-format one) from the shared context meta and resolves it per table. A sort field whose column is projected out is simply skipped, and a table carrying none of the selected fields keeps its original row order.

Note

The width limits are forwarded by hand, from the same specs the projection just resolved. click-extra reads them off ColumnSpec headers on its own, but mpm’s headers are (label, sortable field) pairs instead: a spec’s ID addresses the column for --columns while the field it sorts on may differ (installed_version sorts on version) or be absent altogether, which a bare spec cannot express.

Return type:

None

meta_package_manager.tables.print_serialized_and_exit(ctx, data)[source]¶

Render data in the active serialization format, then exit.

When the global --table-format resolves to one of the structured serialization formats (JSON, YAML, TOML, XML, …), serialize data under the shared mpm root element and stop the program. Otherwise return, so the caller falls through to its human-friendly table rendering.

Return type:

None