Skip to content

Commit

Permalink
Fix when the same python_requirement defines both type stub and imp…
Browse files Browse the repository at this point in the history
…lementation (#15121)

Closes #15111. This is a particular edge case when the same python module has multiple entries, and those entries come from the same target.

The better fix is #14719.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano committed Apr 13, 2022
1 parent 711dde1 commit 2c85240
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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
),
),
}
)
}
)

0 comments on commit 2c85240

Please sign in to comment.