Exemple #1
0
 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
Exemple #2
0
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, ))
Exemple #3
0
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,))
Exemple #4
0
def test_iterutil_flatten(val, expected):
    result = list(iterutil.flatten(val))
    assert result == expected