Repository navigation
feat!: Move PySpark dependencies into [client] and [spark] extras - #202
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces interactive extras for the google-cloud-spark-connect package, including support for %dpip and %%sparksql magics in Jupyter notebooks, along with improved dependency management and installation options. The reviewer provided several constructive suggestions to improve memory management by using weak references for shell states, simplifying token identification in the SQL parser, and optimizing performance by caching dynamically resolved classes. All review comments were kept as they provide actionable improvements.
dborowitz
force-pushed
the
spark-extras
branch
from
October 14, 2026 17:47
bcf5177 to
4e22bbd
Compare
medb
approved these changes
Oct 15, 2026
pyspark is an ~800 MB install that most Spark Connect users do not need, while pyspark-client is a lightweight (~2 MB) pure-Python Spark Connect client. However, pyspark and pyspark-client write to the same pyspark module directory, so installing both in a single environment risks immediate version skew or broken imports if either package is later uninstalled. Because Python package extras are strictly additive, move the Spark dependency out of install_requires into two mutually exclusive extras: - [client]: depends on pyspark-client~=4.0.0 - [spark]: depends on pyspark[connect]~=4.0.0 - no Spark extra: relies on whichever pyspark provider is already present in the environment If pyspark is missing or incomplete (such as a leftover pyspark/ directory after uninstalling one of the two packages) when google.cloud.managed_spark_connect is imported, raise PySparkNotInstalledError recommending google-cloud-spark-connect[client,interactive] when inside an IPython shell, or google-cloud-spark-connect[client] otherwise. It subclasses both ManagedSparkConnectException and ImportError, so existing `except ImportError` guards keep working. As install_requires no longer pins pyspark, also reject a pyspark older than 4.0 on import with UnsupportedPySparkVersionError, a PySparkNotInstalledError subclass, recommending an in-place upgrade via [spark]. %%sparksql gives the same install hint when pyspark is missing. Update README.md to recommend [client,interactive] as the primary installation command and [spark,interactive] when upgrading an existing dataproc-spark-connect environment in-place. Switch requirements-dev.txt to pyspark-client~=4.0.0, and document how to switch a dev environment to full pyspark. CI runs unit tests against each of the [client] and [spark] extras; the local Spark tests need a JVM, so they only run against [spark]. BREAKING CHANGE: pyspark[connect] is no longer installed by default. Install google-cloud-spark-connect[client] (or [client,interactive] for notebooks), google-cloud-spark-connect[spark], or provide pyspark / pyspark-client in the environment. Release-As: 2.0.0
dborowitz
force-pushed
the
spark-extras
branch
from
October 15, 2026 22:29
4e22bbd to
21cb40e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pyspark is an ~800 MB install that most Spark Connect users do not need, while pyspark-client is a lightweight (~2 MB) pure-Python Spark Connect client. However, pyspark and pyspark-client write to the same pyspark module directory, so installing both in a single environment risks immediate version skew or broken imports if either package is later uninstalled. Because Python package extras are strictly additive, move the Spark dependency out of install_requires into two mutually exclusive extras:
If pyspark is missing or incomplete (such as a leftover pyspark/ directory after uninstalling one of the two packages) when google.cloud.managed_spark_connect is imported, raise PySparkNotInstalledError recommending google-cloud-spark-connect[client,interactive] when inside an IPython shell, or google-cloud-spark-connect[client] otherwise. It subclasses both ManagedSparkConnectException and ImportError, so existing
except ImportErrorguards keep working. As install_requires no longer pins pyspark, also reject a pyspark older than 4.0 on import with UnsupportedPySparkVersionError, a PySparkNotInstalledError subclass, recommending an in-place upgrade via [spark]. %%sparksql gives the same install hint when pyspark is missing.Update README.md to recommend [client,interactive] as the primary installation command and [spark,interactive] when upgrading an existing dataproc-spark-connect environment in-place. Switch requirements-dev.txt to pyspark-client~=4.0.0, and document how to switch a dev environment to full pyspark. CI runs unit tests against each of the [client] and [spark] extras; the local Spark tests need a JVM, so they only run against [spark].
BREAKING CHANGE: pyspark[connect] is no longer installed by default. Install google-cloud-spark-connect[client] (or [client,interactive] for notebooks), google-cloud-spark-connect[spark], or provide pyspark / pyspark-client in the environment.
Release-As: 2.0.0