Repository: pantsbuild/pants

Issue:
Deprecate Pex options now deprecated in Pex 2.1.48
Pex 2.1.48 deprecates `--unzip`, `--zip-safe` and `--always-write-cache`. In the upgrade to Pex 2.1.48, the options are no longer passed to Pex but the target level fields in Pants remain:
+ PexExecutionMode.UNZIP for PexExecutionModeField
+ PexZipSafeField
+ PexAlwaysWriteCacheField

These fields should be deprecated in a follow-up to the Pex 2.1.48 upgrade.


Discussion:
Ok, landing this with the upgrade instead in #12808.

Resolving patch:
diff --git a/src/python/pants/backend/python/goals/package_pex_binary.py b/src/python/pants/backend/python/goals/package_pex_binary.py
--- a/src/python/pants/backend/python/goals/package_pex_binary.py
+++ b/src/python/pants/backend/python/goals/package_pex_binary.py
@@ -7,7 +7,6 @@
 
 from pants.backend.python.subsystems.setup import PythonSetup
 from pants.backend.python.target_types import (
-    PexAlwaysWriteCacheField,
     PexBinaryDefaults,
     PexEmitWarningsField,
     PexEntryPointField,
@@ -22,7 +21,6 @@
     PexScriptField,
     PexShebangField,
     PexStripEnvField,
-    PexZipSafeField,
     PythonResolveField,
     ResolvedPexEntryPoint,
     ResolvePexEntryPointRequest,
@@ -58,12 +56,10 @@ class PexBinaryFieldSet(PackageFieldSet, RunFieldSet):
     script: PexScriptField
 
     output_path: OutputPathField
-    always_write_cache: PexAlwaysWriteCacheField
     emit_warnings: PexEmitWarningsField
     ignore_errors: PexIgnoreErrorsField
     inherit_path: PexInheritPathField
     shebang: PexShebangField
-    zip_safe: PexZipSafeField
     strip_env: PexStripEnvField
     platforms: PythonPlatformsField
     execution_mode: PexExecutionModeField
diff --git a/src/python/pants/backend/python/target_types.py b/src/python/pants/backend/python/target_types.py
--- a/src/python/pants/backend/python/target_types.py
+++ b/src/python/pants/backend/python/target_types.py
@@ -12,7 +12,6 @@
 from textwrap import dedent
 from typing import (
     TYPE_CHECKING,
-    Any,
     ClassVar,
     Iterable,
     Iterator,
@@ -29,7 +28,6 @@
 from pants.backend.python.macros.python_artifact import PythonArtifact
 from pants.backend.python.pip_requirement import PipRequirement
 from pants.backend.python.subsystems.setup import PythonSetup
-from pants.base.deprecated import warn_or_error
 from pants.core.goals.package import OutputPathField
 from pants.core.goals.run import RestartableField
 from pants.core.goals.test import RuntimePackageDependenciesField
@@ -377,22 +375,6 @@ def compute_value(
         return super().compute_value(raw_value, address)
 
 
-# TODO(John Sirois): Deprecate: https://github.com/pantsbuild/pants/issues/12803
-class PexZipSafeField(BoolField):
-    alias = "zip_safe"
-    default = True
-    help = (
-        "Whether or not this binary is safe to run in compacted (zip-file) form.\n\nIf the PEX is "
-        "not zip safe, it will be written to disk prior to execution. You may need to mark "
-        "`zip_safe=False` if you're having issues loading your code."
-    )
-    removal_version = "2.9.0.dev0"
-    removal_hint = (
-        "All PEX binaries now unpack your code to disk prior to first execution; so this option no "
-        "longer needs to be specified."
-    )
-
-
 class PexStripEnvField(BoolField):
     alias = "strip_pex_env"
     default = True
@@ -406,21 +388,6 @@ class PexStripEnvField(BoolField):
     )
 
 
-class PexAlwaysWriteCacheField(BoolField):
-    alias = "always_write_cache"
-    default = False
-    help = (
-        "Whether PEX should always write the .deps cache of the .pex file to disk or not. This "
-        "can use less memory in RAM-constrained environments."
-    )
-    removal_version = "2.9.0.dev0"
-    removal_hint = (
-        "This option never had any effect when passed to Pex and the Pex option is now removed "
-        "altogether. PEXes always write all their internal dependencies out to disk as part of "
-        "first execution bootstrapping."
-    )
-
-
 class PexIgnoreErrorsField(BoolField):
     alias = "ignore_errors"
     default = False
@@ -452,7 +419,6 @@ def value_or_global_default(self, pex_binary_defaults: PexBinaryDefaults) -> boo
 
 class PexExecutionMode(Enum):
     ZIPAPP = "zipapp"
-    UNZIP = "unzip"
     VENV = "venv"
 
 
@@ -470,25 +436,9 @@ class PexExecutionModeField(StringField):
         f"the steady state is {PexExecutionMode.VENV.value!r}, which generates a virtual "
         "environment from the PEX file on first run, but then achieves near native virtual "
         "environment start times. This mode also benefits from a traditional virtual environment "
-        "`sys.path`, giving maximum compatibility with stdlib and third party APIs.\n\nThe "
-        f"{PexExecutionMode.UNZIP.value!r} mode is deprecated since the default "
-        f"{PexExecutionMode.ZIPAPP.value!r} mode now executes this way."
+        "`sys.path`, giving maximum compatibility with stdlib and third party APIs."
     )
 
-    @classmethod
-    def _check_deprecated(cls, raw_value: Optional[Any], address_: Address) -> None:
-        if PexExecutionMode.UNZIP.value == raw_value:
-            warn_or_error(
-                removal_version="2.9.0.dev0",
-                entity=f"the {cls.alias!r} field {PexExecutionMode.UNZIP.value!r} value",
-                hint=(
-                    f"The {PexExecutionMode.UNZIP.value!r} mode is now the default PEX execution "
-                    "mode; so you can remove this field setting or explicitly choose the default "
-                    f"of {PexExecutionMode.ZIPAPP.value!r} and get the same benefits you already "
-                    "enjoy from this mode."
-                ),
-            )
-
 
 class PexIncludeToolsField(BoolField):
     alias = "include_tools"
@@ -512,9 +462,7 @@ class PexBinary(Target):
         PexScriptField,
         PexPlatformsField,
         PexInheritPathField,
-        PexZipSafeField,
         PexStripEnvField,
-        PexAlwaysWriteCacheField,
         PexIgnoreErrorsField,
         PexShebangField,
         PexEmitWarningsField,


Test patch:
diff --git a/src/python/pants/backend/python/goals/run_pex_binary_integration_test.py b/src/python/pants/backend/python/goals/run_pex_binary_integration_test.py
--- a/src/python/pants/backend/python/goals/run_pex_binary_integration_test.py
+++ b/src/python/pants/backend/python/goals/run_pex_binary_integration_test.py
@@ -15,9 +15,9 @@
 @pytest.mark.parametrize(
     ("entry_point", "execution_mode", "include_tools"),
     [
-        ("app.py", PexExecutionMode.UNZIP, True),
-        ("app.py", PexExecutionMode.VENV, True),
-        ("app.py:main", PexExecutionMode.ZIPAPP, False),
+        ("app.py", None, True),
+        ("app.py", PexExecutionMode.VENV, False),
+        ("app.py:main", PexExecutionMode.ZIPAPP, True),
         ("app.py:main", None, False),
     ],
 )