in src/package_report.py [0:0]
def _get_package_versions_in_upstream(target_packages_match_spec_out, target_version) -> dict[str, str]:
package_to_version_mapping = {}
is_major_version_release = target_version.minor == 0 and target_version.patch == 0
is_minor_version_release = target_version.patch == 0 and not is_major_version_release
for package in target_packages_match_spec_out:
# Execute a conda search api call in the linux-64 subdirectory
# packages such as pytorch-gpu are present only in linux-64 sub directory
match_spec_out = target_packages_match_spec_out[package]
package_version = str(match_spec_out.get("version")).removeprefix("==")
package_version = get_semver(package_version)
channel = match_spec_out.get("channel").channel_name
subdir_filter = "[subdir=" + match_spec_out.get("subdir") + "]"
search_result = conda.cli.python_api.run_command(
"search", channel + "::" + package + ">=" + str(package_version) + subdir_filter, "--json"
)
# Load the first result as json. The API sends a json string inside an array
package_metadata = json.loads(search_result[0])[package]
# Response is of the structure
# { 'package_name': [{'url':<someurl>, 'dependencies': <List of dependencies>, 'version':
# <version number>}, ..., {'url':<someurl>, 'dependencies': <List of dependencies>, 'version':
# <version number>}]
# We only care about the version number in the last index
package_version_in_conda = ""
if is_major_version_release:
latest_package_version_in_conda = package_metadata[-1]["version"]
elif is_minor_version_release:
package_major_version_prefix = str(package_version.major) + "."
latest_package_version_in_conda = [
x["version"] for x in package_metadata if x["version"].startswith(package_major_version_prefix)
][-1]
else:
package_minor_version_prefix = ".".join([str(package_version.major), str(package_version.minor)])
latest_package_version_in_conda = [
x["version"] for x in package_metadata if x["version"].startswith(package_minor_version_prefix)
][-1]
package_to_version_mapping[package] = latest_package_version_in_conda
return package_to_version_mapping