Skip to content

Fix dependency_order bug #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions stub_uploader/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand Down