Changeset View
Changeset View
Standalone View
Standalone View
swh/core/cli/__init__.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import logging.config | import logging.config | ||||
import warnings | |||||
import click | import click | ||||
import pkg_resources | import pkg_resources | ||||
LOG_LEVEL_NAMES = ["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | LOG_LEVEL_NAMES = ["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | ||||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) | CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | |||||
def main(): | def main(): | ||||
# Even though swh() sets up logging, we need an earlier basic logging setup | # Even though swh() sets up logging, we need an earlier basic logging setup | ||||
# for the next few logging statements | # for the next few logging statements | ||||
logging.basicConfig() | logging.basicConfig() | ||||
# load plugins that define cli sub commands | # load plugins that define cli sub commands | ||||
for entry_point in pkg_resources.iter_entry_points("swh.cli.subcommands"): | for entry_point in pkg_resources.iter_entry_points("swh.cli.subcommands"): | ||||
try: | try: | ||||
cmd = entry_point.load() | cmd = entry_point.load() | ||||
if isinstance(cmd, click.BaseCommand): | |||||
# for BW compat, auto add click commands | |||||
warnings.warn( | |||||
f"{entry_point.name}: automagic addition of click commands " | |||||
f"to the main swh group is deprecated", | |||||
DeprecationWarning, | |||||
vlorentz: you might want to explain why and/or how to fix it in a comment here | |||||
Done Inline ActionsTBH I have the fix for every concerned swh package waiting just behind, so... douardda: TBH I have the fix for every concerned swh package waiting just behind, so... | |||||
Not Done Inline Actionsokay, good vlorentz: okay, good | |||||
) | |||||
swh.add_command(cmd, name=entry_point.name) | swh.add_command(cmd, name=entry_point.name) | ||||
# otherwise it's expected to be a module which has been loaded | |||||
# it's the responsibility of the click commands/groups in this | |||||
# module to transitively have the main swh group as parent. | |||||
except Exception as e: | except Exception as e: | ||||
logger.warning("Could not load subcommand %s: %s", entry_point.name, str(e)) | logger.warning("Could not load subcommand %s: %s", entry_point.name, str(e)) | ||||
return swh(auto_envvar_prefix="SWH") | return swh(auto_envvar_prefix="SWH") | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||
main() | main() |
you might want to explain why and/or how to fix it in a comment here