Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CLI using click, rich, and stevedore #4497

Merged
merged 9 commits into from Aug 27, 2021
Merged

Implement CLI using click, rich, and stevedore #4497

merged 9 commits into from Aug 27, 2021

Conversation

@thrau
Copy link
Member

@thrau thrau commented Aug 26, 2021

This PR introduces a new CLI system using

  • click (the CLI framework, which we already had as transitive dependency)
  • rich (for colors, emojis, and other super important stuff!)
    image
  • stevedore (for the plugin mechanism)
  • It also moves the VERSION constant into localstack.__init__ as per convention

Plugin loading

the localstack-pro CLI now only works when installed as a distribution (using pip install or setup.py install). extensions simply residing in the python path is no longer sufficient for loading them.

to debug the plugin lifecycle run

DEBUG_PLUGINS=1 bin/localstack

Creating plugins

Plugins are advertised using setuptools entrypoints. To create a CLI plugin, first implement the LocalstackCliPlugin class that adds click commands to the localstack command group (a click.Group object):

class MyCliPlugin(LocalstackCliPlugin):
    name = "mine"

    def attach(self, cli: LocalstackCli) -> None:
        cli.group.add_command(...) # add your click commands to `localstack`

then, in the setup.py, add an entry point to the namespace localstack.plugins.cli (this will be automated in the future!)

setup(entry_points={
    "localstack.plugins.cli": [
        "mine = path.to.plugin:MyCliPlugin",
    ]
})

In localstack, we then use stevedore's Extension pattern to load extensions (using an ExtensionManager) in the namespace localstack.plugins.cli

@thrau thrau requested a review from whummer Aug 26, 2021
@coveralls
Copy link

@coveralls coveralls commented Aug 26, 2021

Coverage Status

Coverage increased (+0.09%) to 80.175% when pulling ece9e43 on click-cli into 9ce7c89 on master.

Copy link
Member

@whummer whummer left a comment

Love it! 🤩 Finally a banner, and some nice colors! 🌈

localstack/utils/bootstrap.py Outdated Show resolved Hide resolved
@thrau thrau force-pushed the click-cli branch from ece9e43 to 9568963 Aug 27, 2021
@whummer whummer merged commit 239801c into master Aug 27, 2021
3 of 5 checks passed
3 of 5 checks passed
ci/circleci: docker-build CircleCI is running your tests
Details
ci/circleci: itest-lambda-docker CircleCI is running your tests
Details
ci/circleci: install Your tests passed on CircleCI!
Details
ci/circleci: itest-elasticmq Your tests passed on CircleCI!
Details
ci/circleci: preflight Your tests passed on CircleCI!
Details
@whummer whummer deleted the click-cli branch Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants