[SPARK-54434][PYTHON] Use return instead of exit in bin/find-spark-home short-circuit#55817
Open
1fanwang wants to merge 3 commits into
Open
[SPARK-54434][PYTHON] Use return instead of exit in bin/find-spark-home short-circuit#558171fanwang wants to merge 3 commits into
1fanwang wants to merge 3 commits into
Conversation
…me short-circuit bin/find-spark-home is documented to be sourced. When SPARK_HOME is already set, the short-circuit calls exit 0, which terminates the caller's shell session if the script is sourced twice (e.g. by accident or by repeated shell setup). Use return 0 with an exit 0 fallback so the script works correctly whether sourced (the documented path) or executed.
Signed-off-by: 1fanwang <1fannnw@gmail.com>
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.
What changes were proposed in this pull request?
bin/find-spark-homeis documented as# Should be included using "source" directive, but itsSPARK_HOME-already-set short-circuit callsexit 0. When the script is sourced, that terminates the caller's shell. This PR replacesexit 0withreturn 0 2>/dev/null || exit 0so the script behaves correctly when sourced (the documented path) and still works if executed directly.A pyspark unit test (
test_find_spark_home_script_sourceable) sources the script twice from a subshell and asserts a marker prints after — the test fails on master and passes with this change.Why are the changes needed?
bin/find-spark-homeis sourced bybin/load-spark-env.shand by user shell setup. As reported on SPARK-54434, if a user accidentally sourcesbin/find-spark-hometwice in the same shell, the second invocation hits the short-circuit andexit 0closes the interactive shell session.Reproducer:
Does this PR introduce any user-facing change?
No. Users who source
bin/find-spark-homeno longer lose their shell on the short-circuit path; users who execute it directly see no behavior change.How was this patch tested?
Added
pyspark.tests.test_util.UtilTests.test_find_spark_home_script_sourceable, which sources the script twice from a bash subprocess and asserts a marker prints after the second source. The test fails onmaster(the marker is never emitted becauseexit 0terminates the subshell) and passes with this change.Was this patch authored or co-authored using generative AI tooling?
No