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

pantsbuild / pants / 18252174847

05 Oct 2025 01:36AM UTC coverage: 43.382% (-36.9%) from 80.261%
18252174847

push

github

web-flow
run tests on mac arm (#22717)

Just doing the minimal to pull forward the x86_64 pattern.

ref #20993

25776 of 59416 relevant lines covered (43.38%)

1.3 hits per line

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

32.14
/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
3✔
5

6
import importlib.metadata
3✔
7
from collections.abc import Generator
3✔
8
from importlib.metadata import Distribution
3✔
9

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

14

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

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

26
    # Otherwise, check version specifier and see if version is contained.
27
    try:
×
28
        dist_version = Version(dist.version)
×
29
        return requirement.specifier.contains(dist_version)
×
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(
3✔
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`."""
40
    seen_dist_names: set[NormalizedName] = set()
×
41
    for dist in importlib.metadata.distributions():
×
42
        # Skip non-active distributions. Python prefers the first distribution on `sys.path`.
43
        normalized_dist_name = canonicalize_name(dist.name)
×
44
        if normalized_dist_name in seen_dist_names:
×
45
            continue
×
46
        seen_dist_names.add(normalized_dist_name)
×
47
        if requirement is None or distribution_matches_requirement(dist, requirement):
×
48
            yield dist
×
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

© 2025 Coveralls, Inc