Comments (2)
@grovduck questions are welcome! The docs definitely need some work.
This is a use case I had not considered but after poking around the behavior is, surprisingly, correct. You're on the right track with your point about entry point names matching the objects they reference. The string plugin=root_plugin.cli:main_group
is a set of instructions for pkg_resources
. plugin
is an ID you are assigning to root_plugin.cli:main_group
, which points to a Python object. In code terms:
from pkg_resources import iter_entry_points
mapping = {e.name: e.load() for e in iter_entry_points('root.plugins')}
which produces:
{'plugin': <click.core.Group at 0x10b379668>}
click
then uses the Group()
's name as the subcommand name in the CLI:
mapping['plugin'].name
which defaults to the function name, which in this case is main_group
.
The solution is to do @click.group(name='plugin-name')
so you can reference $ root plugin-name
.
Alternatively, click derives a default Group.name
from the decorated function's name, so you could change the name of main_group()
to plugin()
. The $ foo
command is correct because you're telling setuptools
to install an executable called foo
pointing to main_group
. For the top Group()
in the chain click
uses the executable's name rather than Group.name
. You can see this behavior by adding this snippet to your root_plugin/cli.py
file and executing directly:
if __name__ == '__main__':
main_group()
Although the displayed program name can also be changed in this case with main_group(prog_name='foo')
.
Caveat: if an exception is encountered in EntryPoint.load()
the plugin will be registered under EntryPoint.name
rather than Group.name
. Executing $ root plugin
will reveal the traceback.
plugin † Warning: could not load plugin. See `root plugin --help`.
I'll leave this ticket open and add this info to the docs.
from click-plugins.
Excellent, thanks so much @geowurster. I hadn't seen that syntax on click.group()
before. Works like a charm.
from click-plugins.
Related Issues (19)
- Port from PR
- Release 1.0.2 HOT 1
- Allow with_plugins() to accept a string
- Cleanup docs
- test_group_chain fails with python-click 6.7+git20180829-1 HOT 4
- Release v1.0
- Release 1.0.4 HOT 1
- Investigate performance HOT 1
- List plugin commands in separate sections? HOT 1
- A broken command with arguments hides failure trace
- Replace existing command HOT 1
- Enable Travis-CI and coveralls.io HOT 5
- [ERROR] Package has no install method: python-click-plugins HOT 1
- Entry points can not be loaded if there is a package version conflict anywhere in the environment HOT 7
- click 8+ comapt new release HOT 2
- @with_plugins() causes a type error in PyCharm
- "show_envvar=True" inside plugins shows . used in environment variable name HOT 1
- Release 1.0.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from click-plugins.