Skip to content

Commit 9ae7752

Browse files
authored
plumb through Pex's --check zipapp validation (#20481)
Pex exposes the `--check` flag to "check" if the resulting zipapp can be opened by CPython. Plumb that through so that Pants stops making PEXs that won't work at runtime. ref #19957
1 parent 90b5bc3 commit 9ae7752

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/python/pants/backend/python/goals/package_pex_binary.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pants.backend.python.target_types import (
99
PexArgsField,
1010
PexBinaryDefaults,
11+
PexCheckField,
1112
PexCompletePlatformsField,
1213
PexEmitWarningsField,
1314
PexEntryPointField,
@@ -79,6 +80,7 @@ class PexBinaryFieldSet(PackageFieldSet, RunFieldSet):
7980
venv_site_packages_copies: PexVenvSitePackagesCopies
8081
venv_hermetic_scripts: PexVenvHermeticScripts
8182
environment: EnvironmentField
83+
check: PexCheckField
8284

8385
@property
8486
def _execution_mode(self) -> PexExecutionMode:
@@ -96,6 +98,8 @@ def generate_additional_args(self, pex_binary_defaults: PexBinaryDefaults) -> Tu
9698
args.append(f"--inherit-path={self.inherit_path.value}")
9799
if self.sh_boot.value is True:
98100
args.append("--sh-boot")
101+
if self.check.value is not None:
102+
args.append(f"--check={self.check.value}")
99103
if self.shebang.value is not None:
100104
args.append(f"--python-shebang={self.shebang.value}")
101105
if self.strip_env.value is False:

src/python/pants/backend/python/target_types.py

+19
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ class PexArgsField(StringSequenceField):
381381
)
382382

383383

384+
class PexCheckField(StringField):
385+
alias = "check"
386+
valid_choices = ("none", "warn", "error")
387+
expected_type = str
388+
default = "warn"
389+
help = help_text(
390+
"""
391+
Check that the built PEX is valid. Currently this only
392+
applies to `--layout zipapp` where the PEX zip is
393+
tested for importability of its `__main__` module by
394+
the Python zipimport module. This check will fail for
395+
PEX zips that use ZIP64 extensions since the Python
396+
zipimport zipimporter only works with 32 bit zips. The
397+
check no-ops for all other layouts.
398+
"""
399+
)
400+
401+
384402
class PexEnvField(DictStringToStringField):
385403
alias = "env"
386404
help = help_text(
@@ -697,6 +715,7 @@ class PexVenvHermeticScripts(BoolField):
697715
InterpreterConstraintsField,
698716
PythonResolveField,
699717
PexBinaryDependenciesField,
718+
PexCheckField,
700719
PexPlatformsField,
701720
PexCompletePlatformsField,
702721
PexResolveLocalPlatformsField,

src/python/pants/backend/python/util_rules/pex_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PexCli(TemplatedExternalTool):
3737

3838
default_version = "v2.1.163"
3939
default_url_template = "https://github.com/pantsbuild/pex/releases/download/{version}/pex"
40-
version_constraints = ">=2.1.135,<3.0"
40+
version_constraints = ">=2.1.148,<3.0"
4141

4242
@classproperty
4343
def default_known_versions(cls):

0 commit comments

Comments
 (0)