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

pantsbuild / pants / 25259185675

02 May 2026 06:47PM UTC coverage: 92.141% (-0.8%) from 92.955%
25259185675

push

github

web-flow
Fix the dynamic UI. (#23306)

In #23114 we upgraded to indicatif 0.18.4,
which included a fix to respect TERM, and 
display nothing if it's unset.

Since we did not pass TERM through pantsd, the
dynamic ui is now not shown. 

This change fixes that, and also pass NO_COLOR
through, since indicatif inspects it too.

88773 of 96345 relevant lines covered (92.14%)

3.83 hits per line

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

94.87
/src/python/pants/backend/scala/util_rules/versions.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
from __future__ import annotations
9✔
4

5
import re
9✔
6
from dataclasses import dataclass
9✔
7
from enum import Enum
9✔
8
from typing import Any
9✔
9

10
from pants.engine.rules import collect_rules, rule
9✔
11
from pants.jvm.resolve.coordinate import Coordinate
9✔
12
from pants.util.strutil import softwrap
9✔
13

14

15
class InvalidScalaVersion(ValueError):
9✔
16
    def __init__(self, scala_version: str) -> None:
9✔
17
        super().__init__(
×
18
            softwrap(
19
                f"""Value '{scala_version}' is not a valid Scala version.
20
            It should be formed of [major].[minor].[patch]"""
21
            )
22
        )
23

24

25
class ScalaCrossVersionMode(Enum):
9✔
26
    BINARY = "binary"
9✔
27
    FULL = "full"
9✔
28

29

30
_SCALA_VERSION_PATTERN = re.compile(r"^([0-9]+)\.([0-9]+)\.([0-9]+)(\-(.+))?$")
9✔
31

32

33
@dataclass(frozen=True)
9✔
34
class ScalaVersion:
9✔
35
    major: int
9✔
36
    minor: int
9✔
37
    patch: int
9✔
38
    suffix: str | None = None
9✔
39

40
    @classmethod
9✔
41
    def parse(cls, scala_version: str) -> ScalaVersion:
9✔
42
        matched = _SCALA_VERSION_PATTERN.match(scala_version)
9✔
43
        if not matched:
9✔
44
            raise InvalidScalaVersion(scala_version)
×
45

46
        return cls(
9✔
47
            major=int(matched.groups()[0]),
48
            minor=int(matched.groups()[1]),
49
            patch=int(matched.groups()[2]),
50
            suffix=matched.groups()[4] if len(matched.groups()) == 5 else None,
51
        )
52

53
    def crossversion(self, mode: ScalaCrossVersionMode) -> str:
9✔
54
        if mode == ScalaCrossVersionMode.FULL:
7✔
55
            return str(self)
2✔
56
        if self.major >= 3:
7✔
57
            return str(self.major)
2✔
58
        return f"{self.major}.{self.minor}"
7✔
59

60
    @property
9✔
61
    def binary(self) -> str:
9✔
62
        return self.crossversion(ScalaCrossVersionMode.BINARY)
7✔
63

64
    def __eq__(self, other: Any) -> bool:
9✔
65
        return (
7✔
66
            isinstance(other, ScalaVersion)
67
            and other.major == self.major
68
            and other.minor == self.minor
69
            and other.patch == self.patch
70
            and other.suffix == self.suffix
71
        )
72

73
    def __gt__(self, other: Any) -> bool:
9✔
74
        if isinstance(other, ScalaVersion):
1✔
75
            if self.major > other.major:
1✔
76
                return True
1✔
77
            elif (self.major == other.major) and (self.minor > other.minor):
1✔
78
                return True
1✔
79
            elif (self.major == other.major) and (self.minor == other.minor):
1✔
80
                return self.patch > other.patch
1✔
81
            return False
1✔
82
        return False
×
83

84
    def __str__(self) -> str:
9✔
85
        version_str = f"{self.major}.{self.minor}.{self.patch}"
9✔
86
        if self.suffix:
9✔
87
            version_str += f"-{self.suffix}"
1✔
88
        return version_str
9✔
89

90

91
@dataclass(frozen=True)
9✔
92
class ScalaArtifactsForVersionRequest:
9✔
93
    scala_version: ScalaVersion
9✔
94

95

96
@dataclass(frozen=True)
9✔
97
class ScalaArtifactsForVersionResult:
9✔
98
    compiler_coordinate: Coordinate
9✔
99
    library_coordinate: Coordinate
9✔
100
    reflect_coordinate: Coordinate | None
9✔
101
    compiler_main: str
9✔
102
    repl_main: str
9✔
103

104
    @property
9✔
105
    def all_coordinates(self) -> tuple[Coordinate, ...]:
9✔
106
        coords = [self.compiler_coordinate, self.library_coordinate]
5✔
107
        if self.reflect_coordinate:
5✔
108
            coords.append(self.reflect_coordinate)
5✔
109
        return tuple(coords)
5✔
110

111

112
def _resolve_scala_artifacts_for_version(
9✔
113
    scala_version: ScalaVersion,
114
) -> ScalaArtifactsForVersionResult:
115
    if scala_version.major == 3:
8✔
116
        return ScalaArtifactsForVersionResult(
×
117
            compiler_coordinate=Coordinate(
118
                group="org.scala-lang",
119
                artifact="scala3-compiler_3",
120
                version=str(scala_version),
121
            ),
122
            library_coordinate=Coordinate(
123
                group="org.scala-lang",
124
                artifact="scala3-library_3",
125
                version=str(scala_version),
126
            ),
127
            reflect_coordinate=None,
128
            compiler_main="dotty.tools.dotc.Main",
129
            repl_main="dotty.tools.repl.Main",
130
        )
131

132
    return ScalaArtifactsForVersionResult(
8✔
133
        compiler_coordinate=Coordinate(
134
            group="org.scala-lang",
135
            artifact="scala-compiler",
136
            version=str(scala_version),
137
        ),
138
        library_coordinate=Coordinate(
139
            group="org.scala-lang",
140
            artifact="scala-library",
141
            version=str(scala_version),
142
        ),
143
        reflect_coordinate=Coordinate(
144
            group="org.scala-lang",
145
            artifact="scala-reflect",
146
            version=str(scala_version),
147
        ),
148
        compiler_main="scala.tools.nsc.Main",
149
        repl_main="scala.tools.nsc.MainGenericRunner",
150
    )
151

152

153
@rule
9✔
154
async def resolve_scala_artifacts_for_version(
9✔
155
    request: ScalaArtifactsForVersionRequest,
156
) -> ScalaArtifactsForVersionResult:
157
    return _resolve_scala_artifacts_for_version(request.scala_version)
8✔
158

159

160
def rules():
9✔
161
    return collect_rules()
8✔
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