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

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

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

76.92
/src/python/pants/util/resources.py
1
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4

5
import importlib.resources
1✔
6
from itertools import chain
1✔
7

8

9
def read_resource(package_or_module: str, resource: str) -> bytes:
1✔
10
    """Reads a resource file from within the Pants package itself.
11

12
    This helper function is designed for compatibility with `pkgutil.get_data()` wherever possible,
13
    but also allows compatibility with PEP302 pluggable importers such as included with PyOxidizer.
14
    """
15

16
    a = importlib.import_module(package_or_module)
1✔
17
    package_: str = a.__package__  # type: ignore[assignment]
1✔
18
    resource_parts = resource.split("/")
1✔
19

20
    if len(resource_parts) == 1:
1✔
21
        package = package_
1✔
22
    else:
23
        package = ".".join(chain((package_,), resource_parts[:-1]))
×
24
        resource = resource_parts[-1]
×
25

26
    return importlib.resources.files(package).joinpath(resource).read_bytes()
1✔
27

28

29
def read_sibling_resource(sibling_name: str, resource: str) -> bytes:
1✔
30
    """A convenience function for reading a resource that is a sibling of the calling module.
31

32
    The caller should pass __name__ as the name arg, and the relpath to the resource as the resource
33
    arg.
34
    """
UNCOV
35
    return read_resource(sibling_name.rpartition(".")[0], resource)
×
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