Skip to content
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

Fix when the same python_requirement defines both type stub and implementation (Cherry-pick of #15121) #15127

Merged
merged 1 commit into from
Apr 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
from collections import defaultdict
from dataclasses import dataclass
from functools import total_ordering
from pathlib import PurePath
from typing import DefaultDict, Iterable, Mapping, Tuple

Expand Down Expand Up @@ -39,10 +40,16 @@
ResolveName = str


@total_ordering
class ModuleProviderType(enum.Enum):
TYPE_STUB = enum.auto()
IMPL = enum.auto()

def __lt__(self, other) -> bool:
if not isinstance(other, ModuleProviderType):
return NotImplemented
return self.name < other.name


@dataclass(frozen=True, order=True)
class ModuleProvider:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,29 @@ def get_owners(resolve: str | None) -> PythonModuleOwners:
Address("", target_name="dep1"),
Address("", target_name="dep2"),
)


def test_issue_15111(rule_runner: RuleRunner) -> None:
"""Ensure we can handle when a single address implement multiple modules.

This is currently only possible with third-party targets.
"""
rule_runner.write_files(
{"BUILD": "python_requirement(name='req', requirements=['docopt', 'types-docopt'])"}
)
rule_runner.set_options(["--python-enable-resolves"])
result = rule_runner.request(ThirdPartyPythonModuleMapping, [])
assert result == ThirdPartyPythonModuleMapping(
{
"python-default": FrozenDict(
{
"docopt": (
ModuleProvider(Address("", target_name="req"), ModuleProviderType.IMPL),
ModuleProvider(
Address("", target_name="req"), ModuleProviderType.TYPE_STUB
),
),
}
)
}
)