Skip to content

Commit

Permalink
fix: use shutil instead of cp during pbs bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Mehta committed Oct 18, 2024
1 parent 2d5c6b2 commit a531bce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import collections.abc
import functools
import json
import os
import shutil
import textwrap
from typing import Iterable, TypedDict, cast
from typing import Iterable, TypedDict, Union, cast

from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
Expand Down Expand Up @@ -40,6 +42,8 @@
PBS_NAMED_CACHE_NAME = "python_build_standalone"
PBS_APPEND_ONLY_CACHES = FrozenDict({PBS_NAMED_CACHE_NAME: PBS_SANDBOX_NAME})

StrPath = Union[str, bytes, os.PathLike]


class PBSPythonInfo(TypedDict):
url: str
Expand Down Expand Up @@ -190,7 +194,7 @@ async def get_python(
)
pbs_py_info = versions_info[python_version][platform.value]

downloaded_python = await Get(
await Get(
DownloadedExternalTool,
ExternalToolRequest(
DownloadFile(
Expand All @@ -204,25 +208,12 @@ async def get_python(
),
)

await Get(
ProcessResult,
Process(
[
cp.path,
"--recursive",
"--no-clobber",
"python",
f"{PBS_SANDBOX_NAME}/{python_version}",
],
level=LogLevel.DEBUG,
input_digest=downloaded_python.digest,
description=f"Install Python {python_version}",
append_only_caches=PBS_APPEND_ONLY_CACHES,
# Don't cache, we want this to always be run so that we can assume for the rest of the
# session the named_cache destination for this Python is valid, as the Python ecosystem
# mainly assumes absolute paths for Python interpreters.
cache_scope=ProcessCacheScope.PER_SESSION,
),
# Copy the python binary into the sandbox
shutil.copytree(
"python",
f"{PBS_SANDBOX_NAME}/{python_version}",
dirs_exist_ok=True,
copy_function=_copy_no_clobber,
)

python_path = named_caches_dir.val / PBS_NAMED_CACHE_NAME / python_version / "bin" / "python3"
Expand All @@ -242,3 +233,8 @@ def rules():
*external_tools_rules(),
UnionRule(PythonProvider, PBSPythonProvider),
)


def _copy_no_clobber(src: StrPath, dst: StrPath) -> None:
if not os.path.exists(dst):
shutil.copy2(src, dst)
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def run_run_request(
return mocked_console[1].get_stdout().strip()


@pytest.mark.platform_specific_behavior
@pytest.mark.parametrize("py_version", ["3.8.*", "3.9.*", "3.9.10"])
def test_using_pbs(rule_runner, py_version):
rule_runner.write_files(
Expand Down

0 comments on commit a531bce

Please sign in to comment.