-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Support callable subcommands #362
Conversation
- Renamed the use of builtin `help` in one occasion; - changed 2 TCs to test with 2-tuples; - improved slightly the documentation. See ipython#361 for rational.
+ Mimic behavior of similar libraries (docopt, click) and tools. Part of ipython#361.
740a589
to
5637976
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense, but it will need some changing to how the constructors are implemented, because Applications
are callable and will be handled incorrectly.
# this must be a dict of two-tuples, | ||
# the first element being the application class/import string | ||
# and the second being the help string for the subcommand | ||
#: subcommands for launching other applications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like these colons were added by accident
#: if this is not empty, this will be a parent Application | ||
#: this must be a dict of two-tuples, | ||
#: the first element is the application class, or and import string | ||
#: or a callable with a single argument for the parent returnng |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returnng
if isinstance(subapp, six.string_types): | ||
subapp = import_item(subapp) | ||
if callable(subapp): | ||
self.subapp = subapp(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classes are callable, so this check will catch the common case of subapp being an Application and handle it incorrectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed!
Would this be ok?
if callable(subapp) and not isinstance(subapp, Application):
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think so, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Editing my self, more like issubclass(subapp, Application)
...and also avoid invoking ConfigSingleton.instance()
when factory method supplied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
+ Previous commit was unfinished; the check was outright wrong (see discussion in ipython#362) and the purpose was not to invoke SingletonConfigurable.instance() at all. + Added subcommands-TCs.
5637976
to
bc746ac
Compare
Re-enable TC-code for subcmds forgotten by #362
Subcommands might be classes, strings (name of classes) and now Callables with a single argument: the parent Application instance (i.e. to read configs from).
That way it is possible to create different subcommands based on the same Application-class just with different constructor arguments.
I could not fins any test-cases about subcommands, so this PR is not considered finished - submitted for discussion.