File tree Expand file tree Collapse file tree 1 file changed +2
-28
lines changed Expand file tree Collapse file tree 1 file changed +2
-28
lines changed Original file line number Diff line number Diff line change 18
18
import os
19
19
import sys
20
20
import signal
21
+ import shlex
21
22
import platform
22
23
from subprocess import Popen , PIPE
23
24
from threading import Thread
@@ -35,7 +36,7 @@ def launch_gateway():
35
36
on_windows = platform .system () == "Windows"
36
37
script = "./bin/spark-submit.cmd" if on_windows else "./bin/spark-submit"
37
38
submit_args = os .environ .get ("PYSPARK_SUBMIT_ARGS" )
38
- submit_args = split_preserve_quotes (submit_args )
39
+ submit_args = shlex . split (submit_args )
39
40
command = [os .path .join (SPARK_HOME , script ), "pyspark-shell" ] + submit_args
40
41
if not on_windows :
41
42
# Don't send ctrl-c / SIGINT to the Java gateway:
@@ -76,30 +77,3 @@ def run(self):
76
77
java_import (gateway .jvm , "scala.Tuple2" )
77
78
78
79
return gateway
79
-
80
- def split_preserve_quotes (args ):
81
- """
82
- Given a string of space-delimited arguments with quotes,
83
- split it into a list while preserving the quote boundaries.
84
- """
85
- if args is None :
86
- return []
87
- split_list = []
88
- quoted_string = ""
89
- wait_for_quote = False
90
- for arg in args .split (" " ):
91
- if not wait_for_quote :
92
- if arg .startswith ("\" " ):
93
- wait_for_quote = True
94
- quoted_string = arg
95
- else :
96
- split_list .append (arg )
97
- else :
98
- quoted_string += " " + arg
99
- if quoted_string .endswith ("\" " ):
100
- # Strip quotes
101
- quoted_string = quoted_string [1 :- 1 ]
102
- split_list .append (quoted_string )
103
- quoted_string = ""
104
- wait_for_quote = False
105
- return split_list
You can’t perform that action at this time.
0 commit comments