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

pantsbuild / pants / 21552830208

31 Jan 2026 11:40PM UTC coverage: 80.277% (-0.05%) from 80.324%
21552830208

Pull #23062

github

web-flow
Merge 808a9786c into 2c4dcf9cf
Pull Request #23062: Remove support for Get

18 of 25 new or added lines in 4 files covered. (72.0%)

17119 existing lines in 541 files now uncovered.

78278 of 97510 relevant lines covered (80.28%)

3.36 hits per line

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

72.5
/src/python/pants/backend/codegen/thrift/thrift_parser.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✔
5

UNCOV
6
import re
5✔
UNCOV
7
from collections.abc import Mapping
5✔
UNCOV
8
from dataclasses import dataclass
5✔
9

UNCOV
10
from pants.backend.codegen.thrift.target_types import ThriftSourceField
5✔
UNCOV
11
from pants.engine.engine_aware import EngineAwareParameter
5✔
UNCOV
12
from pants.engine.internals.graph import hydrate_sources
5✔
UNCOV
13
from pants.engine.intrinsics import get_digest_contents
5✔
UNCOV
14
from pants.engine.rules import collect_rules, implicitly, rule
5✔
UNCOV
15
from pants.engine.target import HydrateSourcesRequest
5✔
UNCOV
16
from pants.util.frozendict import FrozenDict
5✔
UNCOV
17
from pants.util.ordered_set import FrozenOrderedSet
5✔
18

UNCOV
19
_QUOTE_CHAR = r"(?:'|\")"
5✔
20
# NB: We don't specify what a valid file name looks like to avoid accidentally breaking unicode.
UNCOV
21
_FILE_NAME = r"(.+?\.thrift)"
5✔
UNCOV
22
_IMPORT_REGEX = re.compile(rf"include\s+{_QUOTE_CHAR}{_FILE_NAME}{_QUOTE_CHAR}\s*")
5✔
23

24
# NB: We don't specify what a valid namespace looks like to avoid accidentally breaking unicode,
25
# but we do limit the namespace language because that is provided by Thrift.
UNCOV
26
_NAMESPACE_REGEX = re.compile(r"namespace\s+([a-z]+)\s+(.+)\s*")
5✔
27

28

UNCOV
29
@dataclass(frozen=True)
5✔
UNCOV
30
class ParsedThrift:
5✔
UNCOV
31
    imports: FrozenOrderedSet[str]
5✔
32
    # Note that Thrift only allows one namespace per language per file; later namespaces overwrite
33
    # earlier ones.
UNCOV
34
    namespaces: FrozenDict[str, str]
5✔
35

36

UNCOV
37
@dataclass(frozen=True)
5✔
UNCOV
38
class ParsedThriftRequest(EngineAwareParameter):
5✔
UNCOV
39
    sources_field: ThriftSourceField
5✔
UNCOV
40
    extra_namespace_directives: tuple[str, ...] = ()
5✔
41

UNCOV
42
    def debug_hint(self) -> str:
5✔
43
        return self.sources_field.file_path
×
44

45

UNCOV
46
@rule
5✔
UNCOV
47
async def parse_thrift_file(request: ParsedThriftRequest) -> ParsedThrift:
5✔
48
    sources = await hydrate_sources(HydrateSourcesRequest(request.sources_field), **implicitly())
×
49
    digest_contents = await get_digest_contents(sources.snapshot.digest)
×
50
    assert len(digest_contents) == 1
×
51

52
    file_content = digest_contents[0].content.decode()
×
53
    extra_namespaces: Mapping[str, str] = {}
×
54
    if request.extra_namespace_directives:
×
55
        for directive in request.extra_namespace_directives:
×
56
            extra_namespace_pattern = re.compile(rf"{directive}\s+([a-z]+)\s+(.+)\s*")
×
57
            extra_namespaces = {
×
58
                **extra_namespaces,
59
                **dict(extra_namespace_pattern.findall(file_content)),
60
            }
61

62
    return ParsedThrift(
×
63
        imports=FrozenOrderedSet(_IMPORT_REGEX.findall(file_content)),
64
        namespaces=FrozenDict({**dict(_NAMESPACE_REGEX.findall(file_content)), **extra_namespaces}),
65
    )
66

67

UNCOV
68
def rules():
5✔
UNCOV
69
    return collect_rules()
5✔
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

© 2026 Coveralls, Inc