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

pantsbuild / pants / 21803785359

08 Feb 2026 07:13PM UTC coverage: 43.3% (-37.0%) from 80.277%
21803785359

Pull #23085

github

web-flow
Merge 7c1cd926d into 40389cc58
Pull Request #23085: A helper method for indexing paths by source root

2 of 6 new or added lines in 1 file covered. (33.33%)

17114 existing lines in 539 files now uncovered.

26075 of 60219 relevant lines covered (43.3%)

0.43 hits per line

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

72.5
/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
1✔
5

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

11
from pants.engine.collection import DeduplicatedCollection
1✔
12
from pants.engine.target import Target
1✔
13
from pants.jvm.resolve.coordinate import Coordinate
1✔
14
from pants.jvm.target_types import (
1✔
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
1✔
25

26

27
@dataclass(frozen=True)
1✔
28
class ArtifactRequirement:
1✔
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
1✔
33

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

39
    @classmethod
1✔
40
    def from_jvm_artifact_target(cls, target: Target) -> ArtifactRequirement:
1✔
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:
1✔
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:
1✔
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:
1✔
UNCOV
80
        attrs = {
×
81
            "url": self.url or "not_provided",
82
            "jar": self.jar.address.spec if self.jar else "not_provided",
83
        }
UNCOV
84
        if self.excludes:
×
85
            attrs["excludes"] = ",".join(sorted(self.excludes))
×
86

UNCOV
87
        return self.coordinate.to_coord_arg_str(attrs)
×
88

89

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

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

98

99
@dataclass(frozen=True)
1✔
100
class GatherJvmCoordinatesRequest:
1✔
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]
1✔
105
    option_name: str
1✔
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