• 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.86
/src/python/pants/init/import_util.py
1
# Copyright 2025 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
import importlib.metadata
12✔
7
from collections.abc import Generator
12✔
8
from importlib.metadata import Distribution
12✔
9

10
from packaging.requirements import Requirement
12✔
11
from packaging.utils import NormalizedName, canonicalize_name
12✔
12
from packaging.version import InvalidVersion, Version
12✔
13

14

15
def distribution_matches_requirement(dist: Distribution, requirement: Requirement) -> bool:
12✔
16
    # Check whether the normalized names match.
UNCOV
17
    dist_name = canonicalize_name(dist.name)
1✔
UNCOV
18
    req_name = canonicalize_name(requirement.name)
1✔
UNCOV
19
    if dist_name != req_name:
1✔
UNCOV
20
        return False
1✔
21

22
    # If there is no version specifier, a name match is sufficient.
UNCOV
23
    if not requirement.specifier:
1✔
UNCOV
24
        return True
1✔
25

26
    # Otherwise, check version specifier and see if version is contained.
UNCOV
27
    try:
1✔
UNCOV
28
        dist_version = Version(dist.version)
1✔
UNCOV
29
        return requirement.specifier.contains(dist_version)
1✔
30
    except InvalidVersion:
×
31
        # If we can't parse the version, assume it doesn't match
32
        return False
×
33

34

35
def find_matching_distributions(
12✔
36
    requirement: Requirement | None,
37
) -> Generator[Distribution, None, None]:
38
    """Yield distributions matching the given requirement or all active distributions if
39
    `requirement` is `None`."""
UNCOV
40
    seen_dist_names: set[NormalizedName] = set()
4✔
UNCOV
41
    for dist in importlib.metadata.distributions():
4✔
42
        # Skip non-active distributions. Python prefers the first distribution on `sys.path`.
UNCOV
43
        normalized_dist_name = canonicalize_name(dist.name)
4✔
UNCOV
44
        if normalized_dist_name in seen_dist_names:
4✔
UNCOV
45
            continue
4✔
UNCOV
46
        seen_dist_names.add(normalized_dist_name)
4✔
UNCOV
47
        if requirement is None or distribution_matches_requirement(dist, requirement):
4✔
UNCOV
48
            yield dist
4✔
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