Skip to content

Commit 1b91343

Browse files
authored
Fix dependency_order bug (#83)
1 parent 6a36fb2 commit 1b91343

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

stub_uploader/metadata.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import graphlib
55
import os
66
import re
7-
from collections.abc import Iterator
7+
from collections.abc import Iterator, Iterable
88
from typing import Any, Optional
99

1010
import requests
@@ -217,7 +217,9 @@ def verify_external_req(
217217
)
218218

219219

220-
def sort_by_dependency(typeshed_dir: str, distributions: list[str]) -> Iterator[str]:
220+
def sort_by_dependency(
221+
typeshed_dir: str, distributions: Iterable[str]
222+
) -> Iterator[str]:
221223
# Just a simple topological sort. Unlike previous versions of the code, we do not rely
222224
# on this to perform validation, like requiring the graph to be complete.
223225
# 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[
237239
)
238240
dist_map[metadata.stub_distribution] = dist
239241

240-
ordered = [dist_map[stub_dist] for stub_dist in ts.static_order()]
241-
missing = set(distributions) - set(ordered)
242+
# ts.static_order may contain external dependencies, so we filter them out
243+
ordered = [
244+
dist_map[stub_dist] for stub_dist in ts.static_order() if stub_dist in dist_map
245+
]
246+
247+
distributions = set(distributions)
248+
missing = distributions - set(ordered)
242249
assert not missing, f"Failed to find distributions {missing}"
243250

244251
for dist in ordered:

tests/test_integration.py

+8
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ def test_recursive_verify_single() -> None:
132132
assert recursive_verify(m, TYPESHED) == {"types-tzlocal", "types-pytz"}
133133

134134

135+
def test_dependency_order_single() -> None:
136+
assert list(sort_by_dependency(TYPESHED, ["tzlocal"])) == ["tzlocal"]
137+
assert list(sort_by_dependency(TYPESHED, ["tzlocal", "pytz"])) == [
138+
"pytz",
139+
"tzlocal",
140+
]
141+
142+
135143
@pytest.mark.parametrize(
136144
"distribution", os.listdir(os.path.join(TYPESHED, THIRD_PARTY_NAMESPACE))
137145
)

0 commit comments

Comments
 (0)