From 7deb240118268ec2b04791b637827872a0ff46bd Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 14 Dec 2022 12:08:06 +0100 Subject: [PATCH 1/3] Fix sort_by_dependency to work with non-standard dist names --- stub_uploader/metadata.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/stub_uploader/metadata.py b/stub_uploader/metadata.py index 78884298..7473e4a1 100644 --- a/stub_uploader/metadata.py +++ b/stub_uploader/metadata.py @@ -217,13 +217,14 @@ def verify_external_req( ) -def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[str]: +def sort_by_dependency(typeshed_dir: str, dist_dirs: list[str]) -> Iterator[str]: # Just a simple topological sort. Unlike previous versions of the code, we do not rely # on this to perform validation, like requiring the graph to be complete. # We only use this to help with edge cases like multiple packages being uploaded # for the first time that depend on each other. ts: graphlib.TopologicalSorter[str] = graphlib.TopologicalSorter() + dist_map: dict[str, str] = {} # maps type distribution name to directory name for dist in os.listdir(os.path.join(typeshed_dir, THIRD_PARTY_NAMESPACE)): metadata = read_metadata(typeshed_dir, dist) ts.add( @@ -234,13 +235,14 @@ def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[ # upload B. *[r.name for r in metadata._unvalidated_requires], ) + dist_map[metadata.stub_distribution] = dist - order = [strip_types_prefix(dist) for dist in ts.static_order()] - missing = set(distributions) - set(order) + ordered_dirs = [dist_map[dist] for dist in ts.static_order()] + missing = set(dist_dirs) - set(ordered_dirs) assert not missing, f"Failed to find distributions {missing}" - for dist in order: - if dist in distributions: + for dist in ordered_dirs: + if dist in dist_dirs: yield dist From 33e9c2fe04b3d638ec2625b2d0a08b9a984d6ed5 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 14 Dec 2022 12:13:38 +0100 Subject: [PATCH 2/3] Rename some variables --- stub_uploader/metadata.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stub_uploader/metadata.py b/stub_uploader/metadata.py index 7473e4a1..aad6db0c 100644 --- a/stub_uploader/metadata.py +++ b/stub_uploader/metadata.py @@ -217,7 +217,7 @@ def verify_external_req( ) -def sort_by_dependency(typeshed_dir: str, dist_dirs: list[str]) -> Iterator[str]: +def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[str]: # Just a simple topological sort. Unlike previous versions of the code, we do not rely # on this to perform validation, like requiring the graph to be complete. # We only use this to help with edge cases like multiple packages being uploaded @@ -237,12 +237,12 @@ def sort_by_dependency(typeshed_dir: str, dist_dirs: list[str]) -> Iterator[str] ) dist_map[metadata.stub_distribution] = dist - ordered_dirs = [dist_map[dist] for dist in ts.static_order()] - missing = set(dist_dirs) - set(ordered_dirs) + ordered = [dist_map[stub_dist] for stub_dist in ts.static_order()] + missing = set(distributions) - set(ordered) assert not missing, f"Failed to find distributions {missing}" - for dist in ordered_dirs: - if dist in dist_dirs: + for dist in ordered: + if dist in distributions: yield dist From f3167200909d6c3615039cfb0e583abb8f60b7a5 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 14 Dec 2022 12:14:24 +0100 Subject: [PATCH 3/3] type -> stub in comment --- stub_uploader/metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stub_uploader/metadata.py b/stub_uploader/metadata.py index aad6db0c..723e0059 100644 --- a/stub_uploader/metadata.py +++ b/stub_uploader/metadata.py @@ -224,7 +224,7 @@ def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[ # for the first time that depend on each other. ts: graphlib.TopologicalSorter[str] = graphlib.TopologicalSorter() - dist_map: dict[str, str] = {} # maps type distribution name to directory name + dist_map: dict[str, str] = {} # maps stub distribution name to directory name for dist in os.listdir(os.path.join(typeshed_dir, THIRD_PARTY_NAMESPACE)): metadata = read_metadata(typeshed_dir, dist) ts.add(