• 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

51.22
/src/python/pants/backend/go/util_rules/pkg_pattern.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
6✔
4

5
import re
6✔
6
from collections.abc import Callable
6✔
7

8
# Adapted from Go toolchain:
9
# https://github.com/golang/go/blob/6a70292d1cb3464e5b2c2c03341e5148730a1889/src/cmd/internal/pkgpattern/pkgpattern.go
10
#
11
# // Copyright 2022 The Go Authors. All rights reserved.
12
# // Use of this source code is governed by a BSD-style
13
# // license that can be found in the LICENSE file.
14

15

16
def match_pattern(pattern: str) -> Callable[[str], bool]:
6✔
17
    """MatchPattern(pattern)(name) reports whether name matches pattern. Pattern is a limited glob
18
    pattern in which '...' means 'any string' and there is no other special syntax. Unfortunately,
19
    there are two special cases. Quoting "go help packages":
20

21
    First, /... at the end of the pattern can match an empty string, so that net/... matches both
22
    net and packages in its subdirectories, like net/http. Second, any slash-separated pattern
23
    element containing a wildcard never participates in a match of the "vendor" element in the path
24
    of a vendored package, so that ./... does not match packages in subdirectories of ./vendor or
25
    ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do. Note, however, that a directory
26
    named vendor that itself contains code is not a vendored package: cmd/vendor would be a command
27
    named vendor, and the pattern cmd/... matches it.
28
    """
29
    return _match_pattern_internal(pattern, True)
×
30

31

32
def match_simple_pattern(pattern: str) -> Callable[[str], bool]:
6✔
33
    """MatchSimplePattern returns a function that can be used to check whether a given name matches
34
    a pattern, where pattern is a limited glob pattern in which '...' means 'any string', with no
35
    other special syntax.
36

37
    There is one special case for MatchPatternSimple: according to the rules in "go help packages":
38
    a /... at the end of the pattern can match an empty string, so that net/... matches both net and
39
    packages in its subdirectories, like net/http.
40
    """
41
    return _match_pattern_internal(pattern, False)
1✔
42

43

44
def _match_pattern_internal(pattern: str, vendor_exclude: bool) -> Callable[[str], bool]:
6✔
45
    # Convert pattern to regular expression.
46
    # The strategy for the trailing /... is to nest it in an explicit ? expression.
47
    # The strategy for the vendor exclusion is to change the unmatchable
48
    # vendor strings to a disallowed code point (vendorChar) and to use
49
    # "(anything but that codepoint)*" as the implementation of the ... wildcard.
50
    # This is a bit complicated, but the obvious alternative,
51
    # namely a handwritten search like in most shell glob matchers,
52
    # is too easy to make accidentally exponential.
53
    # Using package regexp guarantees linear-time matching.
54

55
    vendor_char = chr(0)  # "\x00"
1✔
56

57
    if vendor_exclude and vendor_char in pattern:
1✔
58
        return lambda _name: False
×
59

60
    r: str = re.escape(pattern)
1✔
61
    wild = ".*"
1✔
62
    if vendor_exclude:
1✔
63
        wild = rf"[^{vendor_char}]*"
×
64
        r = _replace_vendor(r, vendor_char)
×
65

66
        suffix = rf"/{vendor_char}/\.\.\."
×
67
        if r.endswith(suffix):
×
68
            r = r[0 : -len(suffix)] + rf"(/vendor|/{vendor_char}/\.\.\.)"
×
69
        elif r == rf"{vendor_char}/\.\.\.":
×
70
            r = rf"(/vendor|/{vendor_char}/\.\.\.)"
×
71

72
    suffix = r"/\.\.\."
1✔
73
    if r.endswith(suffix):
1✔
74
        r = r[0 : -len(suffix)] + r"(/\.\.\.)?"
×
75
    r = r.replace(r"\.\.\.", wild)
1✔
76

77
    reg = re.compile(rf"^{r}$")
1✔
78

79
    def f(name: str) -> bool:
1✔
80
        if vendor_exclude:
1✔
81
            if vendor_char in name:
×
82
                return False
×
83
            name = _replace_vendor(name, vendor_char)
×
84
        return bool(reg.match(name))
1✔
85

86
    return f
1✔
87

88

89
# replaceVendor returns the result of replacing
90
# non-trailing vendor path elements in x with repl.
91
def _replace_vendor(x: str, repl: str) -> str:
6✔
92
    if "vendor" not in x:
×
93
        return x
×
94

95
    elems = x.split("/")
×
96
    for i, elem in enumerate(elems[0:-1]):
×
97
        if elem == "vendor":
×
98
            elems[i] = repl
×
99
    return "/".join(elems)
×
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