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

pantsbuild / pants / 24145945949

08 Apr 2026 04:14PM UTC coverage: 82.077% (-10.8%) from 92.91%
24145945949

Pull #23233

github

web-flow
Merge 089d98e3c into 9036734c9
Pull Request #23233: Introduce a LockfileFormat enum.

8 of 11 new or added lines in 4 files covered. (72.73%)

7635 existing lines in 306 files now uncovered.

63732 of 77649 relevant lines covered (82.08%)

2.96 hits per line

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

84.62
/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
7✔
6
from itertools import chain
7✔
7

8

9
def read_resource(package_or_module: str, resource: str) -> bytes:
7✔
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)
7✔
17
    package_: str = a.__package__  # type: ignore[assignment]
7✔
18
    resource_parts = resource.split("/")
7✔
19

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

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

28

29
def read_sibling_resource(sibling_name: str, resource: str) -> bytes:
7✔
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
    """
35
    return read_resource(sibling_name.rpartition(".")[0], resource)
5✔
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