• 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/go/util_rules/import_analysis.py
1
# Copyright 2021 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
import logging
×
UNCOV
7
from dataclasses import dataclass
×
8

UNCOV
9
import ijson.backends.python as ijson
×
10

UNCOV
11
from pants.backend.go.util_rules import go_mod
×
UNCOV
12
from pants.backend.go.util_rules.cgo import CGoCompilerFlags
×
UNCOV
13
from pants.backend.go.util_rules.sdk import GoSdkProcess
×
UNCOV
14
from pants.engine.process import execute_process_or_raise
×
UNCOV
15
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
16
from pants.util.frozendict import FrozenDict
×
UNCOV
17
from pants.util.logging import LogLevel
×
18

UNCOV
19
logger = logging.getLogger(__name__)
×
20

21

UNCOV
22
@dataclass(frozen=True)
×
UNCOV
23
class GoStdLibPackage:
×
UNCOV
24
    name: str
×
UNCOV
25
    import_path: str
×
UNCOV
26
    pkg_source_path: str
×
UNCOV
27
    imports: tuple[str, ...]
×
UNCOV
28
    import_map: FrozenDict[str, str]
×
29

30
    # Analysis for when Pants is able to compile the SDK directly.
UNCOV
31
    go_files: tuple[str, ...]
×
UNCOV
32
    cgo_files: tuple[str, ...]
×
UNCOV
33
    c_files: tuple[str, ...]
×
UNCOV
34
    cxx_files: tuple[str, ...]
×
UNCOV
35
    m_files: tuple[str, ...]
×
UNCOV
36
    h_files: tuple[str, ...]
×
UNCOV
37
    f_files: tuple[str, ...]
×
UNCOV
38
    s_files: tuple[str, ...]
×
UNCOV
39
    syso_files: tuple[str, ...]
×
UNCOV
40
    cgo_flags: CGoCompilerFlags
×
41

42
    # Embed configuration.
43
    #
44
    # Note: `EmbedConfig` is not resolved here to avoid issues with trying to build the embed analyzer.
45
    # The `EmbedConfig` will be resolved in `build_pkg_target.py` rules.
UNCOV
46
    embed_patterns: tuple[str, ...]
×
UNCOV
47
    embed_files: tuple[str, ...]
×
48

49

UNCOV
50
class GoStdLibPackages(FrozenDict[str, GoStdLibPackage]):
×
51
    """A mapping of standard library import paths to an analysis of the package at that import
52
    path."""
53

54

UNCOV
55
@dataclass(frozen=True)
×
UNCOV
56
class GoStdLibPackagesRequest:
×
UNCOV
57
    with_race_detector: bool
×
UNCOV
58
    cgo_enabled: bool = True
×
59

60

UNCOV
61
@rule(desc="Analyze Go standard library packages.", level=LogLevel.DEBUG)
×
UNCOV
62
async def analyze_go_stdlib_packages(request: GoStdLibPackagesRequest) -> GoStdLibPackages:
×
63
    maybe_race_arg = ["-race"] if request.with_race_detector else []
×
64
    list_result = await execute_process_or_raise(
×
65
        **implicitly(
66
            GoSdkProcess(
67
                # "-find" skips determining dependencies and imports for each package.
68
                command=("list", *maybe_race_arg, "-json", "std"),
69
                env={"CGO_ENABLED": "1" if request.cgo_enabled else "0"},
70
                description="Ask Go for its available import paths",
71
            )
72
        )
73
    )
74
    stdlib_packages = {}
×
75
    for pkg_json in ijson.items(list_result.stdout, "", multiple_values=True):
×
76
        import_path = pkg_json.get("ImportPath")
×
77
        pkg_source_path = pkg_json.get("Dir")
×
78

79
        if not import_path or not pkg_source_path:
×
80
            continue
×
81

82
        stdlib_packages[import_path] = GoStdLibPackage(
×
83
            name=pkg_json.get("Name"),
84
            import_path=import_path,
85
            pkg_source_path=pkg_source_path,
86
            imports=tuple(pkg_json.get("Imports", ())),
87
            import_map=FrozenDict(pkg_json.get("ImportMap", {})),
88
            go_files=tuple(pkg_json.get("GoFiles", ())),
89
            cgo_files=tuple(pkg_json.get("CgoFiles", ())),
90
            c_files=tuple(pkg_json.get("CFiles", ())),
91
            cxx_files=tuple(pkg_json.get("CXXFiles", ())),
92
            m_files=tuple(pkg_json.get("MFiles", ())),
93
            h_files=tuple(pkg_json.get("HFiles", ())),
94
            f_files=tuple(pkg_json.get("FFiles", ())),
95
            s_files=tuple(pkg_json.get("SFiles", ())),
96
            syso_files=tuple(pkg_json.get("SysoFiles", ())),
97
            cgo_flags=CGoCompilerFlags(
98
                cflags=tuple(pkg_json.get("CgoCFLAGS", [])),
99
                cppflags=tuple(pkg_json.get("CgoCPPFLAGS", [])),
100
                cxxflags=tuple(pkg_json.get("CgoCXXFLAGS", [])),
101
                fflags=tuple(pkg_json.get("CgoFFLAGS", [])),
102
                ldflags=tuple(pkg_json.get("CgoLDFLAGS", [])),
103
                pkg_config=tuple(pkg_json.get("CgoPkgConfig", [])),
104
            ),
105
            embed_patterns=tuple(pkg_json.get("EmbedPatterns", [])),
106
            embed_files=tuple(pkg_json.get("EmbedFiles", [])),
107
        )
108

109
    return GoStdLibPackages(stdlib_packages)
×
110

111

UNCOV
112
def rules():
×
UNCOV
113
    return (
×
114
        *collect_rules(),
115
        *go_mod.rules(),
116
    )
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