import importlib


def get_machine_factory(module_name, machine_class,
                        machine_package='ats.atsMachines'):
    """
    Get factory of type "machine_class" found in "module_name".

    Programmatically import and return definition of machine_class from
    module_name. "machine_package" tells Python where module_name can be found if
    not in the project's root directory.
    """
    machine_module = importlib.import_module(f'.{module_name}',
                                             package=machine_package)
    machine_factory = getattr(machine_module, machine_class)
    return machine_factory