Page MenuHomeSoftware Heritage

cli: do not add sub sub commands to the main swh cli group
AbandonedPublic

Authored by douardda on Thu, Sep 10, 10:26 AM.

Details

Reviewers
vlorentz
Group Reviewers
Reviewers
Summary

If the loaded command from the entry_point already exists in the
main swh command group, do not add is as a command of this later.

The idea is if you have a swh package (say swh.objstorage) that
declares a cli group, then a sub-package of this package (say
swh.objstorage.replayer) also declares a cli group that is a
sub-group of the first package's one (swh.objstorage in the
example above), then we do not want to re-add it again.

Typically, if the entrypoint for swh.objstorage.replayer is:

[swh.cli.subcommands]
content-replayer=swh.objstorage.replayer.cli:objstorage_group

with swh.objstorage.replayer.cli:objstorage_group being the cli
group of swh.objstorage, then we do not want to re-add this under
the main swh command group as 'content-replayer'.

Having it loaded is enought to make it registered under its parent
group, here, under swh objstorage.

Depends on D3901.

Event Timeline

douardda created this revision.Thu, Sep 10, 10:26 AM

Build is green

Patch application report for D3902 (id=13752)

Could not rebase; Attempt merge onto 6706f7a7f5...

Updating 6706f7a..48bf960
Fast-forward
 swh/core/cli/__init__.py | 11 ++++++-----
 swh/core/cli/db.py       |  7 ++++---
 2 files changed, 10 insertions(+), 8 deletions(-)
Changes applied before test
commit 48bf96008ad7611e8af7093fb564feab8b4196d8
Author: David Douard <david.douard@sdfa3.org>
Date:   Thu Sep 10 10:14:35 2020 +0200

    cli: do not add sub sub commands to the main swh cli group
    
    If the loaded command from the entry_point already exists in the
    main `swh` command group, do not add is as a command of this later.
    
    The idea is if you have a swh package (say swh.objstorage) that
    declares a cli group, then a sub-package of this package (say
    swh.objstorage.replayer) also declares a cli group that is a
    sub-group of the first package's one (swh.objstorage in the
    example above), then we do not want to re-add it again.
    
    Typically, if the entrypoint for swh.objstorage.replayer is:
    
      [swh.cli.subcommands]
      content-replayer=swh.objstorage.replayer.cli:objstorage_group
    
    with swh.objstorage.replayer.cli:objstorage_group being the cli
    group of swh.objstorage, then we do not want to re-add this under
    the main swh command group as 'content-replayer'.
    
    Having it loaded is enought to make it registered under its parent
    group, here, under `swh objstorage`.

commit 60c535ddee7bad85533974630855b0da825af899
Author: David Douard <david.douard@sdfa3.org>
Date:   Wed Sep 9 17:48:44 2020 +0200

    cli: speedup the `swh` cli command startup time
    
    by moving import statements in functions.
    
    Related to T2575.

See https://jenkins.softwareheritage.org/job/DCORE/job/tests-on-diff/39/ for more details.

Could you explain this as a comment in the code?

Also, tests would be nice but it might be outside the scope of this diff

vlorentz requested changes to this revision.Tue, Sep 15, 11:52 AM
This revision now requires changes to proceed.Tue, Sep 15, 11:52 AM
douardda abandoned this revision.Tue, Sep 22, 2:41 PM