Mark stdlib modules with upper version bounds (#5394)

* Mark stdlib modules with upper version bounds

* Add minus to all versions and enforce in check_consistent

* Fix check_consistent and mypy_test to work with new VERSIONS format
This commit is contained in:
Sebastian Rittau
2021-05-10 15:29:43 +02:00
committed by GitHub
parent 5e907afac7
commit 1eb64b4372
9 changed files with 636 additions and 613 deletions

View File

@@ -71,6 +71,9 @@ def match(fn, args, exclude_list):
return True
_VERSION_LINE_RE = re.compile(r"^([a-zA-Z_][a-zA-Z0-9_]*): ([23]\.\d{1,2})-([23]\.\d{1,2})?$")
def parse_versions(fname):
with open(fname) as f:
data = f.read().splitlines()
@@ -79,13 +82,24 @@ def parse_versions(fname):
# Allow having some comments or empty lines.
if not line.strip() or line.startswith("#"):
continue
mod, ver_str = line.split(": ")
assert ver_str.count(".") == 1
major, minor = ver_str.split(".")
result[mod] = (int(major), int(minor))
m = _VERSION_LINE_RE.match(line)
assert m, "invalid VERSIONS line :" + line
mod = m.group(1)
min_version = parse_version(m.group(2))
max_version = parse_version(m.group(3)) if m.group(3) else (99, 99)
result[mod] = min_version, max_version
return result
_VERSION_RE = re.compile(r"^([23])\.(\d+)$")
def parse_version(v_str):
m = _VERSION_RE.match(v_str)
assert m, "invalid version :" + v_str
return int(m.group(1)), int(m.group(2))
def is_supported(distribution, major):
with open(os.path.join(THIRD_PARTY_NAMESPACE, distribution, "METADATA.toml")) as f:
data = dict(toml.loads(f.read()))
@@ -202,9 +216,8 @@ def main():
if name == PY2_NAMESPACE or name == "VERSIONS":
continue
mod, _ = os.path.splitext(name)
if supported_versions[mod] > (major, minor):
continue
add_files(files, seen, root, name, args, exclude_list)
if supported_versions[mod][0] <= (major, minor) <= supported_versions[mod][1]:
add_files(files, seen, root, name, args, exclude_list)
# Next add files for all third party distributions.
for distribution in os.listdir(THIRD_PARTY_NAMESPACE):