meta_package_manager package

Subpackages

Submodules

meta_package_manager.base module

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.PackageManager[source]

Bases: object

Base class from which all package manager definitions must inherits.

platforms = frozenset({})
requirement = None
cli_search_path = []
global_args = []
stop_on_error = False
ignore_auto_updates = True
id = 'packagemanager'
name = 'PackageManager'
cli_names = ['packagemanager']
virtual = True
cli_path

Fully qualified path to the package manager CLI.

Automaticaly search the location of the CLI in the system. Try multiple CLI names within several system path.

Only checks if the file exists. Its executability will be assessed later. See the self.executable method below.

Returns None if no CLI was found or those found were not a file.

get_version()[source]

Invoke the manager and extract its own reported version.

It does matter if this method return unsanitized and crappy string. The version() method below will clean and normalized it.

version

Parsed and normalized package manager’s own version.

Returns an instance of TokenizedString.

supported

Is the package manager supported on that platform?

executable

Is the package manager CLI can be executed by the current user?

fresh

Does the package manager match the version requirement?

available

Is the package manager available and ready-to-use on the system?

Returns True only if the main CLI:

# is supported on the current platform, # was found on the system, # is executable, and # match the version requirement.

run(*args, dry_run=False)[source]

Run a shell command, return the output and keep error message.

Removes ANSI escape codes, and returns ready-to-use strings.

run_cli(*args, dry_run=False)[source]

Like the run method above, but execute the binary pointed to by the cli_path property set in the current instance.

sync()[source]

Refresh local manager metadata from remote repository.

cleanup()[source]

Remove left-overs and unused packages.

property installed

List packages currently installed on the system.

Returns a dict indexed by package IDs. Each item is a dict with package ID, name and version.

search(query, extended, exact)[source]

Search packages whose ID contain exact or partial query.

Returns a dict indexed by package IDs. Each item is a dict with package ID, name, version and a boolean indicating if the match is exact or partial.

property outdated

List currently installed packages having a new version available.

Returns a dict indexed by package IDs. Each item is a dict with package ID, name, current installed version and latest upgradeable version.

upgrade_cli(package_id=None)[source]

Return a shell-compatible full-CLI to upgrade a package.

upgrade(package_id=None, dry_run=False)[source]

Perform the upgrade of the provided package to latest version.

upgrade_all_cli()[source]

Return a shell-compatible full-CLI to upgrade all packages.

upgrade_all(dry_run=False)[source]

Perform a full upgrade of all outdated packages to latest versions.

If the manager doesn’t implements a full upgrade one-liner, then fall-back to calling single-package upgrade one by one.

static render_cli(cmd, cli_format='plain')[source]

Return a formatted CLI in the requested format.

  • plain returns a simple string

  • fragments returns a list of strings

  • xbar (or bitbar) returns a CLI with parameters formatted into

the xbar dialect

Warning

bitbar is deprecated but is provided as temporary alias to xbar to provide a smooth transition to the rebooted project.

meta_package_manager.cli module

meta_package_manager.cli.json(data)[source]

Utility function to render data structure into pretty printed JSON.

Also care of internal objects like TokenizedString and Path:

meta_package_manager.cli.print_table(header_defs, rows, sort_key=None)[source]

Utility to print a table and sort its content.

meta_package_manager.cli.print_stats(data)[source]

Print statistics.

class meta_package_manager.cli.timeit[source]

Bases: object

Decorator to measure and print elapsed execution time of a function.

meta_package_manager.config module

Utilities to load parameters and options from a configuration file.

exception meta_package_manager.config.ConfigurationFileError[source]

Bases: Exception

Base class for all exceptions related to configuration file.

meta_package_manager.config.default_conf_path()[source]

Returns default location of the configuration file.

Location depends on OS (see Click documentation):

  • macOS & Linux: ~/.mpm/config.toml

  • Windows: C:\Users\<user>\AppData\Roaming\mpm\config.toml

meta_package_manager.config.conf_structure()[source]

Returns the supported configuration structure.

Derives TOML structure from CLI definition.

Sections are dicts. All options have their defaults value to None.

meta_package_manager.config.read_conf(conf_filepath)[source]

Loads a configuration files and only returns recognized options and their values.

Invalid parameters are ignored.

meta_package_manager.config.load_conf(ctx, param, config_file)[source]

meta_package_manager.labels module

Utilities to manage GitHub labels to use in issues and PR management.

meta_package_manager.platform module

Helpers and utilities to identify and handle platform idiosyncracies.

meta_package_manager.platform.LINUX = 'linux'

Constant used to identify OSes of the Linux family.

meta_package_manager.platform.MACOS = 'macos'

Constant used to identify OSes of the macOS family.

meta_package_manager.platform.WINDOWS = 'windows'

Constant used to identify OSes of the Windows family.

meta_package_manager.platform.is_linux()[source]

Return True only if current platform is of the Linux family.

meta_package_manager.platform.is_macos()[source]

Return True only if current platform is of the macOS family.

meta_package_manager.platform.is_windows()[source]

Return True only if current platform is of the Windows family.

meta_package_manager.platform.os_label(os_id)[source]

Return platform label for user-friendly output.

meta_package_manager.platform.current_os()[source]

Return a 2-items tuple with ID and label of current OS.

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 and int types.

We mainly use them here to compare versions and package IDs.

Instantiates a Token from alphanumeric strings or non-negative integers.

static str_to_int(string)[source]

Convert a string or an integer to a (string, integer) couple.

Returns together the original string and its integer representation if convertion is successful and lossless. Else returns the original string and None.

string = None
integer = None
property isint

Does the Token got a pure integer representation?

class meta_package_manager.version.TokenizedString(value, *args, **kwargs)[source]

Bases: object

Tokenize a string for user-friendly sorting.

Essentially a wrapper around a tuple of Token instances.

Return same object if a TokenizedString parameter is used at instanciation.

string = None
tokens = ()
separator = None
pretty_print()[source]
classmethod tokenize(string)[source]

Tokenize a string: ignore case and split at each non-alphanumeric characters.

Returns a tuple of Token instances. Which allows for comparison between strings and integers. That way we get natural, user-friendly sorting of version numbers. That we can get with simple Python, see:

>>> '2019.0.1' > '9.3'
False
>>> ('2019', '0', '1') > ('9', '3')
False
>>> (2019, 0, 1) > (9, 3)
True

Module contents

Expose package-wide elements.