def parse_req_file(req_file, verbatim=False):
    """Take a file and return a dict of (requirement, versions, ignore) based
    on the files requirements specs.
    """
    req_list = []
    requirements = req_file.readlines()
    for requirement in requirements:
        requirement_no_comments = requirement.split('#')[0].strip()

        # if matching requirement line (Thing==1.2.3), update dict, continue
        req_match = re.match(
            r'\s*(?P<package>[^\s\[\]]+)(?P<extras>\[\S+\])?==(?P<version>\S+)',
            requirement_no_comments
        )
        req_ignore = requirement.strip().endswith('  # norot')

        if req_match:
            req_list.append((req_match.group('package'),
                             req_match.group('version'),
                             req_ignore))
        elif requirement_no_comments.startswith('-r'):
            try:
                base_dir = os.path.dirname(os.path.abspath(req_file.name))
            except AttributeError:
                print(
                    'Recursive requirements are not supported in URL based '
                    'lookups'
                )
                continue

            # replace the -r and ensure there are no leading spaces
            file_name = requirement_no_comments.replace('-r', '').strip()
            new_path = os.path.join(base_dir, file_name)
            try:
                if verbatim:
                    req_list.append((None, requirement, req_ignore))
                req_list.extend(
                    parse_req_file(
                        open(new_path),
                        verbatim=verbatim
                    )
                )
            except IOError:
                print('Failed to import {}'.format(file_name))
        elif verbatim:
            req_list.append((None, requirement, req_ignore))
    return req_list
Take a file and return a dict of (requirement, versions, ignore) based
    on the files requirements specs.