• 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/utils.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 pants.backend.python.dependency_inference.module_mapper import PythonModuleOwners
×
UNCOV
7
from pants.engine.addresses import Address
×
UNCOV
8
from pants.util.docutil import doc_url
×
UNCOV
9
from pants.util.strutil import softwrap
×
10

11

UNCOV
12
class MissingPythonCodegenRuntimeLibrary(Exception):
×
UNCOV
13
    pass
×
14

15

UNCOV
16
class AmbiguousPythonCodegenRuntimeLibrary(Exception):
×
UNCOV
17
    pass
×
18

19

UNCOV
20
def find_python_runtime_library_or_raise_error(
×
21
    module_owners: PythonModuleOwners,
22
    codegen_address: Address,
23
    runtime_library_module: str,
24
    *,
25
    resolve: str,
26
    resolves_enabled: bool,
27
    recommended_requirement_name: str,
28
    recommended_requirement_url: str,
29
    disable_inference_option: str,
30
) -> Address:
31
    addresses = module_owners.unambiguous
×
32
    if module_owners.unambiguous:
×
33
        return module_owners.unambiguous[0]
×
34

35
    addresses = module_owners.ambiguous
×
36

37
    for_resolve_str = f" for the resolve '{resolve}'" if resolves_enabled else ""
×
38
    if not addresses:
×
39
        resolve_note = softwrap(
×
40
            (
41
                f"""
42
                Note that because `[python].enable_resolves` is set, you must specifically have a
43
                `python_requirement` target that uses the same resolve '{resolve}' as the target
44
                {codegen_address}. Alternatively, update {codegen_address} to use a different
45
                resolve.
46
                """
47
            )
48
            if resolves_enabled
49
            else ""
50
        )
51
        raise MissingPythonCodegenRuntimeLibrary(
×
52
            softwrap(
53
                f"""
54
                No `python_requirement` target was found with the module `{runtime_library_module}`
55
                in your project{for_resolve_str}, so the Python code generated from the target
56
                {codegen_address} will not work properly. See
57
                {doc_url("docs/python/overview/third-party-dependencies")} for how to add a requirement, such as
58
                adding to requirements.txt. Usually you will want to use the
59
                `{recommended_requirement_name}` project at {recommended_requirement_url}.
60

61
                {resolve_note}
62

63
                To ignore this error, set `{disable_inference_option} = false` in `pants.toml`.
64
                """
65
            )
66
        )
67

68
    alternative_solution = softwrap(
×
69
        (
70
            f"""
71
            Alternatively, change the resolve field for {codegen_address} to use a different resolve
72
            from `[python].resolves`.
73
            """
74
        )
75
        if resolves_enabled
76
        else (
77
            f"""
78
            Alternatively, if you do want to have multiple conflicting versions of the
79
            `{runtime_library_module}` requirement, set `{disable_inference_option} = false` in
80
            `pants.toml`. Then manually add a dependency on the relevant `python_requirement` target
81
            to each target that directly depends on this generated code (e.g. `python_source` targets).
82
            """
83
        )
84
    )
85
    raise AmbiguousPythonCodegenRuntimeLibrary(
×
86
        softwrap(
87
            f"""
88
            Multiple `python_requirement` targets were found with the module `{runtime_library_module}`
89
            in your project{for_resolve_str}, so it is ambiguous which to use for the runtime library
90
            for the Python code generated from the target {codegen_address}:
91
            {sorted(addr.spec for addr in addresses)}
92

93
            To fix, remove one of these `python_requirement` targets{for_resolve_str} so that
94
            there is no ambiguity and Pants can infer a dependency. It
95
            might also help to set
96
            `[python-infer].ambiguity-resolution = "by_source_root"`. {alternative_solution}
97
            """
98
        )
99
    )
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