def __init__(self, read_stream, write_stream): from robocorp_code.rcc import Rcc from robocorp_ls_core.cache import DirCache from robocorp_ls_core.pluginmanager import PluginManager from robocorp_ls_core.ep_providers import DefaultConfigurationProvider from robocorp_ls_core.ep_providers import EPConfigurationProvider from robocorp_ls_core.ep_providers import DefaultDirCacheProvider from robocorp_ls_core.ep_providers import EPDirCacheProvider from robocorp_ls_core.ep_providers import DefaultEndPointProvider from robocorp_ls_core.ep_providers import EPEndPointProvider user_home = os.getenv("ROBOCORP_CODE_USER_HOME", None) if user_home is None: user_home = os.path.expanduser("~") cache_dir = os.path.join(user_home, ".robocorp-code", ".cache") log.debug(f"Cache dir: {cache_dir}") self._dir_cache = DirCache(cache_dir) self._rcc = Rcc(self) self._track = True self._local_list_robots_cache: Dict[ Path, CachedFileInfo[LocalRobotMetadataInfoDict]] = {} PythonLanguageServer.__init__(self, read_stream, write_stream) self._pm = PluginManager() self._config_provider = DefaultConfigurationProvider(self.config) self._pm.set_instance(EPConfigurationProvider, self._config_provider) self._pm.set_instance(EPDirCacheProvider, DefaultDirCacheProvider(self._dir_cache)) self._pm.set_instance(EPEndPointProvider, DefaultEndPointProvider(self._endpoint)) from robocorp_code.plugins.resolve_interpreter import register_plugins register_plugins(self._pm)
def __init__( self, robot_yaml_file_info: _CachedFileInfo, conda_config_file_info: Optional[_CachedFileInfo], env_json_path_file_info: Optional[_CachedFileInfo], pm: PluginManager, ): try: # Kept for backward compatibility from robotframework_ls.ep_resolve_interpreter import DefaultInterpreterInfo from robotframework_ls.ep_providers import EPConfigurationProvider except ImportError: from robocorp_ls_core.ep_resolve_interpreter import DefaultInterpreterInfo from robocorp_ls_core.ep_providers import EPConfigurationProvider self._mtime: _CachedInterpreterMTime = self._obtain_mtime( robot_yaml_file_info, conda_config_file_info, env_json_path_file_info) configuration_provider: EPConfigurationProvider = pm[ EPConfigurationProvider] rcc = Rcc(configuration_provider) interpreter_id = str(robot_yaml_file_info.file_path) result = rcc.get_robot_yaml_environ( robot_yaml_file_info.file_path, env_json_path_file_info.file_path if env_json_path_file_info is not None else None, ) if not result.success: raise RuntimeError( f"Unable to get env details. Error: {result.message}.") json_contents: Optional[str] = result.result if not json_contents: raise RuntimeError( f"Unable to get output when getting environment.") root = str(robot_yaml_file_info.file_path.parent) environ = {} for line in json_contents.splitlines(keepends=False): parts = line.split("=", 1) if len(parts) == 2: environ[parts[0]] = parts[1] pythonpath_lst = robot_yaml_file_info.yaml_contents.get( "PYTHONPATH", []) additional_pythonpath_entries: List[str] = [] if isinstance(pythonpath_lst, list): for v in pythonpath_lst: additional_pythonpath_entries.append(os.path.join( root, str(v))) self.info: IInterpreterInfo = DefaultInterpreterInfo( interpreter_id, environ["PYTHON_EXE"], environ, additional_pythonpath_entries, )
def __init__(self, read_stream, write_stream): from robocorp_code.rcc import Rcc from robocorp_ls_core.cache import DirCache user_home = os.getenv("ROBOCORP_CODE_USER_HOME", None) if user_home is None: user_home = os.path.expanduser("~") cache_dir = os.path.join(user_home, ".robocorp-code", ".cache") log.debug(f"Cache dir: {cache_dir}") self._dir_cache = DirCache(cache_dir) self._rcc = Rcc(self) PythonLanguageServer.__init__(self, read_stream, write_stream)
def rcc(config_provider: IConfigProvider, rcc_config_location: str) -> IRcc: from robocorp_code.rcc import Rcc rcc = Rcc(config_provider) # We don't want to track tests. # There's a bug in which the --do-not-track doesn't work the first time. result = rcc._run_rcc( "configure identity --do-not-track --config".split() + [rcc_config_location]) assert result.success result_msg = result.result assert result_msg if "disabled" not in result_msg: raise AssertionError(f"Did not expect {result_msg}") return rcc
def rcc(config_provider: IConfigProvider, rcc_config_location: str) -> IRcc: from robocorp_code.rcc import Rcc rcc = Rcc(config_provider) # We don't want to track tests. for _i in range(2): # There's a bug in which the --do-not-track doesn't work the first time. result = rcc._run_rcc( "feedback identity --do-not-track --config".split() + [rcc_config_location], expect_ok=False, ) assert result.success result_msg = result.result assert result_msg if "enabled" in result_msg: continue if "disabled" in result_msg: break raise AssertionError(f"Did not expect {result_msg}") else: raise AssertionError(f"Did not expect {result_msg}") return rcc
def __init__(self, read_stream, write_stream): from robocorp_code.rcc import Rcc from robocorp_ls_core.cache import DirCache from robocorp_ls_core.pluginmanager import PluginManager from robocorp_ls_core.ep_providers import DefaultConfigurationProvider from robocorp_ls_core.ep_providers import EPConfigurationProvider from robocorp_ls_core.ep_providers import DefaultDirCacheProvider from robocorp_ls_core.ep_providers import EPDirCacheProvider from robocorp_ls_core.ep_providers import DefaultEndPointProvider from robocorp_ls_core.ep_providers import EPEndPointProvider user_home = os.getenv("ROBOCORP_CODE_USER_HOME", None) if user_home is None: user_home = os.path.expanduser("~") cache_dir = os.path.join(user_home, ".robocorp-code", ".cache") log.debug(f"Cache dir: {cache_dir}") try: import ssl except: # This means that we won't be able to download drivers to # enable the creation of browser locators! # Let's print a bit more info. env_vars_info = "" related_vars = [ "LD_LIBRARY_PATH", "PATH", "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH", ] for v in related_vars: libpath = os.environ.get(v, "") libpath = "\n ".join(libpath.split(os.pathsep)) if libpath: libpath = "\n " + libpath + "\n" else: libpath = " <not set>\n" env_vars_info += f"{v}: {libpath}" log.critical(f"SSL module could not be imported.\n" f"sys.executable: {sys.executable}\n" f"Env vars info: {env_vars_info}\n") self._dir_cache = DirCache(cache_dir) self._rcc = Rcc(self) self._track = True self._local_list_robots_cache: Dict[ Path, CachedFileInfo[LocalRobotMetadataInfoDict]] = {} PythonLanguageServer.__init__(self, read_stream, write_stream) self._pm = PluginManager() self._config_provider = DefaultConfigurationProvider(self.config) self._pm.set_instance(EPConfigurationProvider, self._config_provider) self._pm.set_instance(EPDirCacheProvider, DefaultDirCacheProvider(self._dir_cache)) self._pm.set_instance(EPEndPointProvider, DefaultEndPointProvider(self._endpoint)) from robocorp_code.plugins.resolve_interpreter import register_plugins register_plugins(self._pm) self._locators_in_thread_api = _LocatorsInThreadAPI()
def rcc(config_provider: IConfigProvider, rcc_location: str) -> IRcc: from robocorp_code.rcc import Rcc rcc = Rcc(config_provider) return rcc
def __init__( self, request, launch_response, debug_adapter_comm, rcc_config_location: Optional[str], ): """ :param LaunchRequest request: :param LaunchResponse launch_response: """ import weakref from robocorp_ls_core.basic import as_str from robocorp_code_debug_adapter.constants import VALID_TERMINAL_OPTIONS from robocorp_code_debug_adapter.constants import TERMINAL_NONE from robocorp_ls_core.robotframework_log import get_log_level from robocorp_code.rcc import Rcc from robocorp_ls_core.config import Config from pathlib import Path self._weak_debug_adapter_comm = weakref.ref(debug_adapter_comm) self._valid = True self._cmdline = [] self._popen = None self._launch_response = launch_response self._next_seq = partial(next, itertools.count(0)) self._track_process_pid = None self._sent_terminated = threading.Event() self._rcc_config_location = rcc_config_location def mark_invalid(message): launch_response.success = False launch_response.message = message self._valid = False robot_yaml = request.arguments.kwargs.get("robot") self._terminal = request.arguments.kwargs.get("terminal", TERMINAL_NONE) if self._terminal != TERMINAL_NONE: # We don't currently support the integrated terminal because we don't # have an easy way to get the launched process pid in this way. return mark_invalid( f"Only 'terminal=none' is supported. Found terminal: {self._terminal}" ) task_name = request.arguments.kwargs.get("task", "") args = request.arguments.kwargs.get("args") or [] if not isinstance(args, list): args = [args] args = [str(arg) for arg in args] env = {} request_env = request.arguments.kwargs.get("env") if isinstance(request_env, dict) and request_env: env.update(request_env) env = dict( ((as_str(key), as_str(value)) for (key, value) in env.items())) self._env = env self._run_in_debug_mode = not request.arguments.noDebug if self._terminal not in VALID_TERMINAL_OPTIONS: return mark_invalid( "Invalid terminal option: %s (must be one of: %s)" % (self._terminal, VALID_TERMINAL_OPTIONS)) try: if robot_yaml is None: return mark_invalid("robot not provided in launch.") if not os.path.exists(robot_yaml): return mark_invalid("File: %s does not exist." % (robot_yaml, )) except: log.exception("Error") return mark_invalid("Error checking if robot (%s) exists." % (robot_yaml, )) self._cwd = os.path.dirname(robot_yaml) try: if self._cwd is not None: if not os.path.exists(self._cwd): return mark_invalid("cwd specified does not exist: %s" % (self._cwd, )) except: log.exception("Error") return mark_invalid("Error checking if cwd (%s) exists." % (self._cwd, )) if get_log_level() > 1: log.debug("Run in debug mode: %s\n" % (self._run_in_debug_mode, )) try: config = Config() config_provider = _DefaultConfigurationProvider(config) rcc = Rcc(config_provider=config_provider) rcc_executable = rcc.get_rcc_location() if not os.path.exists(rcc_executable): return mark_invalid(f"Expected: {rcc_executable} to exist.") except: log.exception("Error") return mark_invalid("Error getting rcc executable location.") else: task_args = [] if task_name: task_args.append("--task") task_args.append(task_name) cmdline = ([rcc_executable, "task", "run", "--robot", robot_yaml] + task_args + args) if self._rcc_config_location: cmdline.append("--config") cmdline.append(self._rcc_config_location) env_json_path = Path(robot_yaml).parent / "devdata" / "env.json" if env_json_path.exists(): cmdline.append("-e") cmdline.append(str(env_json_path)) self._cmdline = cmdline