def command_factory(name, base_class, wrapper_method):
    """Factory method to create a distutils or setuptools command with a patched `run` method."""
    return type(str(name), (base_class, object), {'run': wrapper_method})