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
Branch
current
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 5583
Build 7607: tox-on-jenkinsJenkins
Build 7606: arc lint + arc unit

Event Timeline

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
31–35

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
swh/core/cli/__init__.py
31–35

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

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
57

swh.cli.subcommands would certainly be more explicit ?

58

Useless use of swh-? :)

no need to keep the cli plugins in a dict

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.

This revision is now accepted and ready to land.May 6 2019, 12:29 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.