def discover(glob_pattern):
    """
    Find all files matching given glob_pattern,
    parse them, and return list of environments:

    >>> envs = discover("requirements/*.in")
    >>> # print(envs)
    >>> envs == [
    ...     {'name': 'base', 'refs': set()},
    ...     {'name': 'py27', 'refs': set()},
    ...     {'name': 'test', 'refs': {'base'}},
    ...     {'name': 'local', 'refs': {'test'}},
    ...     {'name': 'local27', 'refs': {'test', 'py27'}},
    ...     {'name': 'testwin', 'refs': {'test'}},
    ... ]
    True
    """
    in_paths = glob.glob(glob_pattern)
    names = {
        extract_env_name(path): path
        for path in in_paths
    }
    return order_by_refs([
        {'name': name, 'refs': Environment.parse_references(in_path)}
        for name, in_path in names.items()
    ])
Find all files matching given glob_pattern,
    parse them, and return list of environments:

    >>> envs = discover("requirements/*.in")
    >>> # print(envs)
    >>> envs == [
    ...     {'name': 'base', 'refs': set()},
    ...     {'name': 'py27', 'refs': set()},
    ...     {'name': 'test', 'refs': {'base'}},
    ...     {'name': 'local', 'refs': {'test'}},
    ...     {'name': 'local27', 'refs': {'test', 'py27'}},
    ...     {'name': 'testwin', 'refs': {'test'}},
    ... ]
    True