Skip to content

Commit

Permalink
Add pex_binary support for --no-strip-pex-env. (pantsbuild#12061)
Browse files Browse the repository at this point in the history
Not many PEX files will need this to operate correctly, but it was an
omission brought to attention by pantsbuild#12057.
  • Loading branch information
jsirois authored May 12, 2021
1 parent 1577b8d commit 1d4dc1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/python/pants/backend/python/goals/package_pex_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pants.backend.python.target_types import PexPlatformsField as PythonPlatformsField
from pants.backend.python.target_types import (
PexShebangField,
PexStripEnvField,
PexZipSafeField,
ResolvedPexEntryPoint,
ResolvePexEntryPointRequest,
Expand Down Expand Up @@ -62,6 +63,7 @@ class PexBinaryFieldSet(PackageFieldSet, RunFieldSet):
inherit_path: PexInheritPathField
shebang: PexShebangField
zip_safe: PexZipSafeField
strip_env: PexStripEnvField
platforms: PythonPlatformsField
execution_mode: PexExecutionModeField
include_tools: PexIncludeToolsField
Expand All @@ -84,6 +86,8 @@ def generate_additional_args(self, pex_binary_defaults: PexBinaryDefaults) -> Tu
args.append(f"--python-shebang={self.shebang.value}")
if self.zip_safe.value is False:
args.append("--not-zip-safe")
if self.strip_env.value is False:
args.append("--no-strip-pex-env")
if self._execution_mode is PexExecutionMode.UNZIP:
args.append("--unzip")
if self._execution_mode is PexExecutionMode.VENV:
Expand Down
13 changes: 13 additions & 0 deletions src/python/pants/backend/python/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ class PexZipSafeField(BoolField):
)


class PexStripEnvField(BoolField):
alias = "strip_pex_env"
default = True
help = (
"Whether or not to strip the PEX runtime environment of `PEX*` environment variables.\n\n"
"Most applications have no need for the `PEX*` environment variables that are used to "
"control PEX startup; so these variables are scrubbed from the environment by Pex before "
"transferring control to the application by default. This prevents any subprocesses that "
"happen to execute other PEX files from inheriting these control knob values since most "
"would be undesired; e.g.: PEX_MODULE or PEX_PATH."
)


class PexAlwaysWriteCacheField(BoolField):
alias = "always_write_cache"
default = False
Expand Down

0 comments on commit 1d4dc1b

Please sign in to comment.