示例#1
0
    def infos(self, exists=True):
        """
        get VenvInfo instances generator.

        Usage
        -----

        ::

            for venv_info in venvs.infos():
                pass

        :param exists: the virtualenv must exist to be included in the generator
        :type exists: bool
        """
        if not self.in_virtualenv and not self.defined:
            raise NoAvailableVirtualenv()
        value = self._ver_attr
        if not is_sequence(value):
            value = [value]
        try:
            for ver in value:
                venv_info = VenvInfo(ver)
                if exists:
                    if venv_info.exists():
                        yield venv_info
                else:
                    yield venv_info
        except Exception as ex:
            error(str(ex))
def test_is_sequence():
    """does the given object behave like a list but is not a string?"""

    # non-list-like objects
    assert not is_sequence(None)
    assert not is_sequence(1)
    assert not is_sequence('')
    assert not is_sequence('foo')

    # list-like objects

    # lists
    assert is_sequence([])
    assert is_sequence([1])
    assert is_sequence([1, 2])
    # tuples
    assert is_sequence(())
    assert is_sequence((1,))
    assert is_sequence((1, 2))
示例#3
0
    def _variable_substitution(self, raw_lines):
        lines = []
        for line in raw_lines:

            match = re.search(r'\[([^\]]+)]', line)
            if match:
                value = getattr(self._project, match.group(1), match.group(0))
                if not is_sequence(value):
                    value = [value]
                new_lines = []

                line = re.sub(r"python_version\s*==\s*", r"python_version in ", line)
                line = re.sub(r'\[([^\]]+)]', ' '.join([self._project.ver_to_version(v) for v in value]), line)
                new_lines.append(line)
            else:
                new_lines = [line]

            lines.extend(new_lines)

        return lines