parameters: (environ_cp)
docstring: Setup python related env variables.
docstring_summary: Setup python related env variables.
docstring_tokens: Setup python related env variables .
function: def setup_python(environ_cp):
    """Setup python related env variables."""
    # Get PYTHON_BIN_PATH, default is the current running python.
    default_python_bin_path = sys.executable
    ask_python_bin_path = ('Please specify the location of python. [Default is '
                           '%s]: ') % default_python_bin_path
    while True:
      python_bin_path = get_from_env_or_user_or_default(
          environ_cp, 'PYTHON_BIN_PATH', ask_python_bin_path,
          default_python_bin_path)
      # Check if the path is valid
      if os.path.isfile(python_bin_path) and os.access(python_bin_path, os.X_OK):
        break
      elif not os.path.exists(python_bin_path):
        print('Invalid python path: %s cannot be found.' % python_bin_path)
      else:
        print('%s is not executable.  Is it the python binary?' % python_bin_path)
      environ_cp['PYTHON_BIN_PATH'] = ''
  
    # Convert python path to Windows style before checking lib and version
    if is_windows() or is_cygwin():
      python_bin_path = cygpath(python_bin_path)
  
    # Get PYTHON_LIB_PATH
    python_lib_path = environ_cp.get('PYTHON_LIB_PATH')
    if not python_lib_path:
      python_lib_paths = get_python_path(environ_cp, python_bin_path)
      if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':
        python_lib_path = python_lib_paths[0]
      else:
        print('Found possible Python library paths:\n  %s' %
              '\n  '.join(python_lib_paths))
        default_python_lib_path = python_lib_paths[0]
        python_lib_path = get_input(
            'Please input the desired Python library path to use.  '
            'Default is [%s]\n' % python_lib_paths[0])
        if not python_lib_path:
          python_lib_path = default_python_lib_path
      environ_cp['PYTHON_LIB_PATH'] = python_lib_path
  
    _ = get_python_major_version(python_bin_path)
  
    # Convert python path to Windows style before writing into bazel.rc
    if is_windows() or is_cygwin():
      python_lib_path = cygpath(python_lib_path)
  
    # Set-up env variables used by python_configure.bzl
    write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path)
    write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path)
    write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
    environ_cp['PYTHON_BIN_PATH'] = python_bin_path
  
    # If choosen python_lib_path is from a path specified in the PYTHONPATH
    # variable, need to tell bazel to include PYTHONPATH
    if environ_cp.get('PYTHONPATH'):
      python_paths = environ_cp.get('PYTHONPATH').split(':')
      if python_lib_path in python_paths:
        write_action_env_to_bazelrc('PYTHONPATH', environ_cp.get('PYTHONPATH'))
  
    # Write tools/python_bin_path.sh
    with open(
        os.path.join(_TF_WORKSPACE_ROOT, 'tools', 'python_bin_path.sh'),
        'w') as f:
      f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
function_tokens: def setup_python ( environ_cp ) : # Get PYTHON_BIN_PATH, default is the current running python. default_python_bin_path = sys . executable ask_python_bin_path = ( 'Please specify the location of python. [Default is ' '%s]: ' ) % default_python_bin_path while True : python_bin_path = get_from_env_or_user_or_default ( environ_cp , 'PYTHON_BIN_PATH' , ask_python_bin_path , default_python_bin_path ) # Check if the path is valid if os . path . isfile ( python_bin_path ) and os . access ( python_bin_path , os . X_OK ) : break elif not os . path . exists ( python_bin_path ) : print ( 'Invalid python path: %s cannot be found.' % python_bin_path ) else : print ( '%s is not executable.  Is it the python binary?' % python_bin_path ) environ_cp [ 'PYTHON_BIN_PATH' ] = '' # Convert python path to Windows style before checking lib and version if is_windows ( ) or is_cygwin ( ) : python_bin_path = cygpath ( python_bin_path ) # Get PYTHON_LIB_PATH python_lib_path = environ_cp . get ( 'PYTHON_LIB_PATH' ) if not python_lib_path : python_lib_paths = get_python_path ( environ_cp , python_bin_path ) if environ_cp . get ( 'USE_DEFAULT_PYTHON_LIB_PATH' ) == '1' : python_lib_path = python_lib_paths [ 0 ] else : print ( 'Found possible Python library paths:\n  %s' % '\n  ' . join ( python_lib_paths ) ) default_python_lib_path = python_lib_paths [ 0 ] python_lib_path = get_input ( 'Please input the desired Python library path to use.  ' 'Default is [%s]\n' % python_lib_paths [ 0 ] ) if not python_lib_path : python_lib_path = default_python_lib_path environ_cp [ 'PYTHON_LIB_PATH' ] = python_lib_path _ = get_python_major_version ( python_bin_path ) # Convert python path to Windows style before writing into bazel.rc if is_windows ( ) or is_cygwin ( ) : python_lib_path = cygpath ( python_lib_path ) # Set-up env variables used by python_configure.bzl write_action_env_to_bazelrc ( 'PYTHON_BIN_PATH' , python_bin_path ) write_action_env_to_bazelrc ( 'PYTHON_LIB_PATH' , python_lib_path ) write_to_bazelrc ( 'build --python_path=\"%s"' % python_bin_path ) environ_cp [ 'PYTHON_BIN_PATH' ] = python_bin_path # If choosen python_lib_path is from a path specified in the PYTHONPATH # variable, need to tell bazel to include PYTHONPATH if environ_cp . get ( 'PYTHONPATH' ) : python_paths = environ_cp . get ( 'PYTHONPATH' ) . split ( ':' ) if python_lib_path in python_paths : write_action_env_to_bazelrc ( 'PYTHONPATH' , environ_cp . get ( 'PYTHONPATH' ) ) # Write tools/python_bin_path.sh with open ( os . path . join ( _TF_WORKSPACE_ROOT , 'tools' , 'python_bin_path.sh' ) , 'w' ) as f : f . write ( 'export PYTHON_BIN_PATH="%s"' % python_bin_path )