From 61121c579ee787970daaa48769703d80babe3f03 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sat, 30 Jan 2021 16:38:11 +0000 Subject: [PATCH 1/3] More consistency checks for dependencies --- tests/check_consistent.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index e779238b440f..959b954f1bdb 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -128,7 +128,28 @@ def check_versions(): assert not extra, f"Versions not in modules: {extra}" +def _strip_dep_version(dependency): + dep_version_pos = len(dependency) + for pos, c in enumerate(dependency): + if c in "=<>": + dep_version_pos = pos + break + stripped = dependency[:dep_version_pos] + rest = dependency[dep_version_pos:] + if not rest: + return stripped, "", "" + number_pos = 0 + for pos, c in enumerate(rest): + if c not in "=<>": + number_pos = pos + break + relation = rest[:number_pos] + version = rest[number_pos:] + return stripped, relation, version + + def check_metadata(): + known_distributions = set(os.listdir("stubs")) for distribution in os.listdir("stubs"): with open(os.path.join("stubs", distribution, "METADATA.toml")) as f: data = toml.loads(f.read()) @@ -146,9 +167,19 @@ def check_metadata(): assert isinstance(data.get("python3", True), bool), f"Invalid python3 value for {distribution}" assert isinstance(data.get("requires", []), list), f"Invalid requires value for {distribution}" for dep in data.get("requires", []): - # TODO: add more validation here. assert isinstance(dep, str), f"Invalid dependency {dep} for {distribution}" assert dep.startswith("types-"), f"Only stub dependencies supported, got {dep}" + dep = dep[len("types-"):] + for space in " \t\n": + assert space not in dep, f"For consistency dependency should not have whitespace: {dep}" + stripped, relation, dep_version = _strip_dep_version(dep) + assert stripped in known_distributions, f"Only known dependencies are supported, got {stripped}" + msg = f"Bad version in dependency {dep}" + if relation: + assert relation in {"==", ">", ">=", "<", "<="}, msg + assert version.count(".") <= 2, msg + for part in version.split("."): + assert part.isnumeric(), msg if __name__ == "__main__": From 2b9435326f3303ede121daa11141f8e663a21424 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sat, 30 Jan 2021 16:39:42 +0000 Subject: [PATCH 2/3] Tweak --- tests/check_consistent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 959b954f1bdb..3f3957f8ffe6 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -174,8 +174,8 @@ def check_metadata(): assert space not in dep, f"For consistency dependency should not have whitespace: {dep}" stripped, relation, dep_version = _strip_dep_version(dep) assert stripped in known_distributions, f"Only known dependencies are supported, got {stripped}" - msg = f"Bad version in dependency {dep}" if relation: + msg = f"Bad version in dependency {dep}" assert relation in {"==", ">", ">=", "<", "<="}, msg assert version.count(".") <= 2, msg for part in version.split("."): From b458021d49aff299a5aef21a26c4e34835d6e128 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Mon, 1 Feb 2021 14:44:30 +0000 Subject: [PATCH 3/3] Adress CR --- tests/check_consistent.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 3f3957f8ffe6..15949e045aac 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -172,8 +172,9 @@ def check_metadata(): dep = dep[len("types-"):] for space in " \t\n": assert space not in dep, f"For consistency dependency should not have whitespace: {dep}" + assert ";" not in dep, f"Semicolons in dependencies are not supported, got {dep}" stripped, relation, dep_version = _strip_dep_version(dep) - assert stripped in known_distributions, f"Only known dependencies are supported, got {stripped}" + assert stripped in known_distributions, f"Only dependencies from typeshed are supported, got {stripped}" if relation: msg = f"Bad version in dependency {dep}" assert relation in {"==", ">", ">=", "<", "<="}, msg