Skip to main content

A set of utilities around click, for extensible CLI

Project description

extencli

A set of utilities around click, which offers extensible CLI mechanism, with little effort

Features

Easy third-party extensible click.group

This package offers a specialized click.group implementation. Using it, you can create a CLI that will be extended by simply installing additional modules.

As an example, here is how one would define an extensible click.group in their python package core_module:

import click

from extencli import PluginAutoloaderGroup

@click.group('core', cls=PluginAutoloaderGroup, depends_on='core_module')
def core_group():
    ...

The depends_on parameter is required:

  • depends_on specifies the name of the package that CLI extensions should depend on

Now, the CLI extension package should import the core_group from the core_module like so:

from core_module.cli import core_group

@core_group.command('myext')
def cli_extension():
    ...

Now, by simply installing both the core_module and the extension third-party, the core_module will be extended with the myext command:

$> core --help
Usage: core [OPTIONS] COMMAND [ARGS]...

Options:
  --help                          Show this message and exit.

Commands:
  myext

Caveats

Silent "failure" to load extensions

If the base CLI has its extensible group declared in the __init__.py file, the internal click initialization mechanism might use different instances of the group when loaded by extensions, and when invoked through the CLI.

To avoid this, please refer to the tests's tests/python_packages/test_core python module, which is built in a way that avoid this caveat:

  • extensible group should not be in the __init__.py file
  • pyproject.toml may refer directly to it for script entrypoints

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extencli-0.3.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

extencli-0.3.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file extencli-0.3.0.tar.gz.

File metadata

  • Download URL: extencli-0.3.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for extencli-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ddbb32d139ef912133527333f31d618deb5dba4ee1f36076d8f00fcce5a00101
MD5 f9352283612e4eb77343fd309bf110ff
BLAKE2b-256 24c4ec747be05aedf4ea619dcd0739111f798f8f9e7896dcb4d6c54a26d7b023

See more details on using hashes here.

Provenance

The following attestation bundles were made for extencli-0.3.0.tar.gz:

Publisher: workflow.yml on Joacchim/extencli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file extencli-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: extencli-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for extencli-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d35bb03deb4d223084566d0bd8cf99162db45c84b1d661d4e481eafd5ee11a0
MD5 b932fd1790b1e3d524b811829a62139f
BLAKE2b-256 f6b464a49e703d12f5e6c0bd6a6f55ab05ed6dd0f4ac3920a18ea9a55e56f675

See more details on using hashes here.

Provenance

The following attestation bundles were made for extencli-0.3.0-py3-none-any.whl:

Publisher: workflow.yml on Joacchim/extencli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page