fix: keep pre versions (#14752)

This commit is contained in:
Jirka Borovec 2022-09-16 20:11:00 +02:00 committed by GitHub
parent 47f0d336f1
commit d9be959bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import json
import os import os
import re import re
import shutil import shutil
from distutils.version import LooseVersion, StrictVersion from distutils.version import LooseVersion
from importlib.util import module_from_spec, spec_from_file_location from importlib.util import module_from_spec, spec_from_file_location
from itertools import chain from itertools import chain
from pathlib import Path from pathlib import Path
@ -16,6 +16,7 @@ from urllib.request import Request, urlopen
import fire import fire
import pkg_resources import pkg_resources
from packaging.version import parse as version_parse
REQUIREMENT_FILES = { REQUIREMENT_FILES = {
"pytorch": ( "pytorch": (
@ -30,15 +31,20 @@ REQUIREMENT_FILES_ALL = tuple(chain(*REQUIREMENT_FILES.values()))
PACKAGE_MAPPING = {"app": "lightning-app", "pytorch": "pytorch-lightning"} PACKAGE_MAPPING = {"app": "lightning-app", "pytorch": "pytorch-lightning"}
def pypi_versions(package_name: str) -> List[str]: def pypi_versions(package_name: str, drop_pre: bool = True) -> List[str]:
"""Return a list of released versions of a provided pypi name.""" """Return a list of released versions of a provided pypi name.
>>> _ = pypi_versions("lightning_app", drop_pre=False)
"""
# https://stackoverflow.com/a/27239645/4521646 # https://stackoverflow.com/a/27239645/4521646
url = f"https://pypi.org/pypi/{package_name}/json" url = f"https://pypi.org/pypi/{package_name}/json"
data = json.load(urlopen(Request(url))) data = json.load(urlopen(Request(url)))
versions = list(data["releases"].keys()) versions = list(data["releases"].keys())
# todo: drop this line after cleaning Pypi history from invalid versions # todo: drop this line after cleaning Pypi history from invalid versions
versions = list(filter(lambda v: v.count(".") == 2 and "rc" not in v, versions)) versions = list(filter(lambda v: v.count(".") == 2, versions))
versions.sort(key=StrictVersion) if drop_pre:
versions = list(filter(lambda v: all(c not in v for c in ["rc", "dev"]), versions))
versions.sort(key=version_parse)
return versions return versions
@ -122,7 +128,7 @@ class AssistantCLI:
url = f"https://pypi.org/pypi/{PACKAGE_MAPPING[package]}/json" url = f"https://pypi.org/pypi/{PACKAGE_MAPPING[package]}/json"
data = json.load(urlopen(Request(url))) data = json.load(urlopen(Request(url)))
if not version: if not version:
pypi_vers = pypi_versions(PACKAGE_MAPPING[package]) pypi_vers = pypi_versions(PACKAGE_MAPPING[package], drop_pre=False)
version = pypi_vers[-1] version = pypi_vers[-1]
releases = list(filter(lambda r: r["packagetype"] == "sdist", data["releases"][version])) releases = list(filter(lambda r: r["packagetype"] == "sdist", data["releases"][version]))
assert releases, f"Missing 'sdist' for this package/version aka {package}/{version}" assert releases, f"Missing 'sdist' for this package/version aka {package}/{version}"