Repository: pantsbuild/pants

Issue:
detect older versions of scie-pants and emit deprecation warning if too old
With the source of truth for Pants releases moving to GitHub from PyPi, `scie-pants` will need to be upgraded to v0.9.x(?) in order to consume GitHub releases. To help inform users, we should consider having Pants detect the scie-pants versions it is running under and emit a deprecation warning to inform the user about the need to upgrade.


Discussion:
I'm going to add this to 2.17.x unless we decide otherwise so that it doesn't slip through the cracks.
@thejcannon suggests a good place to start for this would be: https://github.com/pantsbuild/pants/blob/06321e5edf3f648f39f0abc7b11d348181a15a31/src/python/pants/bin/pants_runner.py#L83

I'll see if I have time for this later today.

Resolving patch:
diff --git a/src/python/pants/bin/pants_runner.py b/src/python/pants/bin/pants_runner.py
--- a/src/python/pants/bin/pants_runner.py
+++ b/src/python/pants/bin/pants_runner.py
@@ -8,6 +8,8 @@
 from dataclasses import dataclass
 from typing import List, Mapping
 
+from packaging.version import Version
+
 from pants.base.deprecated import warn_or_error
 from pants.base.exception_sink import ExceptionSink
 from pants.base.exiter import ExitCode
@@ -21,6 +23,10 @@
 
 logger = logging.getLogger(__name__)
 
+# Pants 2.18 is using a new distribution model, that's only supported in 0.9.0 (this is 0.9.2,
+# because _detecting_ the version is only supported from 0.9.2), so people should upgrade
+MINIMUM_SCIE_PANTS_VERSION = Version("0.9.2")
+
 
 @dataclass(frozen=True)
 class PantsRunner:
@@ -83,7 +89,11 @@ def run(self, start_time: float) -> ExitCode:
         ):
             # N.B. We inline imports to speed up the python thin client run, and avoids importing
             # engine types until after the runner has had a chance to set __PANTS_BIN_NAME.
-            if "SCIE" not in os.environ and "NO_SCIE_WARNING" not in os.environ:
+            run_via_scie = "SCIE" in os.environ
+            enable_scie_warning = "NO_SCIE_WARNING" not in os.environ
+            scie_pants_version = os.environ.get("SCIE_PANTS_VERSION")
+
+            if not run_via_scie and enable_scie_warning:
                 warn_or_error(
                     "2.18.0.dev0",
                     f"Running Pants in an external Python interpreter via a `{bin_name()}` script",
@@ -95,6 +105,27 @@ def run(self, start_time: float) -> ExitCode:
                     ),
                 )
 
+            if run_via_scie and (
+                # either scie-pants is too old to communicate its version:
+                scie_pants_version is None
+                # or the version itself is too old:
+                or Version(scie_pants_version) < MINIMUM_SCIE_PANTS_VERSION
+            ):
+                current_version_text = (
+                    f"The current version of the `pants` launcher binary is {scie_pants_version}"
+                    if scie_pants_version
+                    else "Run `PANTS_BOOTSTRAP_VERSION=report pants` to see the current version of the `pants` launcher binary"
+                )
+                warn_or_error(
+                    "2.18.0.dev6",
+                    f"using a `pants` launcher binary older than {MINIMUM_SCIE_PANTS_VERSION}",
+                    softwrap(
+                        f"""
+                        {current_version_text}, and see {doc_url("installation")} for how to upgrade.
+                        """
+                    ),
+                )
+
             if self._should_run_with_pantsd(global_bootstrap_options):
                 from pants.bin.remote_pants_runner import RemotePantsRunner
 


Test patch: