spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zjffdu <...@git.apache.org>
Subject [GitHub] spark pull request #14180: [SPARK-16367][PYSPARK] Wheelhouse and VirtualEnv ...
Date Tue, 23 Aug 2016 08:37:07 GMT
Github user zjffdu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14180#discussion_r75823127
  
    --- Diff: core/src/main/scala/org/apache/spark/api/python/PythonWorkerFactory.scala ---
    @@ -68,6 +100,135 @@ private[spark] class PythonWorkerFactory(pythonExec: String, envVars:
Map[String
         }
       }
     
    +
    +  def unzipWheelhouse(zipFile: String, outputFolder: String): Unit = {
    +
    +    val buffer = new Array[Byte](1024)
    +
    +    try {
    +
    +      // output directory
    +      val folder = new File(outputFolder);
    +      if (!folder.exists()) {
    +        folder.mkdir();
    +      }
    +
    +      // zip file content
    +      val zis: ZipInputStream = new ZipInputStream(new FileInputStream(zipFile));
    +      // get the zipped file list entry
    +      var ze: ZipEntry = zis.getNextEntry();
    +
    +      while (ze != null) {
    +        breakable {
    +
    +          if (ze.isDirectory()) {
    +            // continue
    +            break;
    +          }
    +
    +          val fileName = ze.getName();
    +          val newFile = new File(outputFolder + File.separator + fileName);
    +
    +          logDebug("file unzip : " + newFile.getAbsoluteFile());
    +
    +          // create folders
    +          new File(newFile.getParent()).mkdirs();
    +
    +          val fos = new FileOutputStream(newFile);
    +
    +          var len: Int = zis.read(buffer);
    +
    +          while (len > 0) {
    +
    +            fos.write(buffer, 0, len)
    +            len = zis.read(buffer)
    +          }
    +
    +          fos.close()
    +        }
    +        ze = zis.getNextEntry()
    +      }
    +
    +      zis.closeEntry()
    +      zis.close()
    +
    +    } catch {
    +      case e: IOException => logError("exception caught: " + e.getMessage)
    +    }
    +
    +  }
    +
    +  /**
    +   * Create virtualenv using native virtualenv or conda
    +   *
    +   * Native Virtualenv:
    +   *   -  Execute command: virtualenv -p pythonExec --no-site-packages virtualenvName
    +   *   -  if wheelhouse specified:
    +   *        - Execute command: python -m pip --cache-dir cache-dir install -r requirement_file.txt
    +   *      else:
    +   *        - Execute command: python -m pip --cache-dir cache-dir install --use-wheel
\
    +   *                                  --no-index --find-links=wheelhouse -r requirement_file.txt
    +   *
    +   * Conda
    +   *   -  Execute command: conda create --name virtualenvName --file requirement_file.txt
-y
    +   *
    +   */
    +  def setupVirtualEnv(): Unit = {
    +    logDebug("Start to setup virtualenv...")
    +    virtualEnvName = "virtualenv_" + conf.getAppId + "_" + WORKER_Id.getAndIncrement()
    +    // use the absolute path when it is local mode otherwise just use filename as it
would be
    +    // fetched from FileServer
    +    val pyspark_requirements =
    +      if (Utils.isLocalMaster(conf)) {
    +        virtualRequirements
    +      } else {
    +        virtualRequirements.split("/").last
    +      }
    +
    +    val createEnvCommand =
    +      if (virtualEnvType == "native") {
    +        if (virtualEnvSystemSitePackages) {
    +          Arrays.asList(virtualEnvPath, "-p", pythonExec, "--system-site-packages", virtualEnvName)
    +        }
    +        else {
    +          Arrays.asList(virtualEnvPath, "-p", pythonExec, virtualEnvName)
    +        }
    +      } else {
    +        // Conda
    +        Arrays.asList(virtualEnvPath,
    +          "create", "--prefix", System.getProperty("user.dir") + "/" + virtualEnvName,
    +          "--file", pyspark_requirements, "-y")
    +      }
    +    execCommand(createEnvCommand)
    +    // virtualenv will be created in the working directory of Executor.
    +    virtualPythonExec = virtualEnvName + "/bin/python"
    +    if (virtualEnvType == "native") {
    +      var basePipArgs = mutable.ListBuffer[String]()
    +      basePipArgs += (virtualPythonExec, "-m", "pip", "install", "-r", pyspark_requirements)
    +      if (!virtualWheelhouse.isEmpty) {
    +        unzipWheelhouse("wheelhouse.zip", "wheelhouse")
    --- End diff --
    
    wheelhouse.zip is hard coded, it's better to specify it through configuration rather than
hard code it and add it through --files. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message