diff options
author | Erik Skultety <eskultet@redhat.com> | 2023-03-14 14:26:04 +0100 |
---|---|---|
committer | Erik Skultety <eskultet@redhat.com> | 2023-03-14 15:50:40 +0100 |
commit | ab81087fbbbb070a67c8b95bdb74c40df14879c6 (patch) | |
tree | 50a78e24ca9bfd01a02e61afa8f70102ab522a69 /bin | |
parent | afaa24d276bc0db736f37b50c92ea6fa1e15cd30 (diff) | |
download | libvirt-ci-ab81087fbbbb070a67c8b95bdb74c40df14879c6.zip libvirt-ci-ab81087fbbbb070a67c8b95bdb74c40df14879c6.tar.gz libvirt-ci-ab81087fbbbb070a67c8b95bdb74c40df14879c6.tar.bz2 |
bin: lcitool: Execute the CLI from within the __main__.py module
Now that we're fully compliant with using pyproject.toml for the build
backend, we can simplify the script's logic to a mere import, similarly
to what Python would do if the lcitool package was actually installed.
This patch includes one important change which could not have been
performed before switching to pyproject.toml from setup.py - it always
overrides PYTHONPATH because our bin/lcitool is no longer being
installed along with the package, because the build backends relying
pyproject.toml as build input generate an implicit bin/lcitool script
wrapping whatever API entrypoint we specified in the package
installation location.
Signed-off-by: Erik Skultety <eskultet@redhat.com>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/lcitool | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/bin/lcitool b/bin/lcitool index 44673db..600715d 100755 --- a/bin/lcitool +++ b/bin/lcitool @@ -6,7 +6,6 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import logging import sys from pathlib import Path @@ -14,41 +13,8 @@ from pathlib import Path # This hack is to add lcitool/ to PYTHONPATH. It allows execution of # lcitool without prior package installation using pip. root = Path(__file__).parent.parent -lib = Path(root, "lcitool") +sys.path.insert(0, root.as_posix()) -if lib.exists(): - sys.path.insert(0, root.as_posix()) +from lcitool.__main__ import main -from lcitool.application import Application -from lcitool.commandline import CommandLine -from lcitool.logger import LevelFormatter - -class LcitoolLogger(logging.Logger): - def debug(self, *args, **kwargs): - super().debug(*args, **kwargs, exc_info=True) - -if __name__ == "__main__": - log_level_formats = { - logging.DEBUG: "[%(levelname)s] %(module)s:%(funcName)s:%(lineno)d: %(message)s", - logging.ERROR: "[%(levelname)s]: %(message)s", - } - - logging.setLoggerClass(LcitoolLogger) - - custom_formatter = LevelFormatter(log_level_formats) - custom_handler = logging.StreamHandler(stream=sys.stderr) - custom_handler.setFormatter(custom_formatter) - - log = logging.getLogger() - log.addHandler(custom_handler) - - args = CommandLine().parse() - - if args.debug: - log.setLevel(logging.DEBUG) - - try: - Application().run(args) - except Exception: - log.exception("An unexpected error occurred") - sys.exit(1) +main() |