Skip pre-release versions when looking for the lastest

Fixes #57.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-07-05 15:44:52 +02:00
parent 4436a110cf
commit 628fb7c494

View file

@ -150,14 +150,27 @@ def local_crate(crate, version):
cratename, version = os.path.basename(crate)[:-6].rsplit("-", 1)
return crate, cratename, version
def download(crate, version):
if version is None:
# Now we need to get latest version
def query_newest_version(crate):
url = requests.compat.urljoin(API_URL, f"crates/{crate}/versions")
req = requests.get(url, headers={"User-Agent": "rust2rpm"})
req.raise_for_status()
versions = req.json()["versions"]
version = next(version["num"] for version in versions if not version["yanked"])
for struct in versions:
version = struct["num"]
if struct["yanked"]:
print(f'Ignoring yanked version {version}')
elif re.search('alpha|beta|rc|pre', version):
print(f'Ignoring pre-release version {version}')
else:
print(f'Found version {version}')
return version
raise ValueError("Couldn't find any release versions. Specify a version explicitly.")
def download(crate, version):
if version is None:
# Now we need to get latest version
version = query_newest_version(crate)
os.makedirs(CACHEDIR, exist_ok=True)
cratef_base = f"{crate}-{version}.crate"