Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions utt/__main__.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down
17 changes: 0 additions & 17 deletions utt/check_python_version.py

This file was deleted.

37 changes: 0 additions & 37 deletions utt/main.py

This file was deleted.