Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/5408#discussion_r30831455
--- Diff: python/pyspark/context.py ---
@@ -693,23 +701,71 @@ def clearFiles(self):
Clear the job's list of files added by L{addFile} or L{addPyFile}
so
that they do not get downloaded to any new nodes.
"""
- # TODO: remove added .py or .zip files from the PYTHONPATH?
+ # TODO: remove added .py, .whl, .egg or .zip files from the
PYTHONPATH?
self._jsc.sc().clearFiles()
def addPyFile(self, path):
"""
- Add a .py or .zip dependency for all tasks to be executed on this
- SparkContext in the future. The C{path} passed can be either a
local
- file, a file in HDFS (or other Hadoop-supported filesystems), or an
- HTTP, HTTPS or FTP URI.
+ Add a .py, .whl, .egg or .zip dependency for all tasks to be
+ executed on this SparkContext in the future. The C{path} passed
can
+ be either a local file, a file in HDFS (or other Hadoop-supported
+ filesystems), or an HTTP, HTTPS or FTP URI.
"""
self.addFile(path)
- (dirname, filename) = os.path.split(path) # dirname may be
directory or HDFS/S3 prefix
+ self._include_python_packages(paths=(path,))
+ self._install_wheel_files(paths=(path,))
- if filename[-4:].lower() in self.PACKAGE_EXTENSIONS:
- self._python_includes.append(filename)
- # for tests in local mode
- sys.path.insert(1, os.path.join(SparkFiles.getRootDirectory(),
filename))
+ def _include_python_packages(self, paths):
+ """
+ Add Python package dependencies. Python packages (except for .whl)
are
+ added to PYTHONPATH.
+ """
+ root_dir = SparkFiles.getRootDirectory()
+ for path in paths:
+ basename = os.path.basename(path)
+ extname = os.path.splitext(basename)[1].lower()
+ if extname in self.PACKAGE_EXTENSIONS \
+ and basename not in self._python_includes:
+ self._python_includes.append(basename)
+ if extname != '.whl':
+ # Prepend the python package (except for *.whl) to
sys.path
+ sys.path.insert(1, os.path.join(root_dir, basename))
+
+ def _install_wheel_files(
+ self,
--- End diff --
Could you change this to match the style with others?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]