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

pantsbuild / pants / 22507851448

27 Feb 2026 11:28PM UTC coverage: 92.928% (-0.007%) from 92.935%
22507851448

push

github

web-flow
silence new HdrHistogram induced deprecation warning on Python 3.14 (#23144)

No more:
```
/usr/lib/python3.14/ctypes/_endian.py:33: DeprecationWarning: Due to '_pack_', the
'ExternalHeader' Structure will use memory layout compatible with MSVC (Windows). If this is intended, set _layout_ to 'ms'. The
 implicit default is deprecated and slated to become an error in Python 3.19.
  super().__setattr__(attrname, value)
/usr/lib/python3.14/ctypes/_endian.py:33: DeprecationWarning: Due to '_pack_', the 'PayloadHeader' Structure will use memory
layout compatible with MSVC (Windows). If this is intended, set _layout_ to 'ms'. The implicit default is deprecated and slated
to become an error in Python 3.19.
  super().__setattr__(attrname, value)
```

0 of 1 new or added line in 1 file covered. (0.0%)

71 existing lines in 12 files now uncovered.

90912 of 97831 relevant lines covered (92.93%)

4.06 hits per line

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

0.0
/src/python/pants/bin/pants_loader.py
1
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4

5
import importlib
×
6
import locale
×
7
import os
×
8
import sys
×
9
import time
×
10
import warnings
×
11

12
from pants.base.exiter import PANTS_FAILED_EXIT_CODE
×
13
from pants.bin.pants_env_vars import (
×
14
    DAEMON_ENTRYPOINT,
15
    IGNORE_UNRECOGNIZED_ENCODING,
16
    RECURSION_LIMIT,
17
)
18
from pants.bin.pants_runner import PantsRunner
×
19
from pants.engine.internals import native_engine
×
20
from pants.util.strutil import softwrap
×
21

22

23
class PantsLoader:
×
24
    """Initial entrypoint for pants.
25

26
    Executes a pants_runner by default, or executes a pantsd-specific entrypoint.
27
    """
28

29
    @staticmethod
×
30
    def setup_warnings() -> None:
×
31
        # We want to present warnings to the user, set this up before importing any of our own code,
32
        # to ensure all deprecation warnings are seen, including module deprecations.
33
        # The "default" action displays a warning for a particular file and line number exactly once.
34
        # See https://docs.python.org/3/library/warnings.html#the-warnings-filter for the complete list.
35
        #
36
        # However, we do turn off deprecation warnings for libraries that Pants uses for which we do
37
        # not have a fixed upstream version, typically because the library is no longer maintained.
38
        warnings.simplefilter("default", category=DeprecationWarning)
×
39
        # TODO: Eric-Arellano has emailed the author to see if he is willing to accept a PR fixing the
40
        # deprecation warnings and to release the fix. If he says yes, remove this once fixed.
41
        warnings.filterwarnings("ignore", category=DeprecationWarning, module="ansicolors")
×
42
        # Silence ctypes _pack_/_layout_ warning from HdrHistogram; due by Python 3.19
43
        # See: https://github.com/HdrHistogram/HdrHistogram/issues/216
NEW
44
        warnings.filterwarnings(
×
45
            "ignore",
46
            category=DeprecationWarning,
47
            message=r"Due to '_pack_', the '.+' Structure will use memory layout compatible with MSVC",
48
        )
49
        # Silence this ubiquitous warning. Several of our 3rd party deps incur this.
50
        warnings.filterwarnings(
×
51
            "ignore",
52
            category=DeprecationWarning,
53
            message="Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated",
54
        )
55

56
    @classmethod
×
57
    def ensure_locale(cls) -> None:
×
58
        """Ensure the locale uses UTF-8 encoding, or prompt for an explicit bypass."""
59

60
        encoding = locale.getpreferredencoding()
×
61
        if (
×
62
            encoding.lower() != "utf-8"
63
            and os.environ.get(IGNORE_UNRECOGNIZED_ENCODING, None) is None
64
        ):
65
            raise RuntimeError(
×
66
                softwrap(
67
                    f"""
68
                    Your system's preferred encoding is `{encoding}`, but Pants requires `UTF-8`.
69
                    Specifically, Python's `locale.getpreferredencoding()` must resolve to `UTF-8`.
70

71
                    You can fix this by setting the LC_* and LANG environment variables, e.g.:
72
                      LC_ALL=en_US.UTF-8
73
                      LANG=en_US.UTF-8
74
                    Or, bypass it by setting {IGNORE_UNRECOGNIZED_ENCODING}=1. Note that
75
                    pants may exhibit inconsistent behavior if this check is bypassed.
76
                    """
77
                )
78
            )
79

80
    @staticmethod
×
81
    def sandboxer_bin() -> str | None:
×
82
        # In theory as_file could return a temporary file and clean it up, so we'd be returning
83
        # an invalid path. But in practice we know that we're running either in a venv with all
84
        # resources expanded on disk, or from sources, and either way we will get a persistent
85
        # valid path that will not be cleaned up.
86
        with importlib.resources.as_file(
×
87
            importlib.resources.files("pants.bin").joinpath("sandboxer")
88
        ) as sandboxer_bin:
89
            if os.path.isfile(sandboxer_bin):
×
90
                os.chmod(sandboxer_bin, 0o755)
×
91
                return str(sandboxer_bin)
×
92
        return None
×
93

94
    @staticmethod
×
95
    def run_alternate_entrypoint(entrypoint: str) -> None:
×
96
        try:
×
97
            module_path, func_name = entrypoint.split(":", 1)
×
98
        except ValueError:
×
99
            print(
×
100
                f"{DAEMON_ENTRYPOINT} must be of the form `module.path:callable`", file=sys.stderr
101
            )
102
            sys.exit(PANTS_FAILED_EXIT_CODE)
×
103

104
        module = importlib.import_module(module_path)
×
105
        entrypoint_fn = getattr(module, func_name)
×
106
        entrypoint_fn()
×
107

108
    @staticmethod
×
109
    def run_default_entrypoint() -> None:
×
110
        start_time = time.time()
×
111
        try:
×
112
            runner = PantsRunner(args=sys.argv, env=os.environ)
×
113
            exit_code = runner.run(start_time)
×
114
        except KeyboardInterrupt as e:
×
115
            print(f"Interrupted by user:\n{e}", file=sys.stderr)
×
116
            exit_code = PANTS_FAILED_EXIT_CODE
×
117
        sys.exit(exit_code)
×
118

119
    @classmethod
×
120
    def main(cls) -> None:
×
121
        native_engine.initialize()
×
122
        cls.setup_warnings()
×
123
        cls.ensure_locale()
×
124

125
        sys.setrecursionlimit(int(os.environ.get(RECURSION_LIMIT, "10000")))
×
126

127
        os.environ["PANTS_SANDBOXER_BINARY_PATH"] = cls.sandboxer_bin() or ""
×
128
        entrypoint = os.environ.pop(DAEMON_ENTRYPOINT, None)
×
129
        if entrypoint:
×
130
            cls.run_alternate_entrypoint(entrypoint)
×
131
        else:
132
            cls.run_default_entrypoint()
×
133

134

135
def main() -> None:
×
136
    PantsLoader.main()
×
137

138

139
if __name__ == "__main__":
×
140
    main()
×
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