def METHOD_NAME(self, versions, spec=None, custom_system=None):
    assert not spec or isinstance(spec, PackageSpec)
    result = []
    for version in versions:
        semver = cast_version_to_semver(version["name"])
        if spec and spec.requirements and semver not in spec.requirements:
            continue
        if not any(
            self.is_system_compatible(f.get("system"), custom_system=custom_system)
            for f in version["files"]
        ):
            continue
        result.append(version)
    return result