• 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

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

4
import os
1✔
5
from collections.abc import Mapping
1✔
6
from typing import Any, Protocol
1✔
7

8

9
class FilePathOracle(Protocol):
1✔
10
    def filepath(self) -> str: ...
11

12

13
class ParseContext:
1✔
14
    """The build file context that context aware objects - aka BUILD macros - operate against.
15

16
    All fields of the ParseContext must be assumed to be mutable by macros, and should
17
    thus only be consumed in the context of a macro's `__call__` method (rather than
18
    in its `__init__`).
19
    """
20

21
    def __init__(
1✔
22
        self, build_root: str, type_aliases: Mapping[str, Any], filepath_oracle: FilePathOracle
23
    ) -> None:
24
        """Create a ParseContext.
25

26
        :param build_root: The absolute path to the build root.
27
        :param type_aliases: A dictionary of BUILD file symbols.
28
        :param filepath_oracle: An oracle than can be queried for the current BUILD file name.
29
        """
UNCOV
30
        self._build_root = build_root
×
UNCOV
31
        self._type_aliases = type_aliases
×
UNCOV
32
        self._filepath_oracle = filepath_oracle
×
33

34
    def create_object(self, alias: str, *args: Any, **kwargs: Any) -> Any:
1✔
35
        """Constructs the type with the given alias using the given args and kwargs.
36

37
        :API: public
38

39
        :param alias: The type alias.
40
        :param args: These pass through to the underlying callable object.
41
        :param kwargs: These pass through to the underlying callable object.
42
        :returns: The created object.
43
        """
44
        object_type = self._type_aliases.get(alias)
×
45
        if object_type is None:
×
46
            raise KeyError(f"There is no type registered for alias {alias}")
×
47
        if not callable(object_type):
×
48
            raise TypeError(
×
49
                f"Asked to call {alias} with args {args} and kwargs {kwargs} but it is not "
50
                f"callable, its a {type(alias).__name__}."
51
            )
52
        return object_type(*args, **kwargs)
×
53

54
    @property
1✔
55
    def rel_path(self) -> str:
1✔
56
        """Relative path from the build root to the directory of the BUILD file being parsed.
57

58
        :API: public
59
        """
60
        return os.path.dirname(self._filepath_oracle.filepath())
×
61

62
    @property
1✔
63
    def build_root(self) -> str:
1✔
64
        """Absolute path of the build root."""
65
        return self._build_root
×
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