• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 18517631058

15 Oct 2025 04:18AM UTC coverage: 69.207% (-11.1%) from 80.267%
18517631058

Pull #22745

github

web-flow
Merge 642a76ca1 into 99919310e
Pull Request #22745: [windows] Add windows support in the stdio crate.

53815 of 77759 relevant lines covered (69.21%)

2.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/python/pants/backend/codegen/thrift/apache/python/python_thrift_module_mapper.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
×
5

6
from collections import defaultdict
×
7
from pathlib import PurePath
×
8
from typing import DefaultDict
×
9

10
from pants.backend.codegen.thrift import thrift_parser
×
11
from pants.backend.codegen.thrift.target_types import AllThriftTargets, ThriftSourceField
×
12
from pants.backend.codegen.thrift.thrift_parser import ParsedThriftRequest, parse_thrift_file
×
13
from pants.backend.python.dependency_inference.module_mapper import (
×
14
    FirstPartyPythonMappingImpl,
15
    FirstPartyPythonMappingImplMarker,
16
    ModuleProvider,
17
    ModuleProviderType,
18
    ResolveName,
19
)
20
from pants.backend.python.subsystems.setup import PythonSetup
×
21
from pants.backend.python.target_types import PythonResolveField
×
22
from pants.engine.rules import collect_rules, concurrently, rule
×
23
from pants.engine.unions import UnionRule
×
24
from pants.util.logging import LogLevel
×
25

26

27
def thrift_path_to_py_modules(source_path: str, *, namespace: str | None) -> tuple[str, str]:
×
28
    prefix = namespace if namespace else PurePath(source_path).stem
×
29
    return f"{prefix}.ttypes", f"{prefix}.constants"
×
30

31

32
class PythonThriftMappingMarker(FirstPartyPythonMappingImplMarker):
×
33
    pass
×
34

35

36
@rule(desc="Creating map of Thrift targets to generated Python modules", level=LogLevel.DEBUG)
×
37
async def map_thrift_to_python_modules(
×
38
    thrift_targets: AllThriftTargets,
39
    python_setup: PythonSetup,
40
    _: PythonThriftMappingMarker,
41
) -> FirstPartyPythonMappingImpl:
42
    parsed_files = await concurrently(
×
43
        parse_thrift_file(ParsedThriftRequest(tgt[ThriftSourceField])) for tgt in thrift_targets
44
    )
45

46
    resolves_to_modules_to_providers: DefaultDict[
×
47
        ResolveName, DefaultDict[str, list[ModuleProvider]]
48
    ] = defaultdict(lambda: defaultdict(list))
49
    for tgt, parsed in zip(thrift_targets, parsed_files):
×
50
        resolve = tgt[PythonResolveField].normalized_value(python_setup)
×
51
        provider = ModuleProvider(tgt.address, ModuleProviderType.IMPL)
×
52
        m1, m2 = thrift_path_to_py_modules(
×
53
            source_path=tgt[ThriftSourceField].file_path, namespace=parsed.namespaces.get("py")
54
        )
55
        resolves_to_modules_to_providers[resolve][m1].append(provider)
×
56
        resolves_to_modules_to_providers[resolve][m2].append(provider)
×
57

58
    return FirstPartyPythonMappingImpl.create(resolves_to_modules_to_providers)
×
59

60

61
def rules():
×
62
    return (
×
63
        *collect_rules(),
64
        *thrift_parser.rules(),
65
        UnionRule(FirstPartyPythonMappingImplMarker, PythonThriftMappingMarker),
66
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc