(packages, licenses_db)
return filtered_packages_licenses
Get the licenses for the specified packages based on their version. 

    :param packages: packages list
    :param licenses_db: the licenses db in the raw form.
    :return: list of objects with the packages and their respectives licenses.
Get the licenses for the specified packages based on their version.
Get the licenses for the specified packages based on their version .
def get_packages_licenses(packages, licenses_db):
    """Get the licenses for the specified packages based on their version. 

    :param packages: packages list
    :param licenses_db: the licenses db in the raw form.
    :return: list of objects with the packages and their respectives licenses.
    """
    packages_licenses_db = licenses_db.get('packages', {})
    filtered_packages_licenses = []

    for pkg in packages:
        # Ignore recursive files not resolved
        if isinstance(pkg, RequirementFile):
            continue
        # normalize the package name
        pkg_name = pkg.key.replace("_", "-").lower()
        # packages may have different licenses depending their version.
        pkg_licenses = packages_licenses_db.get(pkg_name, [])
        version_requested = parse_version(pkg.version)
        license_id = None
        license_name = None
        for pkg_version in pkg_licenses:
            license_start_version = parse_version(pkg_version['start_version'])
            # Stops and return the previous stored license when a new
            # license starts on a version above the requested one.
            if version_requested >= license_start_version:
                license_id = pkg_version['license_id']
            else:
                # We found the license for the version requested
                break

        if license_id:
            license_name = get_license_name_by_id(license_id, licenses_db)
        if not license_id or not license_name:
            license_name = "N/A"

        filtered_packages_licenses.append({
            "package": pkg_name,
            "version": pkg.version,
            "license": license_name
        })

    return filtered_packages_licenses
def get_packages_licenses ( packages , licenses_db ) : packages_licenses_db = licenses_db . get ( 'packages' , { } ) filtered_packages_licenses = [ ] for pkg in packages : # Ignore recursive files not resolved if isinstance ( pkg , RequirementFile ) : continue # normalize the package name pkg_name = pkg . key . replace ( "_" , "-" ) . lower ( ) # packages may have different licenses depending their version. pkg_licenses = packages_licenses_db . get ( pkg_name , [ ] ) version_requested = parse_version ( pkg . version ) license_id = None license_name = None for pkg_version in pkg_licenses : license_start_version = parse_version ( pkg_version [ 'start_version' ] ) # Stops and return the previous stored license when a new # license starts on a version above the requested one. if version_requested >= license_start_version : license_id = pkg_version [ 'license_id' ] else : # We found the license for the version requested break if license_id : license_name = get_license_name_by_id ( license_id , licenses_db ) if not license_id or not license_name : license_name = "N/A" filtered_packages_licenses . append ( { "package" : pkg_name , "version" : pkg . version , "license" : license_name } ) return filtered_packages_licenses