def parse_requirements(file_):
    "Parse a requirements formatted file.\n\n    Traverse a string until a delimiter is detected, then split at said\n    delimiter, get module name by element index, create a dict consisting of\n    module:version, and add dict to list of parsed modules.\n\n    Args:\n        file_: File to parse.\n\n    Raises:\n        OSerror: If there's any issues accessing the file.\n\n    Returns:\n        tuple: The contents of the file, excluding comments.\n    "
    modules = []
    delim = ['<', '>', '=', '!', '~']
    try:
        f = open_func(file_, 'r')
    except OSError:
        logging.error('Failed on file: {}'.format(file_))
        raise
    else:
        data = [x.strip() for x in f.readlines() if (x != '\n')]
    finally:
        f.close()
    data = [x for x in data if x[0].isalpha()]
    for x in data:
        if (not any([(y in x) for y in delim])):
            modules.append({'name': x, 'version': None})
        for y in x:
            if (y in delim):
                module = x.split(y)
                module_name = module[0]
                module_version = module[(- 1)].replace('=', '')
                module = {'name': module_name, 'version': module_version}
                if (module not in modules):
                    modules.append(module)
                break
    return modules
Parse a requirements formatted file.

Traverse a string until a delimiter is detected, then split at said
delimiter, get module name by element index, create a dict consisting of
module:version, and add dict to list of parsed modules.

Args:
    file_: File to parse.

Raises:
    OSerror: If there's any issues accessing the file.

Returns:
    tuple: The contents of the file, excluding comments.
def parse_requirements(file_):
    "Parse a requirements formatted file.\n\n    Traverse a string until a delimiter is detected, then split at said\n    delimiter, get module name by element index, create a dict consisting of\n    module:version, and add dict to list of parsed modules.\n\n    Args:\n        file_: File to parse.\n\n    Raises:\n        OSerror: If there's any issues accessing the file.\n\n    Returns:\n        tuple: The contents of the file, excluding comments.\n    "
    modules = []
    delim = ['<', '>', '=', '!', '~']
    try:
        f = open_func(file_, 'r')
    except OSError:
        logging.error('Failed on file: {}'.format(file_))
        raise
    else:
        data = [x.strip() for x in f.readlines() if (x != '\n')]
    finally:
        f.close()
    data = [x for x in data if x[0].isalpha()]
    for x in data:
        if (not any([(y in x) for y in delim])):
            modules.append({'name': x, 'version': None})
        for y in x:
            if (y in delim):
                module = x.split(y)
                module_name = module[0]
                module_version = module[(- 1)].replace('=', )
                module = {'name': module_name, 'version': module_version}
                if (module not in modules):
                    modules.append(module)
                break
    return modules