def _find_best_match_link(finder: PackageFinder, req: Requirement, files: list[FileHash]) -> Link | None:
    """Get the best matching link for a requirement"""

    # This function is called when a lock file candidate is given or incompatible wheel
    # In this case, the requirement must be pinned, so no need to pass allow_prereleases
    # If links are not empty, find the best match from the links, otherwise find from
    # the package sources.
    from unearth import Link

    links = [Link(f["url"]) for f in files if "url" in f]
    hashes = convert_hashes(files)

    if not links:
        best = finder.find_best_match(req.as_line(), hashes=hashes).best
    else:
        # this branch won't be executed twice if ignore_compatibility is True
        evaluator = finder.build_evaluator(req.name)
        packages = finder._evaluate_links(links, evaluator)
        best = max(packages, key=finder._sort_key, default=None)
    return best.link if best is not None else None
Get the best matching link for a requirement
src/pdm/models/candidates.py