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

pantsbuild / pants / 21552830208

31 Jan 2026 11:40PM UTC coverage: 80.277% (-0.05%) from 80.324%
21552830208

Pull #23062

github

web-flow
Merge 808a9786c into 2c4dcf9cf
Pull Request #23062: Remove support for Get

18 of 25 new or added lines in 4 files covered. (72.0%)

17119 existing lines in 541 files now uncovered.

78278 of 97510 relevant lines covered (80.28%)

3.36 hits per line

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

95.45
/src/python/pants/jvm/resolve/lockfile_metadata.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
12✔
5

6
from collections.abc import Iterable
12✔
7
from dataclasses import dataclass
12✔
8
from enum import Enum
12✔
9
from typing import Any, cast
12✔
10

11
from pants.core.util_rules.lockfile_metadata import (
12✔
12
    LockfileMetadata,
13
    LockfileMetadataValidation,
14
    LockfileScope,
15
    _get_metadata,
16
    lockfile_metadata_registrar,
17
)
18
from pants.jvm.resolve.common import ArtifactRequirement
12✔
19
from pants.util.ordered_set import FrozenOrderedSet
12✔
20

21
_jvm_lockfile_metadata = lockfile_metadata_registrar(LockfileScope.JVM)
12✔
22

23

24
class InvalidJVMLockfileReason(Enum):
12✔
25
    REQUIREMENTS_MISMATCH = "requirements_mismatch"
12✔
26

27

28
class LockfileContext(Enum):
12✔
29
    USER = "user"
12✔
30
    TOOL = "tool"
12✔
31

32

33
@dataclass(frozen=True)
12✔
34
class JVMLockfileMetadata(LockfileMetadata):
12✔
35
    scope = LockfileScope.JVM
12✔
36

37
    @staticmethod
12✔
38
    def new(
12✔
39
        requirements: Iterable[ArtifactRequirement],
40
    ) -> JVMLockfileMetadata:
41
        """Call the most recent version of the `LockfileMetadata` class to construct a concrete
42
        instance.
43

44
        This static method should be used in place of the `LockfileMetadata` constructor. This gives
45
        calling sites a predictable method to call to construct a new `LockfileMetadata` for
46
        writing, while still allowing us to support _reading_ older, deprecated metadata versions.
47
        """
48

UNCOV
49
        return JVMLockfileMetadataV1.from_artifact_requirements(requirements)
4✔
50

51
    def is_valid_for(
12✔
52
        self,
53
        requirements: Iterable[ArtifactRequirement] | None,
54
        context: LockfileContext,
55
    ) -> LockfileMetadataValidation:
56
        """Returns Truthy if this `JVMLockfileMetadata` can be used in the current execution
57
        context."""
58

59
        raise NotImplementedError("call `is_valid_for` on subclasses only")
×
60

61

62
@_jvm_lockfile_metadata(1)
12✔
63
@dataclass(frozen=True)
12✔
64
class JVMLockfileMetadataV1(JVMLockfileMetadata):
12✔
65
    """Initial metadata version for JVM user lockfiles.
66

67
    User validity is tested by the set of user requirements strings appearing as a subset of those
68
    in the metadata requirements.
69

70
    Tool validity is tested by the set of user requirements strings being an exact match of those
71
    in the metadata requirements.
72
    """
73

74
    requirements: FrozenOrderedSet[str]
12✔
75

76
    @classmethod
12✔
77
    def from_artifact_requirements(
12✔
78
        cls, requirements: Iterable[ArtifactRequirement]
79
    ) -> JVMLockfileMetadataV1:
UNCOV
80
        return cls(FrozenOrderedSet(sorted(i.to_metadata_str() for i in requirements)))
4✔
81

82
    @classmethod
12✔
83
    def _from_json_dict(
12✔
84
        cls: type[JVMLockfileMetadataV1],
85
        json_dict: dict[Any, Any],
86
        lockfile_description: str,
87
        error_suffix: str,
88
    ) -> JVMLockfileMetadataV1:
UNCOV
89
        metadata = _get_metadata(json_dict, lockfile_description, error_suffix)
10✔
90

UNCOV
91
        requirements = metadata(
10✔
92
            "generated_with_requirements",
93
            FrozenOrderedSet[str],
94
            FrozenOrderedSet,
95
        )
96

UNCOV
97
        return JVMLockfileMetadataV1(requirements)
10✔
98

99
    @classmethod
12✔
100
    def additional_header_attrs(cls, instance: LockfileMetadata) -> dict[Any, Any]:
12✔
UNCOV
101
        instance = cast(JVMLockfileMetadataV1, instance)
3✔
UNCOV
102
        return {
3✔
103
            "generated_with_requirements": (
104
                sorted(instance.requirements) if instance.requirements is not None else None
105
            )
106
        }
107

108
    def is_valid_for(
12✔
109
        self,
110
        requirements: Iterable[ArtifactRequirement] | None,
111
        context: LockfileContext,
112
    ) -> LockfileMetadataValidation:
113
        """Returns a truthy object if the request requirements match the metadata requirements."""
114

UNCOV
115
        failure_reasons: set[InvalidJVMLockfileReason] = set()
10✔
UNCOV
116
        req_strings = FrozenOrderedSet(sorted(i.to_metadata_str() for i in requirements or []))
10✔
117

UNCOV
118
        if (context == LockfileContext.USER and not self.requirements.issuperset(req_strings)) or (
10✔
119
            context == LockfileContext.TOOL and self.requirements != req_strings
120
        ):
121
            failure_reasons.add(InvalidJVMLockfileReason.REQUIREMENTS_MISMATCH)
×
122

UNCOV
123
        return LockfileMetadataValidation(failure_reasons)
10✔
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