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

pantsbuild / pants / 19381742489

15 Nov 2025 12:52AM UTC coverage: 49.706% (-30.6%) from 80.29%
19381742489

Pull #22890

github

web-flow
Merge d961abf79 into 42e1ebd41
Pull Request #22890: Updated all python subsystem constraints to 3.14

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

14659 existing lines in 485 files now uncovered.

31583 of 63540 relevant lines covered (49.71%)

0.79 hits per line

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

80.0
/src/python/pants/jvm/resolve/common.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
2✔
5

6
import dataclasses
2✔
7
from collections.abc import Iterable
2✔
8
from dataclasses import dataclass
2✔
9
from urllib.parse import quote_plus as url_quote_plus
2✔
10

11
from pants.engine.collection import DeduplicatedCollection
2✔
12
from pants.engine.target import Target
2✔
13
from pants.jvm.resolve.coordinate import Coordinate
2✔
14
from pants.jvm.target_types import (
2✔
15
    JvmArtifactArtifactField,
16
    JvmArtifactExclusionsField,
17
    JvmArtifactFieldSet,
18
    JvmArtifactForceVersionField,
19
    JvmArtifactGroupField,
20
    JvmArtifactJarSourceField,
21
    JvmArtifactUrlField,
22
    JvmArtifactVersionField,
23
)
24
from pants.util.ordered_set import FrozenOrderedSet
2✔
25

26

27
@dataclass(frozen=True)
2✔
28
class ArtifactRequirement:
2✔
29
    """A single Maven-style coordinate for a JVM dependency, along with information of how to fetch
30
    the dependency if it is not to be fetched from a Maven repository."""
31

32
    coordinate: Coordinate
2✔
33

34
    url: str | None = None
2✔
35
    jar: JvmArtifactJarSourceField | None = None
2✔
36
    excludes: frozenset[str] | None = None
2✔
37
    force_version: bool = False
2✔
38

39
    @classmethod
2✔
40
    def from_jvm_artifact_target(cls, target: Target) -> ArtifactRequirement:
2✔
41
        if not JvmArtifactFieldSet.is_applicable(target):
×
42
            raise AssertionError(
×
43
                "`ArtifactRequirement.from_jvm_artifact_target()` only works on targets with "
44
                "`JvmArtifactFieldSet` fields present."
45
            )
46

47
        exclusions = target[JvmArtifactExclusionsField].value or ()
×
48
        return ArtifactRequirement(
×
49
            coordinate=Coordinate(
50
                group=target[JvmArtifactGroupField].value,
51
                artifact=target[JvmArtifactArtifactField].value,
52
                version=target[JvmArtifactVersionField].value,
53
            ),
54
            url=target[JvmArtifactUrlField].value,
55
            jar=(
56
                target[JvmArtifactJarSourceField]
57
                if target[JvmArtifactJarSourceField].value
58
                else None
59
            ),
60
            excludes=frozenset([*(exclusion.to_coord_str() for exclusion in exclusions)]) or None,
61
            force_version=target[JvmArtifactForceVersionField].value,
62
        )
63

64
    def with_extra_excludes(self, *excludes: str) -> ArtifactRequirement:
2✔
65
        """Creates a copy of this `ArtifactRequirement` with `excludes` provided.
66

67
        Mostly useful for testing (`Coordinate(...).as_requirement().with_extra_excludes(...)`).
68
        """
69

70
        return dataclasses.replace(
×
71
            self, excludes=self.excludes.union(excludes) if self.excludes else frozenset(excludes)
72
        )
73

74
    def to_coord_arg_str(self) -> str:
2✔
75
        return self.coordinate.to_coord_arg_str(
×
76
            {"url": url_quote_plus(self.url)} if self.url else {}
77
        )
78

79
    def to_metadata_str(self) -> str:
2✔
80
        attrs = {
1✔
81
            "url": self.url or "not_provided",
82
            "jar": self.jar.address.spec if self.jar else "not_provided",
83
        }
84
        if self.excludes:
1✔
85
            attrs["excludes"] = ",".join(sorted(self.excludes))
×
86

87
        return self.coordinate.to_coord_arg_str(attrs)
1✔
88

89

90
# TODO: Consider whether to carry classpath scope in some fashion via ArtifactRequirements.
91
class ArtifactRequirements(DeduplicatedCollection[ArtifactRequirement]):
2✔
92
    """An ordered list of Coordinates used as requirements."""
93

94
    @classmethod
2✔
95
    def from_coordinates(cls, coordinates: Iterable[Coordinate]) -> ArtifactRequirements:
2✔
UNCOV
96
        return ArtifactRequirements(ArtifactRequirement(coord) for coord in coordinates)
×
97

98

99
@dataclass(frozen=True)
2✔
100
class GatherJvmCoordinatesRequest:
2✔
101
    """A request to turn strings of coordinates (`group:artifact:version`) and/or addresses to
102
    `jvm_artifact` targets into `ArtifactRequirements`."""
103

104
    artifact_inputs: FrozenOrderedSet[str]
2✔
105
    option_name: str
2✔
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