LorenzoMartini opened a new pull request, #60244:
URL: https://github.com/apache/spark/pull/60244

   ### What changes were proposed in this pull request?
   
   Use `sys.implementation.name == "pypy"` to detect PyPy in the vendored 
cloudpickle module, and remove the unused `platform` import.
   
   ### Why are the changes needed?
   
   Some Python distributions ship a `sys.version` string containing an 
additional `packaged by ...` note. For example, a version banner can have this 
form:
   
   ```text
   3.12.0 | packaged by example | (main, Oct 2 2023, 12:00:00) [GCC 12.2.0]
   ```
   
   `platform.python_implementation()` calls a helper that parses the full 
version banner. If the parser does not recognize the additional text, it raises 
`ValueError`, causing PySpark to fail during import even though the interpreter 
itself is supported.
   
   `sys.implementation.name` provides the interpreter's identifier directly, 
without parsing build metadata. Its value is lowercase (`"cpython"` or 
`"pypy"`) and the API has been available since Python 3.3, before any Python 
version supported by this Spark branch. This preserves the existing 
PyPy-specific behavior while avoiding dependence on the formatting of 
`sys.version`.
   
   See the [Python 
documentation](https://docs.python.org/3/library/sys.html#sys.implementation) 
and [PEP 421](https://peps.python.org/pep-0421/#platform-python-implementation).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. PySpark can import and use cloudpickle when a vendor-branded Python 
version string would otherwise cause implementation detection to raise 
`ValueError`. There are no public API changes.
   
   ### How was this patch tested?
   
   Added a regression test that starts a fresh Python process, inserts a 
generic `packaged by example` note into its real version banner, then imports 
cloudpickle and round-trips a lambda. A fresh process ensures a previously 
cached import cannot hide the failure. The test fails with the original 
implementation and passes with this change.
   
   The following serialization and import tests pass on CPython 3.13.13 (12 
tests):
   
   ```bash
   SPARK_SKIP_CONNECT_COMPAT_TESTS=1 python/run-tests \
     --python-executables=python \
     --testnames 'pyspark.tests.test_serializers SerializationTestCase 
SerializersTest,pyspark.tests.test_import_spark' \
     --parallelism 1
   ```
   
   The interpreter was selected through an activated virtual environment. Ruff 
lint and formatting checks and `git diff --check` pass. JVM-dependent tests and 
a PyPy runtime were not run.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex CLI 0.154.0
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to