[SPARK-50824][PYTHON] Avoid importing optional Python packages for checking #49500
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.
What changes were proposed in this pull request?
This PR proposes to avoid importing optional Python packages for checking, by using
importlib.util.find_spec
instead of actually loading/importing the package.Why are the changes needed?
a409199 changed to import optional dependencies in main code. After that, technically f223b8d broke the Python Spark Core tests, (because now we will import
pyspark.testing
, and it will import optional dependencies) but it did not run the tests.By importing
deepspeed
, via logger, it can show stdout (https://github.com/microsoft/DeepSpeed/blob/master/accelerator/real_accelerator.py#L182). This broke the test inpyspark.conf
. After that, the real test failure was found when core change was triggered at 6f3b778. In the PR, build passed because it was before f223b8d was merged.Does this PR introduce any user-facing change?
Technically yes. There might be some side effects by importing optional dependencies, and this PR avoid them.
How was this patch tested?
CI in this PR should verify it.
Was this patch authored or co-authored using generative AI tooling?
No.