import re


def tox_split_envlist(string):
    """Split envlist config string into list of strings.

    This function will respect generative environments.

    >>> tox_split_envlist('py{36,37},doctest,flake8')
    ['py{36,37}', 'doctest', 'flake8']

    """
    escaped = string
    while re.search(r"({[^,}]*),", escaped):
        escaped = re.subn(r"({[^,}]*),", r"\1:", escaped)[0]
    parts = escaped.split(",")
    return [re.subn(r":", ",", p)[0].strip() for p in parts]