• 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

92.68
/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).
UNCOV
3
from __future__ import annotations
7✔
4

UNCOV
5
import re
7✔
UNCOV
6
from collections.abc import Callable
7✔
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

UNCOV
16
def match_pattern(pattern: str) -> Callable[[str], bool]:
7✔
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
    """
UNCOV
29
    return _match_pattern_internal(pattern, True)
1✔
30

31

UNCOV
32
def match_simple_pattern(pattern: str) -> Callable[[str], bool]:
7✔
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
    """
UNCOV
41
    return _match_pattern_internal(pattern, False)
1✔
42

43

UNCOV
44
def _match_pattern_internal(pattern: str, vendor_exclude: bool) -> Callable[[str], bool]:
7✔
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

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

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

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

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

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

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

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

UNCOV
86
    return f
1✔
87

88

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

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