def test_flatten(self): def yielding(): yield 1 yield (2, "3") cases = [ ([], []), ((1, "2"), [1, "2"]), (yielding(), [1, 2, "3"]), ((1, ["2", [], 3]), [1, "2", 3]), ] for val, expected in cases: result = list(iterutil.flatten(val)) assert result == expected
def install_tools(dependencies): """ Install a required tool before using it, if it's missing. Note that C{dependencies} can be a distutils requirement, or a simple name from the C{tools} task configuration, or a (nested) list of such requirements. """ tools = getattr(easy.options, "tools", {}) for dependency in iterutil.flatten(dependencies): dependency = tools.get(dependency, dependency) try: pkg_resources.require(dependency) except pkg_resources.DistributionNotFound: vsh("pip", "install", "-q", dependency) dependency = pkg_resources.require(dependency) easy.info("Installed required tool %s" % (dependency, ))
def install_tools(dependencies): """ Install a required tool before using it, if it's missing. Note that C{dependencies} can be a distutils requirement, or a simple name from the C{tools} task configuration, or a (nested) list of such requirements. """ tools = getattr(easy.options, "tools", {}) for dependency in iterutil.flatten(dependencies): dependency = tools.get(dependency, dependency) try: pkg_resources.require(dependency) except pkg_resources.DistributionNotFound: vsh("pip", "install", "-q", dependency) dependency = pkg_resources.require(dependency) easy.info("Installed required tool %s" % (dependency,))
def test_iterutil_flatten(val, expected): result = list(iterutil.flatten(val)) assert result == expected