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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 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

UNCOV
4
from __future__ import annotations
×
5

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

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

26

UNCOV
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

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

35

UNCOV
36
@rule(desc="Creating map of Thrift targets to generated Python modules", level=LogLevel.DEBUG)
×
UNCOV
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

UNCOV
61
def rules():
×
UNCOV
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