Page MenuHomeSoftware Heritage

cli: add a generic main 'swh' command and extract the db-init command
ClosedPublic

Authored by douardda on Apr 19 2019, 12:13 PM.

Details

Summary

in a dedicated submodule. Ensure both:

swh db-init

and

swh-db-init

work.

Related to T1671.

Diff Detail

Repository
rDCORE Foundations and core functionalities
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

douardda created this revision.Apr 19 2019, 12:13 PM
olasd requested changes to this revision.Apr 19 2019, 4:16 PM
olasd added a subscriber: olasd.
olasd added inline comments.
swh/core/cli/__init__.py
32–36

Do we really need the dict here? If so, would you mind adding a comment as to how/where it's being used in addition to the noqa? (and if not, I guess we can just flip around the for loop)

This revision now requires changes to proceed.Apr 19 2019, 4:16 PM
douardda added inline comments.Apr 19 2019, 4:19 PM
swh/core/cli/__init__.py
32–36

we probably do not need to keep this dict, but we need to ensure packages are loaded. Let me check this.

olasd added a comment.Apr 19 2019, 4:22 PM

So, from what I understand, the subcommand name is set by the name of the function in the plugin, when the swh.command() decorator is called.

I think it would be less surprising, if the entry points were used to actually define which functions are to be decorated, and the subcommand name.

So your entry point definition could be

[swh.cli.subcommands]
db-init=swh.core.cli.db:db_init

And you could make the main or swh command lazy-load and decorate the proper function at runtime.

Does that make sense?

setup.py
58

swh.cli.subcommands would certainly be more explicit ?

59

Useless use of swh-? :)

douardda updated this revision to Diff 4645.Apr 19 2019, 4:24 PM

no need to keep the cli plugins in a dict

douardda updated this revision to Diff 4682.May 2 2019, 3:19 PM

Implement the entrypoint loading mechanism using functions instead of modules

as suggested by olasd. This does not implement any generic lazy loading
magic stuff for now.

olasd accepted this revision.May 6 2019, 12:29 PM
This revision is now accepted and ready to land.May 6 2019, 12:29 PM
douardda updated this revision to Diff 4699.May 6 2019, 3:22 PM

include forgotten patch: add log_level to 'swh' context obj

so subcommands can do specific stuff with current log level if needed.

See swh/core/cli/__init__.py:26

This revision was landed with ongoing or failed builds.May 6 2019, 3:23 PM
This revision was automatically updated to reflect the committed changes.