diff --git a/stub_uploader/metadata.py b/stub_uploader/metadata.py index 723e0059..859dbf35 100644 --- a/stub_uploader/metadata.py +++ b/stub_uploader/metadata.py @@ -4,7 +4,7 @@ import graphlib import os import re -from collections.abc import Iterator +from collections.abc import Iterator, Iterable from typing import Any, Optional import requests @@ -217,7 +217,9 @@ def verify_external_req( ) -def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[str]: +def sort_by_dependency( + typeshed_dir: str, distributions: Iterable[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,8 +239,13 @@ def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[ ) dist_map[metadata.stub_distribution] = dist - ordered = [dist_map[stub_dist] for stub_dist in ts.static_order()] - missing = set(distributions) - set(ordered) + # ts.static_order may contain external dependencies, so we filter them out + ordered = [ + dist_map[stub_dist] for stub_dist in ts.static_order() if stub_dist in dist_map + ] + + distributions = set(distributions) + missing = distributions - set(ordered) assert not missing, f"Failed to find distributions {missing}" for dist in ordered: diff --git a/tests/test_integration.py b/tests/test_integration.py index 025c4cbe..397e1d51 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -132,6 +132,14 @@ def test_recursive_verify_single() -> None: assert recursive_verify(m, TYPESHED) == {"types-tzlocal", "types-pytz"} +def test_dependency_order_single() -> None: + assert list(sort_by_dependency(TYPESHED, ["tzlocal"])) == ["tzlocal"] + assert list(sort_by_dependency(TYPESHED, ["tzlocal", "pytz"])) == [ + "pytz", + "tzlocal", + ] + + @pytest.mark.parametrize( "distribution", os.listdir(os.path.join(TYPESHED, THIRD_PARTY_NAMESPACE)) )