Git Product home page Git Product logo

Comments (1)

geowurster avatar geowurster commented on September 23, 2024

@thedrow Looks like the answer is no. Using the included example PrintIt package as the example package that receives plugins I tried modifying PrintItBold to override the upper command:

$ pip install -e example/PrintIt
$ printit --help
Usage: printit [OPTIONS] COMMAND [ARGS]...

  Format and print file contents.

  For example:
  
      $ cat README.rst | printit lower

Options:
  --help  Show this message and exit.

Commands:
  lower  Convert to lower case.
  upper  Convert to upper case.

First I defined a new upper() function in example/PrintItBold/printit_bold/core.py

@click.command()
def upper():

    """
    Override.
    """
    
    click.echo("Override.")

Then I registered it as a plugin in example/PrintItBold/setup.py

upper=printit_bold.core:upper

Installing the plugin shows a new bold command as expected, however the upper command is from PrintIt and not PrintItBold.

$ pip install -e example/PrintItBold
$ printit --help
Usage: printit [OPTIONS] COMMAND [ARGS]...

  Format and print file contents.

  For example:
  
      $ cat README.rst | printit lower

Options:
  --help  Show this message and exit.

Commands:
  bold   † Warning: could not load plugin. See `printit bold --help`.
  lower  Convert to lower case.
  upper  Convert to upper case.

Removing the code defining the upper command does cause the new upper command to be exposed:

$ printit --help
Usage: printit [OPTIONS] COMMAND [ARGS]...

  Format and print file contents.

  For example:
  
      $ cat README.rst | printit lower

Options:
  --help  Show this message and exit.

Commands:
  bold   † Warning: could not load plugin. See `printit bold --help`.
  lower  Convert to lower case.
  upper  Override.

So this feature is feasible given that technically the parent command is overriding the plugin, but after stepping through this the current behavior seems correct. Preserving the parent commands offers consistency to all users and instead forces alternate command implementations to register themselves under new names. If a plugin overrides the parent command with the same help text but behaves differently then it could be difficult to identify exactly why the command is behaving differently. I can see this scenario happening:

  • A user depends on a specific package with a specific command.
  • They install some other package.
  • That package has a dependency that the user did not explicitly install.
  • The dependency overrides the CLI command that the user depends on.
  • The CLI command may or may not clearly be different and may or may not provide drastically different behavior.

from click-plugins.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.