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

pantsbuild / pants / 19250292619

11 Nov 2025 12:09AM UTC coverage: 77.865% (-2.4%) from 80.298%
19250292619

push

github

web-flow
flag non-runnable targets used with `code_quality_tool` (#22875)

2 of 5 new or added lines in 2 files covered. (40.0%)

1487 existing lines in 72 files now uncovered.

71448 of 91759 relevant lines covered (77.86%)

3.22 hits per line

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

40.0
/src/python/pants/backend/python/macros/python_artifact.py
1
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
import collections.abc
11✔
5
import copy
11✔
6
import json
11✔
7
from typing import Any
11✔
8

9
from pants.util.strutil import softwrap
11✔
10

11

12
def _normalize_entry_points(
11✔
13
    all_entry_points: dict[str, list[str] | dict[str, str]],
14
) -> dict[str, dict[str, str]]:
15
    """Ensure any entry points are in the form Dict[str, Dict[str, str]]."""
UNCOV
16
    if not isinstance(all_entry_points, collections.abc.Mapping):
×
UNCOV
17
        raise ValueError(
×
18
            softwrap(
19
                f"""
20
                The `entry_points` in `python_artifact()` must be a dictionary,
21
                but was {all_entry_points!r} with type {type(all_entry_points).__name__}.
22
                """
23
            )
24
        )
25

UNCOV
26
    def _values_to_entry_points(values):
×
UNCOV
27
        if isinstance(values, collections.abc.Mapping):
×
UNCOV
28
            return values
×
UNCOV
29
        if isinstance(values, collections.abc.Iterable) and not isinstance(values, str):
×
UNCOV
30
            for entry_point in values:
×
UNCOV
31
                if not isinstance(entry_point, str) or "=" not in entry_point:
×
UNCOV
32
                    raise ValueError(
×
33
                        softwrap(
34
                            f"""
35
                            Invalid `entry_point`, expected `<name> = <entry point>`,
36
                            but got {entry_point!r}.
37
                            """
38
                        )
39
                    )
40

UNCOV
41
            return dict(tuple(map(str.strip, entry_point.split("=", 1))) for entry_point in values)
×
UNCOV
42
        raise ValueError(
×
43
            softwrap(
44
                f"""
45
                The values of the `entry_points` dictionary in `python_artifact()` must be
46
                a list of strings or a dictionary of string to string,
47
                but got {values!r} of type {type(values).__name__}.
48
                """
49
            )
50
        )
51

UNCOV
52
    return {
×
53
        category: _values_to_entry_points(values) for category, values in all_entry_points.items()
54
    }
55

56

57
class PythonArtifact:
11✔
58
    """Represents a Python setup.py-based project."""
59

60
    def __init__(self, **kwargs) -> None:
11✔
61
        """
62
        :param kwargs: Passed to `setuptools.setup
63
          <https://setuptools.pypa.io/en/latest/setuptools.html>`_.
64
        """
UNCOV
65
        if "entry_points" in kwargs:
×
66
            # coerce entry points from Dict[str, List[str]] to Dict[str, Dict[str, str]]
67
            kwargs["entry_points"] = _normalize_entry_points(kwargs["entry_points"])
×
68

UNCOV
69
        self._kw: dict[str, Any] = copy.deepcopy(kwargs)
×
70
        # The kwargs come from a BUILD file, and can contain somewhat arbitrary nested structures,
71
        # so we don't have a principled way to make them into a hashable data structure.
72
        # E.g., we can't naively turn all lists into tuples because distutils checks that some
73
        # fields (such as ext_modules) are lists, and doesn't accept tuples.
74
        # Instead we stringify and precompute a hash to use in our own __hash__, since we know
75
        # that this object is immutable.
UNCOV
76
        self._hash: int = hash(json.dumps(kwargs, sort_keys=True))
×
77

78
    @property
11✔
79
    def kwargs(self) -> dict[str, Any]:
11✔
80
        return self._kw
×
81

82
    def asdict(self) -> dict[str, Any]:
11✔
83
        return self.kwargs
×
84

85
    def __eq__(self, other: Any) -> bool:
11✔
UNCOV
86
        if not isinstance(other, PythonArtifact):
×
87
            return False
×
UNCOV
88
        return self._kw == other._kw
×
89

90
    def __hash__(self) -> int:
11✔
91
        return self._hash
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

© 2025 Coveralls, Inc