• 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/python/goals/package_pex_binary.py
1
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
import logging
×
UNCOV
5
from dataclasses import dataclass
×
6

UNCOV
7
from pants.backend.python.target_types import (
×
8
    PexArgsField,
9
    PexBinaryDefaults,
10
    PexCheckField,
11
    PexCompletePlatformsField,
12
    PexEmitWarningsField,
13
    PexEntryPointField,
14
    PexEnvField,
15
    PexExecutableField,
16
    PexExecutionMode,
17
    PexExecutionModeField,
18
    PexExtraBuildArgsField,
19
    PexIgnoreErrorsField,
20
    PexIncludeRequirementsField,
21
    PexIncludeSourcesField,
22
    PexIncludeToolsField,
23
    PexInheritPathField,
24
    PexLayout,
25
    PexLayoutField,
26
    PexScriptField,
27
    PexShBootField,
28
    PexShebangField,
29
    PexStripEnvField,
30
    PexVenvHermeticScripts,
31
    PexVenvSitePackagesCopies,
32
    ResolvePexEntryPointRequest,
33
)
UNCOV
34
from pants.backend.python.target_types_rules import resolve_pex_entry_point
×
UNCOV
35
from pants.backend.python.util_rules.pex import create_pex, digest_complete_platforms
×
UNCOV
36
from pants.backend.python.util_rules.pex_from_targets import PexFromTargetsRequest
×
UNCOV
37
from pants.core.environments.target_types import EnvironmentField
×
UNCOV
38
from pants.core.goals.package import (
×
39
    BuiltPackage,
40
    BuiltPackageArtifact,
41
    OutputPathField,
42
    PackageFieldSet,
43
)
UNCOV
44
from pants.core.goals.run import RunFieldSet, RunInSandboxBehavior
×
UNCOV
45
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
46
from pants.engine.unions import UnionRule
×
UNCOV
47
from pants.util.frozendict import FrozenDict
×
UNCOV
48
from pants.util.logging import LogLevel
×
49

UNCOV
50
logger = logging.getLogger(__name__)
×
51

52

UNCOV
53
@dataclass(frozen=True)
×
UNCOV
54
class PexBinaryFieldSet(PackageFieldSet, RunFieldSet):
×
UNCOV
55
    run_in_sandbox_behavior = RunInSandboxBehavior.RUN_REQUEST_HERMETIC
×
56

UNCOV
57
    required_fields = (PexEntryPointField,)
×
58

59
    entry_point: PexEntryPointField
60
    script: PexScriptField
61
    executable: PexExecutableField
62
    args: PexArgsField
63
    env: PexEnvField
64

65
    output_path: OutputPathField
66
    emit_warnings: PexEmitWarningsField
67
    ignore_errors: PexIgnoreErrorsField
68
    inherit_path: PexInheritPathField
69
    sh_boot: PexShBootField
70
    shebang: PexShebangField
71
    strip_env: PexStripEnvField
72
    complete_platforms: PexCompletePlatformsField
73
    layout: PexLayoutField
74
    execution_mode: PexExecutionModeField
75
    include_requirements: PexIncludeRequirementsField
76
    include_sources: PexIncludeSourcesField
77
    include_tools: PexIncludeToolsField
78
    venv_site_packages_copies: PexVenvSitePackagesCopies
79
    venv_hermetic_scripts: PexVenvHermeticScripts
80
    environment: EnvironmentField
81
    check: PexCheckField
82
    extra_build_args: PexExtraBuildArgsField
83

UNCOV
84
    @property
×
UNCOV
85
    def _execution_mode(self) -> PexExecutionMode:
×
86
        return PexExecutionMode(self.execution_mode.value)
×
87

UNCOV
88
    def generate_additional_args(self, pex_binary_defaults: PexBinaryDefaults) -> tuple[str, ...]:
×
89
        args = []
×
90
        if self.emit_warnings.value_or_global_default(pex_binary_defaults) is False:
×
91
            args.append("--no-emit-warnings")
×
92
        elif self.emit_warnings.value_or_global_default(pex_binary_defaults) is True:
×
93
            args.append("--emit-warnings")
×
94
        if self.ignore_errors.value is True:
×
95
            args.append("--ignore-errors")
×
96
        if self.inherit_path.value is not None:
×
97
            args.append(f"--inherit-path={self.inherit_path.value}")
×
98
        if self.sh_boot.value is True:
×
99
            args.append("--sh-boot")
×
100
        if self.check.value is not None:
×
101
            args.append(f"--check={self.check.value}")
×
102
        if self.shebang.value is not None:
×
103
            args.append(f"--python-shebang={self.shebang.value}")
×
104
        if self.strip_env.value is False:
×
105
            args.append("--no-strip-pex-env")
×
106
        if self._execution_mode is PexExecutionMode.VENV:
×
107
            args.extend(("--venv", "prepend"))
×
108
        if self.include_tools.value is True:
×
109
            args.append("--include-tools")
×
110
        if self.venv_site_packages_copies.value is True:
×
111
            args.append("--venv-site-packages-copies")
×
112
        if self.venv_hermetic_scripts.value is False:
×
113
            args.append("--non-hermetic-venv-scripts")
×
114
        if self.extra_build_args.value:
×
115
            args.extend(self.extra_build_args.value)
×
116
        return tuple(args)
×
117

118

UNCOV
119
@dataclass(frozen=True)
×
UNCOV
120
class PexFromTargetsRequestForBuiltPackage:
×
121
    """An intermediate class that gives consumers access to the data used to create a
122
    `PexFromTargetsRequest` to fulfil a `BuiltPackage` request.
123

124
    This class is used directly by `run_pex_binary`, but should be handled transparently by direct
125
    `BuiltPackage` requests.
126
    """
127

128
    request: PexFromTargetsRequest
129

130

UNCOV
131
@rule(level=LogLevel.DEBUG)
×
UNCOV
132
async def package_pex_binary(
×
133
    field_set: PexBinaryFieldSet,
134
    pex_binary_defaults: PexBinaryDefaults,
135
) -> PexFromTargetsRequestForBuiltPackage:
136
    resolved_entry_point = await resolve_pex_entry_point(
×
137
        ResolvePexEntryPointRequest(field_set.entry_point)
138
    )
139

140
    output_filename = field_set.output_path.value_or_default(file_ending="pex")
×
141

142
    complete_platforms = await digest_complete_platforms(field_set.complete_platforms)
×
143

144
    request = PexFromTargetsRequest(
×
145
        addresses=[field_set.address],
146
        internal_only=False,
147
        main=resolved_entry_point.val or field_set.script.value or field_set.executable.value,
148
        inject_args=field_set.args.value or [],
149
        inject_env=field_set.env.value or FrozenDict[str, str](),
150
        complete_platforms=complete_platforms,
151
        output_filename=output_filename,
152
        layout=PexLayout(field_set.layout.value),
153
        additional_args=field_set.generate_additional_args(pex_binary_defaults),
154
        include_requirements=field_set.include_requirements.value,
155
        include_source_files=field_set.include_sources.value,
156
        include_local_dists=True,
157
        warn_for_transitive_files_targets=True,
158
    )
159

160
    return PexFromTargetsRequestForBuiltPackage(request)
×
161

162

UNCOV
163
@rule
×
UNCOV
164
async def built_package_for_pex_from_targets_request(
×
165
    field_set: PexBinaryFieldSet,
166
) -> BuiltPackage:
167
    pft_request = await package_pex_binary(field_set, **implicitly())
×
168
    pex = await create_pex(**implicitly(pft_request.request))
×
169
    return BuiltPackage(pex.digest, (BuiltPackageArtifact(pft_request.request.output_filename),))
×
170

171

UNCOV
172
def rules():
×
UNCOV
173
    return [*collect_rules(), UnionRule(PackageFieldSet, PexBinaryFieldSet)]
×
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