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

pantsbuild / pants / 18827312341

27 Oct 2025 01:50AM UTC coverage: 65.106% (-15.2%) from 80.279%
18827312341

Pull #22806

github

web-flow
Merge 082bdd4c2 into 170094e99
Pull Request #22806: Updated Javascript dependencies and re-locked

3 of 3 new or added lines in 3 files covered. (100.0%)

8118 existing lines in 291 files now uncovered.

48695 of 74793 relevant lines covered (65.11%)

1.81 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
5✔
5
from collections.abc import Mapping
5✔
6
from typing import Any, Protocol
5✔
7

8

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

12

13
class ParseContext:
5✔
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__(
5✔
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:
5✔
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
5✔
55
    def rel_path(self) -> str:
5✔
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
5✔
63
    def build_root(self) -> str:
5✔
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