On Wed, Feb 26, 2020 at 1:17 PM Michael McLean <mikem(a)redhat.com> wrote:
I've assumed we'd eventually split commands.py (and for that matter kojihub.py).
When we reach that point, I don't think git blame output will be a blocker. It's
not so much losing history as putting an event into the history that most git tools
don't understand fully.
I do think this is a much larger discussion than the OP. I don't think we necessarily
have to immediately split commands.py in order to add new commands in a different file.
That said, however we do add new commands is likely to be the new standard, so we should
think about it carefully.
I am concerned about doing it right. If we were to simply split this file up yet keep the
rest of our cli framework the same, I fear we'd slow down load time for the tool (by
having to load a separate module for each command on each invocation). There are certainly
ways around this, but it's not clear to me what the best path is.
Do folks have examples of other python tools that they feel are good examples worthy of
emulation in this regard?
The pattern that I've used in python-errata-tool is that a command
invocation walks through three different files:
/usr/bin/errata-tool -
https://github.com/red-hat-storage/errata-tool/blob/master/bin/errata-tool
- This is just enough stub to get into the main library.
https://github.com/red-hat-storage/errata-tool/blob/master/errata_tool/cl...
- This is the main library that dispatches to each sub-command. It
passes a reference to the main ArgumentParser subparser into each
sub-command library's "add_parser()" method so that each sub-command
can do whatever it needs to do. Each sub-command library sets a
default "func" argument on the argparse subparser, and the main.py
dispatcher calls that as "args.func(args)" in order to hand over the
rest of the program.
https://github.com/red-hat-storage/errata-tool/blob/master/errata_tool/cl...
- This is an example of one sub-command, each with its own further
sub-commands.
For Koji, there are many sub-commands, so we don't want the explicit
"import" statements in the dispatcher for every one. I used
pkgutil.iter_modules and importlib.import_module to improve that today
at
https://github.com/red-hat-storage/errata-tool/pull/193 . We could
use something similar to walk through koji's commands/* and import
everything.
- Ken