Skip to content

Commit

Permalink
Fix PexPEX invocations (pantsbuild#18610)
Browse files Browse the repository at this point in the history
Fixes pantsbuild#18601 (among likely
other issues) by ensuring we always run the pex PEX with a `--python`
set to the bootstrap Python.

Note that none of the callers were passing `python` so I removed the
parameter.
  • Loading branch information
thejcannon authored Mar 29, 2023
1 parent c398899 commit a805788
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 2 additions & 9 deletions src/python/pants/backend/python/util_rules/pex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
from pants.backend.python.subsystems.python_native_code import PythonNativeCodeSubsystem
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.util_rules import pex_environment
from pants.backend.python.util_rules.pex_environment import (
PexEnvironment,
PexSubsystem,
PythonExecutable,
)
from pants.backend.python.util_rules.pex_environment import PexEnvironment, PexSubsystem
from pants.core.util_rules import adhoc_binaries, external_tool
from pants.core.util_rules.adhoc_binaries import PythonBuildStandaloneBinary
from pants.core.util_rules.external_tool import (
Expand Down Expand Up @@ -67,7 +63,6 @@ class PexCliProcess:
extra_env: Optional[FrozenDict[str, str]]
output_files: Optional[Tuple[str, ...]]
output_directories: Optional[Tuple[str, ...]]
python: Optional[PythonExecutable]
level: LogLevel
concurrency_available: int
cache_scope: ProcessCacheScope
Expand All @@ -82,7 +77,6 @@ def __init__(
extra_env: Optional[Mapping[str, str]] = None,
output_files: Optional[Iterable[str]] = None,
output_directories: Optional[Iterable[str]] = None,
python: Optional[PythonExecutable] = None,
level: LogLevel = LogLevel.INFO,
concurrency_available: int = 0,
cache_scope: ProcessCacheScope = ProcessCacheScope.SUCCESSFUL,
Expand All @@ -96,7 +90,6 @@ def __init__(
object.__setattr__(
self, "output_directories", tuple(output_directories) if output_directories else None
)
object.__setattr__(self, "python", python)
object.__setattr__(self, "level", level)
object.__setattr__(self, "concurrency_available", concurrency_available)
object.__setattr__(self, "cache_scope", cache_scope)
Expand Down Expand Up @@ -190,7 +183,7 @@ async def setup_pex_cli_process(
complete_pex_env = pex_env.in_sandbox(working_directory=None)
normalized_argv = complete_pex_env.create_argv(pex_pex.exe, *args)
env = {
**complete_pex_env.environment_dict(python=request.python),
**complete_pex_env.environment_dict(python=bootstrap_python),
**python_native_code.subprocess_env_vars,
**(request.extra_env or {}),
# If a subcommand is used, we need to use the `pex3` console script.
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/python/util_rules/pex_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ class CompletePexEnvironment:
def interpreter_search_paths(self) -> tuple[str, ...]:
return self._pex_environment.interpreter_search_paths

def create_argv(
self, pex_filepath: str, *args: str, python: PythonExecutable | None = None
) -> tuple[str, ...]:
def create_argv(self, pex_filepath: str, *args: str) -> tuple[str, ...]:
pex_relpath = (
os.path.relpath(pex_filepath, self._working_directory)
if self._working_directory
else pex_filepath
)
return (self._pex_environment.bootstrap_python.path, pex_relpath, *args)

def environment_dict(self, *, python: PythonExecutable | None = None) -> Mapping[str, str]:
def environment_dict(
self, *, python: PythonExecutable | PythonBuildStandaloneBinary | None = None
) -> Mapping[str, str]:
"""The environment to use for running anything with PEX.
If the Process is run with a pre-selected Python interpreter, set `python_configured=True`
Expand Down

0 comments on commit a805788

Please sign in to comment.