diff --git a/test/apply_fixes/execution_logic.py b/test/apply_fixes/execution_logic.py index 613e1c5..9343b4c 100644 --- a/test/apply_fixes/execution_logic.py +++ b/test/apply_fixes/execution_logic.py @@ -10,7 +10,7 @@ from tempfile import TemporaryDirectory from typing import TYPE_CHECKING -from test.support.bazel import get_bazel_binary +from test.support.bazel import get_bazel_binary, get_current_workspace from test.support.result import Error if TYPE_CHECKING: @@ -52,11 +52,6 @@ def dwyu_path_as_string(dwyu_path: Path) -> str: return str(dwyu_path) if isinstance(dwyu_path, PosixPath) else str(dwyu_path).replace("\\", "\\\\") -def get_current_workspace(bazel_binary: Path) -> Path: - process = subprocess.run([bazel_binary, "info", "workspace"], check=True, capture_output=True, text=True) - return Path(process.stdout.strip()) - - @dataclass class TestDefinition: name: str diff --git a/test/aspect/execution_logic.py b/test/aspect/execution_logic.py index 532ec2a..bd6457c 100644 --- a/test/aspect/execution_logic.py +++ b/test/aspect/execution_logic.py @@ -10,7 +10,7 @@ from version import CompatibleVersions, TestedVersions -from test.support.bazel import get_bazel_binary +from test.support.bazel import get_bazel_binary, get_current_workspace from test.support.result import Error if TYPE_CHECKING: @@ -44,13 +44,6 @@ def execute_test( return succeeded -def get_current_workspace() -> Path: - process = subprocess.run( - ["bazel", "--max_idle_secs=5", "info", "workspace"], check=True, capture_output=True, text=True - ) - return Path(process.stdout.strip()) - - def get_bazel_rolling_version(bazel_bin: Path) -> str: run_env = deepcopy(environ) run_env["USE_BAZEL_VERSION"] = "rolling" @@ -80,7 +73,8 @@ def main( list_tests: bool = False, only_default_version: bool = False, ) -> int: - workspace_path = get_current_workspace() + bazel_binary = get_bazel_binary() + workspace_path = get_current_workspace(bazel_binary) test_files = sorted([Path(x) for x in workspace_path.glob("*/test_*.py")]) if list_tests: @@ -103,7 +97,6 @@ def main( else: versions = tested_versions - bazel_binary = get_bazel_binary() versions = set_rolling_bazel_version(versions=versions, bazel_bin=bazel_binary) failed_tests = [] diff --git a/test/support/bazel.py b/test/support/bazel.py index dbaf8db..db9f0ce 100644 --- a/test/support/bazel.py +++ b/test/support/bazel.py @@ -20,3 +20,15 @@ def get_bazel_binary() -> Path: return Path(bazel) raise RuntimeError("No bazelisk binary or bazel symlink towards bazelisk available on your system") + + +def get_current_workspace(bazel_bin: Path) -> Path: + cmd = [ + str(bazel_bin), + # Make sure no idle server lives forever wasting RAM + "--max_idle_secs=10", + "info", + "workspace", + ] + process = subprocess.run(cmd, shell=False, check=True, capture_output=True, text=True) + return Path(process.stdout.strip())