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

pantsbuild / pants / 26342152999

23 May 2026 07:59PM UTC coverage: 91.165% (-1.6%) from 92.792%
26342152999

push

github

web-flow
Run Linux ARM CI on Depot runners (#23363)

RunsOn is deprecating their v2 stack, and rather than migrate
to v3 we should use the resources kindly donated by Depot.

GitHub also now has Linux ARM runners, should we need them.

87305 of 95766 relevant lines covered (91.16%)

3.87 hits per line

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

72.34
/src/python/pants/base/build_root.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
11✔
5
from collections.abc import Iterator
11✔
6
from contextlib import contextmanager
11✔
7
from pathlib import Path
11✔
8

9
from pants.util.meta import SingletonMetaclass
11✔
10

11

12
class BuildRoot(metaclass=SingletonMetaclass):
11✔
13
    """Represents the global workspace build root.
14

15
    By default, a Pants workspace is defined by a root directory where one of multiple sentinel
16
    files resides, such as `pants.toml` or `BUILD_ROOT`. This path can also be manipulated through
17
    this interface for re-location of the build root in tests.
18
    """
19

20
    sentinel_files = ["pants.toml", "pants", "BUILDROOT", "BUILD_ROOT"]
11✔
21

22
    class NotFoundError(Exception):
11✔
23
        """Raised when unable to find the current workspace build root."""
24

25
    def find_buildroot(self) -> str:
11✔
26
        buildroot = Path.cwd().resolve()
11✔
27
        while not any((buildroot / sentinel).is_file() for sentinel in self.sentinel_files):
11✔
28
            if buildroot != buildroot.parent:
×
29
                buildroot = buildroot.parent
×
30
            else:
31
                raise self.NotFoundError(
×
32
                    "No build root detected. Pants detects the build root by looking for at least one file "
33
                    f"from {self.sentinel_files} in the cwd and its ancestors. If you have none of these "
34
                    f"files, you can create an empty file in your build root."
35
                )
36
        return str(buildroot)
11✔
37

38
    def __init__(self) -> None:
11✔
39
        self._root_dir: str | None = None
11✔
40

41
    @property
11✔
42
    def pathlib_path(self) -> Path:
11✔
43
        return Path(self.path)
5✔
44

45
    @property
11✔
46
    def path(self) -> str:
11✔
47
        """Returns the build root for the current workspace."""
48
        if self._root_dir is None:
11✔
49
            # Do not remove/change this env var without coordinating with `pantsbuild/scie-pants` as
50
            # it is being used when bootstrapping Pants.
51
            override_buildroot = os.environ.get("PANTS_BUILDROOT_OVERRIDE", None)
11✔
52
            if override_buildroot:
11✔
53
                self._root_dir = override_buildroot
1✔
54
            else:
55
                self._root_dir = os.path.realpath(self.find_buildroot())
11✔
56
        return self._root_dir
11✔
57

58
    @path.setter
11✔
59
    def path(self, root_dir: str) -> None:
11✔
60
        """Manually establishes the build root for the current workspace."""
61
        path = os.path.realpath(root_dir)
11✔
62
        if not os.path.exists(path):
11✔
63
            raise ValueError(f"Build root does not exist: {root_dir}")
×
64
        self._root_dir = path
11✔
65

66
    def reset(self) -> None:
11✔
67
        """Clears the last calculated build root for the current workspace."""
68
        self._root_dir = None
×
69

70
    def __str__(self) -> str:
11✔
71
        return f"BuildRoot({self._root_dir})"
×
72

73
    @contextmanager
11✔
74
    def temporary(self, path: str) -> Iterator[None]:
11✔
75
        """Establishes a temporary build root, restoring the prior build root on exit."""
76
        if path is None:
×
77
            raise ValueError("Can only temporarily establish a build root given a path.")
×
78
        prior = self._root_dir
×
79
        self._root_dir = path
×
80
        try:
×
81
            yield
×
82
        finally:
83
            self._root_dir = prior
×
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