parameters: (executable, run_on_host=False)
return_statement: return executable
docstring: find the location of an executable
docstring_summary: find the location of an executable
docstring_tokens: find the location of an executable
function: def which(executable, run_on_host=False):
      """find the location of an executable"""
      def _get_path(executable, locations):
          for location in locations:
              executable_path = os.path.join(location, executable)
              if os.path.exists(executable_path) and os.path.isfile(executable_path):
                  return executable_path
          return None
  
      static_locations = (
          '/usr/local/bin',
          '/bin',
          '/usr/bin',
          '/usr/local/sbin',
          '/usr/sbin',
          '/sbin',
      )
  
      if not run_on_host:
          path = os.getenv('PATH', '')
          path_locations = path.split(':')
          exec_in_path = _get_path(executable, path_locations)
          if exec_in_path:
              return exec_in_path
          mlogger.warning('Executable {} not in PATH: {}'.format(executable, path))
  
          exec_in_static_locations = _get_path(executable, static_locations)
          if exec_in_static_locations:
              mlogger.warning('Found executable under {}, please ensure $PATH is set correctly!'.format(exec_in_static_locations))
              return exec_in_static_locations
      else:
          executable = find_executable_on_host(static_locations, executable)
  
      # At this point, either `find_executable_on_host()` found an executable on the host
      # or we fallback to just returning the argument as-is, to prevent a hard fail, and
      # hoping that the system might have the executable somewhere custom
      return executable
function_tokens: def which ( executable , run_on_host = False ) : def _get_path ( executable , locations ) : for location in locations : executable_path = os . path . join ( location , executable ) if os . path . exists ( executable_path ) and os . path . isfile ( executable_path ) : return executable_path return None static_locations = ( '/usr/local/bin' , '/bin' , '/usr/bin' , '/usr/local/sbin' , '/usr/sbin' , '/sbin' , ) if not run_on_host : path = os . getenv ( 'PATH' , '' ) path_locations = path . split ( ':' ) exec_in_path = _get_path ( executable , path_locations ) if exec_in_path : return exec_in_path mlogger . warning ( 'Executable {} not in PATH: {}' . format ( executable , path ) ) exec_in_static_locations = _get_path ( executable , static_locations ) if exec_in_static_locations : mlogger . warning ( 'Found executable under {}, please ensure $PATH is set correctly!' . format ( exec_in_static_locations ) ) return exec_in_static_locations else : executable = find_executable_on_host ( static_locations , executable ) # At this point, either `find_executable_on_host()` found an executable on the host # or we fallback to just returning the argument as-is, to prevent a hard fail, and # hoping that the system might have the executable somewhere custom return executable