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

Allow subcommands to be created by namespace packages #269

Closed
goodmami opened this issue Jan 15, 2020 · 0 comments
Closed

Allow subcommands to be created by namespace packages #269

goodmami opened this issue Jan 15, 2020 · 0 comments
Milestone

Comments

@goodmami
Copy link
Member

Just like packages in the delphin.codecs namespace become available for the delphin convert command, we could allow namespace packages to register subcommands for the delphin command-line interface. One way of doing this is to crawl all top-level packages and look for some metadata, similar to how the codecs work. But this would slow down command invocation because all modules would need to be imported. If backward compatibility weren't an issue, we could make delphin.commands into a namespace package and just look for modules in that directory, but then existing imports (like from delphin.commands import mkprof; mkprof(...)) would not work as mkprof would need to be a module and modules are not callable. Instead we could make a new namespace like delphin.cli.

It would work like this:

  • delphin.main crawls modules in delphin.cli
  • if one of these modules contains the appropriate code, a subcommand is created for it

The "appropriate code" could be some metadata that delphin.main uses to construct the subcommand, or some function like register() that takes the top-level argument parser and adds the subcommand itself.

@goodmami goodmami added this to the v1.2.0 milestone Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant