parameters: (environ_cp)
docstring: Setup python related env variables interactively.
docstring_summary: Setup python related env variables interactively.
docstring_tokens: Setup python related env variables interactively .
function: def setup_python_interactively(environ_cp):
      """Setup python related env variables interactively."""
      # 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 '
          '{}]: ').format(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: {} cannot be found.'.format(
                  python_bin_path))
          else:
              print('{} is not executable.  Is it the python binary?'.format(
                  python_bin_path))
          environ_cp['PYTHON_BIN_PATH'] = ''
  
      python_major_version = get_python_major_version(python_bin_path)
      if python_major_version != '3':
          print('Python 2 was Retired on April 2020. Use Python 3 instead.')
          sys.exit(1)
  
      # 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)
          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 [{}]\n'.format(python_lib_paths[0]))
          if not python_lib_path:
              python_lib_path = default_python_lib_path
          environ_cp['PYTHON_LIB_PATH'] = 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=\"{}\"'.format(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'))
function_tokens: def setup_python_interactively ( 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 ' '{}]: ' ) . format ( 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: {} cannot be found.' . format ( python_bin_path ) ) else : print ( '{} is not executable.  Is it the python binary?' . format ( python_bin_path ) ) environ_cp [ 'PYTHON_BIN_PATH' ] = '' python_major_version = get_python_major_version ( python_bin_path ) if python_major_version != '3' : print ( 'Python 2 was Retired on April 2020. Use Python 3 instead.' ) sys . exit ( 1 ) # 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 ) 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 [{}]\n' . format ( python_lib_paths [ 0 ] ) ) if not python_lib_path : python_lib_path = default_python_lib_path environ_cp [ 'PYTHON_LIB_PATH' ] = 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=\"{}\"' . format ( 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' ) )