From dde14adef2a230489a06e118ac745af9ee3fabc0 Mon Sep 17 00:00:00 2001 From: Mathieu Larose Date: Sun, 2 Nov 2025 13:33:39 -0500 Subject: [PATCH] Remove Python version check warning --- utt/__main__.py | 36 ++++++++++++++++++++++++++++++++---- utt/check_python_version.py | 17 ----------------- utt/main.py | 37 ------------------------------------- 3 files changed, 32 insertions(+), 58 deletions(-) delete mode 100644 utt/check_python_version.py delete mode 100644 utt/main.py diff --git a/utt/__main__.py b/utt/__main__.py index 8eee4a0..24b064b 100644 --- a/utt/__main__.py +++ b/utt/__main__.py @@ -1,12 +1,40 @@ -from .check_python_version import warn_if_python_version_is_unsupported +import argparse +import importlib +import pkgutil +import sys -warn_if_python_version_is_unsupported() +import utt.plugins +from utt.api import _v1 +from utt.components.commands import Commands + + +def iter_namespace(ns_pkg): + # Specifying the second argument (prefix) to iter_modules makes the + # returned name an absolute name instead of a relative one. This allows + # import_module to work without having to do additional modification to + # the name. + # + # Source: https://packaging.python.org/guides/creating-and-discovering-plugins/ + return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".") + + +def load_plugins(): + for _, name, _ in iter_namespace(utt.plugins): + importlib.import_module(name) def main(): - from utt.main import main + if len(sys.argv) == 1: + sys.argv.append("--help") - main() + load_plugins() + + command_name = _v1._private.container[argparse.Namespace].command + + commands: Commands = _v1._private.container[Commands] + for command in commands: + if command.name == command_name: + _v1._private.container[command.handler_class]() if __name__ == "__main__": diff --git a/utt/check_python_version.py b/utt/check_python_version.py deleted file mode 100644 index c4a4281..0000000 --- a/utt/check_python_version.py +++ /dev/null @@ -1,17 +0,0 @@ -import sys - -MIN_PYTHON_VERSION = (3, 7) - - -def python_version_is_supported(): - python_version = (sys.version_info.major, sys.version_info.minor) - - return python_version >= MIN_PYTHON_VERSION - - -def warn_if_python_version_is_unsupported(): - if python_version_is_supported(): - return - - print("Warning: utt requires Python version 3.7 or above.", file=sys.stderr) - print(file=sys.stderr) diff --git a/utt/main.py b/utt/main.py deleted file mode 100644 index aa5e305..0000000 --- a/utt/main.py +++ /dev/null @@ -1,37 +0,0 @@ -import argparse -import importlib -import pkgutil -import sys - -import utt.plugins -from utt.api import _v1 -from utt.components.commands import Commands - - -def iter_namespace(ns_pkg): - # Specifying the second argument (prefix) to iter_modules makes the - # returned name an absolute name instead of a relative one. This allows - # import_module to work without having to do additional modification to - # the name. - # - # Source: https://packaging.python.org/guides/creating-and-discovering-plugins/ - return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".") - - -def load_plugins(): - for _, name, _ in iter_namespace(utt.plugins): - importlib.import_module(name) - - -def main(): - if len(sys.argv) == 1: - sys.argv.append("--help") - - load_plugins() - - command_name = _v1._private.container[argparse.Namespace].command - - commands: Commands = _v1._private.container[Commands] - for command in commands: - if command.name == command_name: - _v1._private.container[command.handler_class]()