-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24384][PYTHON][SPARK SUBMIT] Add .py files correctly into PythonRunner in submit with client mode in spark-submit #21426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package org.apache.spark.deploy | |
|
|
||
| import java.io.File | ||
| import java.net.{InetAddress, URI} | ||
| import java.nio.file.Files | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
| import scala.collection.mutable.ArrayBuffer | ||
|
|
@@ -48,7 +49,7 @@ object PythonRunner { | |
|
|
||
| // Format python file paths before adding them to the PYTHONPATH | ||
| val formattedPythonFile = formatPath(pythonFile) | ||
| val formattedPyFiles = formatPaths(pyFiles) | ||
| val formattedPyFiles = resolvePyFiles(formatPaths(pyFiles)) | ||
|
|
||
| // Launch a Py4J gateway server for the process to connect to; this will let it see our | ||
| // Java system properties and such | ||
|
|
@@ -153,4 +154,30 @@ object PythonRunner { | |
| .map { p => formatPath(p, testWindows) } | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the ".py" files. ".py" file should not be added as is because PYTHONPATH does | ||
| * not expect a file. This method creates a temporary directory and puts the ".py" files | ||
| * if exist in the given paths. | ||
| */ | ||
| private def resolvePyFiles(pyFiles: Array[String]): Array[String] = { | ||
| lazy val dest = Utils.createTempDir(namePrefix = "localPyFiles") | ||
| pyFiles.flatMap { pyFile => | ||
| // In case of client with submit, the python paths should be set before context | ||
| // initialization because the context initialization can be done later. | ||
| // We will copy the local ".py" files because ".py" file shouldn't be added | ||
| // alone but its parent directory in PYTHONPATH. See SPARK-24384. | ||
| if (pyFile.endsWith(".py")) { | ||
| val source = new File(pyFile) | ||
| if (source.exists() && source.canRead) { | ||
|
||
| Files.copy(source.toPath, new File(dest, source.getName).toPath) | ||
| Some(dest.getAbsolutePath) | ||
| } else { | ||
| // Don't have to add it if it doesn't exist or isn't readable. | ||
| None | ||
| } | ||
| } else { | ||
| Some(pyFile) | ||
| } | ||
| }.distinct | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we check if the file is existed or not, also if it is readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap