2
0
Fork 0
mirror of https://github.com/rust-lang/rust-clippy synced 2024-12-19 17:44:21 +00:00
rust-clippy/util/versions.py
Philipp Krones 445f428a65
Fix version.py after deleting v* dirs
I missed updating this file.

I also ran black and isort over it.
2023-06-17 10:05:06 +02:00

51 lines
1 KiB
Python
Executable file

#!/usr/bin/env python
import json
import logging as log
import os
import sys
log.basicConfig(level=log.INFO, format="%(levelname)s: %(message)s")
def key(v):
if v == "master":
return float("inf")
if v == "stable":
return sys.maxsize
if v == "beta":
return sys.maxsize - 1
if v == "pre-1.29.0":
return -1
v = v.replace("rust-", "")
s = 0
for i, val in enumerate(v.split(".")[::-1]):
s += int(val) * 100**i
return s
def main():
if len(sys.argv) < 2:
log.error("specify output directory")
return
outdir = sys.argv[1]
versions = [
dir
for dir in os.listdir(outdir)
if not dir.startswith(".")
and not dir.startswith("v")
and os.path.isdir(os.path.join(outdir, dir))
]
versions.sort(key=key)
with open(os.path.join(outdir, "versions.json"), "w") as fp:
json.dump(versions, fp, indent=2)
log.info("wrote JSON for great justice")
if __name__ == "__main__":
main()