|
|
@ -10,16 +10,20 @@ __metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
import inspect
|
|
|
|
import os.path
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
import pkgutil
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import typing as t
|
|
|
|
from straight.plugin import load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
import argcomplete
|
|
|
|
import argcomplete
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
argcomplete = None
|
|
|
|
argcomplete = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C = t.TypeVar('C')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_lib_path(this_script=__file__):
|
|
|
|
def build_lib_path(this_script=__file__):
|
|
|
|
"""Return path to the common build library directory."""
|
|
|
|
"""Return path to the common build library directory."""
|
|
|
@ -55,6 +59,27 @@ def create_arg_parser(program_name):
|
|
|
|
return parser
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load(package: str, subclasses: t.Type[C]) -> list[t.Type[C]]:
|
|
|
|
|
|
|
|
"""Load modules in the specified package and return concrete types that derive from the specified base class."""
|
|
|
|
|
|
|
|
for module in pkgutil.iter_modules(importlib.import_module(package).__path__, f'{package}.'):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
importlib.import_module(module.name)
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
pass # ignore plugins which are missing dependencies
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
types: set[t.Type[C]] = set()
|
|
|
|
|
|
|
|
queue: list[t.Type[C]] = [subclasses]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while queue:
|
|
|
|
|
|
|
|
for child in queue.pop().__subclasses__():
|
|
|
|
|
|
|
|
queue.append(child)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not inspect.isabstract(child):
|
|
|
|
|
|
|
|
types.add(child)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sorted(types, key=lambda sc: sc.__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Start our run.
|
|
|
|
Start our run.
|
|
|
@ -69,7 +94,9 @@ def main():
|
|
|
|
help='Show tracebacks and other debugging information')
|
|
|
|
help='Show tracebacks and other debugging information')
|
|
|
|
subparsers = arg_parser.add_subparsers(title='Subcommands', dest='command',
|
|
|
|
subparsers = arg_parser.add_subparsers(title='Subcommands', dest='command',
|
|
|
|
help='for help use build-ansible.py SUBCOMMANDS -h')
|
|
|
|
help='for help use build-ansible.py SUBCOMMANDS -h')
|
|
|
|
subcommands.pipe('init_parser', subparsers.add_parser)
|
|
|
|
|
|
|
|
|
|
|
|
for subcommand in subcommands:
|
|
|
|
|
|
|
|
subcommand.init_parser(subparsers.add_parser)
|
|
|
|
|
|
|
|
|
|
|
|
if argcomplete:
|
|
|
|
if argcomplete:
|
|
|
|
argcomplete.autocomplete(arg_parser)
|
|
|
|
argcomplete.autocomplete(arg_parser)
|
|
|
|