Back to home page

OSCL-LXR

 
 

    


0001 @echo off
0002 
0003 rem
0004 rem Licensed to the Apache Software Foundation (ASF) under one or more
0005 rem contributor license agreements.  See the NOTICE file distributed with
0006 rem this work for additional information regarding copyright ownership.
0007 rem The ASF licenses this file to You under the Apache License, Version 2.0
0008 rem (the "License"); you may not use this file except in compliance with
0009 rem the License.  You may obtain a copy of the License at
0010 rem
0011 rem    http://www.apache.org/licenses/LICENSE-2.0
0012 rem
0013 rem Unless required by applicable law or agreed to in writing, software
0014 rem distributed under the License is distributed on an "AS IS" BASIS,
0015 rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 rem See the License for the specific language governing permissions and
0017 rem limitations under the License.
0018 rem
0019 
0020 rem Path to Python script finding SPARK_HOME
0021 set FIND_SPARK_HOME_PYTHON_SCRIPT=%~dp0find_spark_home.py
0022 
0023 rem Default to standard python interpreter unless told otherwise
0024 set PYTHON_RUNNER=python
0025 rem If PYSPARK_DRIVER_PYTHON is set, it overwrites the python version
0026 if not "x%PYSPARK_DRIVER_PYTHON%"=="x" (
0027   set PYTHON_RUNNER=%PYSPARK_DRIVER_PYTHON%
0028 )
0029 rem If PYSPARK_PYTHON is set, it overwrites the python version
0030 if not "x%PYSPARK_PYTHON%"=="x" (
0031   set PYTHON_RUNNER=%PYSPARK_PYTHON%
0032 )
0033 
0034 rem If there is python installed, trying to use the root dir as SPARK_HOME
0035 where %PYTHON_RUNNER% > nul 2>&1
0036 if %ERRORLEVEL% neq 0 (
0037   if not exist %PYTHON_RUNNER% (
0038     if "x%SPARK_HOME%"=="x" (
0039       echo Missing Python executable '%PYTHON_RUNNER%', defaulting to '%~dp0..' for SPARK_HOME ^
0040 environment variable. Please install Python or specify the correct Python executable in ^
0041 PYSPARK_DRIVER_PYTHON or PYSPARK_PYTHON environment variable to detect SPARK_HOME safely.
0042       set SPARK_HOME=%~dp0..
0043     )
0044   )
0045 )
0046 
0047 rem Only attempt to find SPARK_HOME if it is not set.
0048 if "x%SPARK_HOME%"=="x" (
0049   if not exist "%FIND_SPARK_HOME_PYTHON_SCRIPT%" (
0050     rem If we are not in the same directory as find_spark_home.py we are not pip installed so we don't
0051     rem need to search the different Python directories for a Spark installation.
0052     rem Note only that, if the user has pip installed PySpark but is directly calling pyspark-shell or
0053     rem spark-submit in another directory we want to use that version of PySpark rather than the
0054     rem pip installed version of PySpark.
0055     set SPARK_HOME=%~dp0..
0056   ) else (
0057     rem We are pip installed, use the Python script to resolve a reasonable SPARK_HOME
0058     for /f "delims=" %%i in ('%PYTHON_RUNNER% %FIND_SPARK_HOME_PYTHON_SCRIPT%') do set SPARK_HOME=%%i
0059   )
0060 )