Repository navigation
Expand file tree
/
Copy pathget_versions.py
More file actions
83 lines (66 loc) · 2.46 KB
/
Copy pathget_versions.py
File metadata and controls
83 lines (66 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Get the pyrefly versions from PyPI that still need to be mirrored.
Usage:
python get_versions.py [version ...]
With no arguments, outputs every non-yanked PyPI release at or above
MIN_VERSION that has no matching git tag in this repository. Releases from all
tracks (stable and dev) are included, so a stable release published alongside
a newer dev release is not skipped.
With arguments, outputs exactly those versions after checking that each one
exists on PyPI and is not already tagged. Use this to re-release versions that
were missed.
Output:
Space-separated list of versions, sorted in ascending order.
"""
import json
import subprocess
import sys
import urllib.request
from packaging import version
# Releases older than this are never auto-detected, so that we don't backfill
# versions that predate this mirror. Older versions can still be mirrored by
# passing them explicitly.
MIN_VERSION = version.parse('1.3.2')
def get_pypi_versions():
"""Return the non-yanked versions of pyrefly published on PyPI."""
with urllib.request.urlopen('https://pypi.org/pypi/pyrefly/json') as response:
data = json.load(response)
return {
v for v, files in data['releases'].items()
if files and not all(f.get('yanked', False) for f in files)
}
def get_tags():
"""Return the set of git tags in this repository."""
result = subprocess.run(
['git', 'tag', '--list'], check=True, capture_output=True, text=True
)
return set(result.stdout.split())
def main():
requested = sys.argv[1:]
pypi_versions = get_pypi_versions()
tags = get_tags()
if requested:
errors = []
for v in requested:
if v not in pypi_versions:
errors.append(f'{v} is not a (non-yanked) pyrefly release on PyPI')
elif v in tags:
errors.append(f'{v} is already tagged')
if errors:
for error in errors:
print(f'Error: {error}', file=sys.stderr)
sys.exit(1)
versions = set(requested)
else:
versions = {
v for v in pypi_versions
if v not in tags and version.parse(v) >= MIN_VERSION
}
print(' '.join(sorted(versions, key=version.parse)))
if __name__ == '__main__':
main()