def get_latest_version(data):
"""
Return the version string of what we think is the latest version.
In the data blob from PyPI there is the info->version key which
is just the latest in time. Ideally we want the latest non-pre-release.
"""
if not data.get('releases'):
# If there were no releases, fall back to the old way of doing
# things with the info->version key.
# This feels kinda strange but it has worked for years
return data['info']['version']
all_versions = []
for version in data['releases']:
v = parse(version)
if not v.is_prerelease:
all_versions.append((v, version))
all_versions.sort(reverse=True)
# return the highest non-pre-release version
return str(all_versions[0][1])
评论列表
文章目录