def dev_main(): import os.path try: import robocorp_code except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robocorp_code # @UnusedImport robocorp_code.import_robocorp_ls_core() from robocorp_code.__main__ import main sys.argv = [ sys.argv[0], "-vv", "--tcp", "--port=1457", # "--log-file=c:/temp/robotlog.log", ] main()
def main(): log = None try: try: import robocorp_code except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname( os.path.dirname(os.path.dirname( os.path.dirname(__file__))))) import robocorp_code # @UnusedImport robocorp_code.import_robocorp_ls_core() from robocorp_ls_core.robotframework_log import get_logger log = get_logger(__name__) log.info("Initializing Locators Server api. Args: %s", (sys.argv[1:], )) from robocorp_code import __main__ from robocorp_code.locators.server.locator_server_api import LocatorServerApi __main__.main(language_server_class=LocatorServerApi) except: try: if log is not None: log.exception("Error initializing LocatorServerApi.") finally: # Critical error (the logging may not be set up properly). # Print to file and stderr. with open(_critical_error_log_file, "a+") as stream: traceback.print_exc(file=stream) traceback.print_exc()
def main(args=None, after_bind=lambda server: None, language_server_class=None): original_args = args if args is not None else sys.argv[1:] parser = argparse.ArgumentParser() add_arguments(parser) args = parser.parse_args(args=original_args) verbose = args.verbose log_file = args.log_file or "" try: try: import robocorp_code except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robocorp_code # @UnusedImport robocorp_code.import_robocorp_ls_core() from robocorp_ls_core.robotframework_log import ( configure_logger, log_args_and_python, get_logger, ) except: # Failed before having setup the logger (but after reading args). log_file = os.path.expanduser(log_file) log_file = os.path.realpath(os.path.abspath(log_file)) dirname = os.path.dirname(log_file) basename = os.path.basename(log_file) try: os.makedirs(dirname) except: pass # Ignore error if it already exists. name, ext = os.path.splitext(basename) postfix = "lsp.init" log_file = os.path.join( dirname, name + "." + postfix + "." + str(os.getpid()) + ext) with open(log_file, "a+") as stream: traceback.print_exc(file=stream) raise if args.version: sys.stdout.write(robocorp_code.__version__) sys.stdout.flush() return configure_logger("lsp", verbose, log_file) log = get_logger("robocorp_code.__main__") log_args_and_python(log, original_args, robocorp_code.__version__) try: from robocorp_code.options import Setup, Options Setup.options = Options(args) from robocorp_ls_core.python_ls import ( start_io_lang_server, start_tcp_lang_server, binary_stdio, ) if language_server_class is None: from robocorp_code.robocorp_language_server import RobocorpLanguageServer language_server_class = RobocorpLanguageServer if args.tcp: start_tcp_lang_server(args.host, args.port, language_server_class, after_bind=after_bind) else: stdin, stdout = binary_stdio() start_io_lang_server(stdin, stdout, language_server_class) except: log.exception("Error initializing") raise
def main(): """ Starts the debug adapter (creates a thread to read from stdin and another to write to stdout as expected by the vscode debug protocol). We pass the command processor to the reader thread as the idea is that the reader thread will read a message, convert it to an instance of the message in the schema and then forward it to the command processor which will interpret and act on it, posting the results to the writer queue. """ log = None try: import sys try: import robocorp_code_debug_adapter import robocorp_code except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robocorp_code_debug_adapter # @UnusedImport import robocorp_code robocorp_code.import_robocorp_ls_core() from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import ( STOP_WRITER_THREAD, ) from robocorp_ls_core.robotframework_log import ( get_logger, configure_logger, log_args_and_python, ) from robocorp_code_debug_adapter.constants import LOG_FILENAME from robocorp_code_debug_adapter.constants import LOG_LEVEL configure_logger("dap", LOG_LEVEL, LOG_FILENAME) log = get_logger("robocorp_code_debug_adapter.__main__") log_args_and_python(log, sys.argv, robocorp_code) from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import ( reader_thread, ) from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import ( writer_thread, ) from queue import Queue from robocorp_code_debug_adapter.debug_adapter_comm import DebugAdapterComm to_client_queue = Queue() comm = DebugAdapterComm(to_client_queue) write_to = sys.stdout read_from = sys.stdin if sys.version_info[0] <= 2: if sys.platform == "win32": # must read streams as binary on windows import msvcrt msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) else: # Py3 write_to = sys.stdout.buffer read_from = sys.stdin.buffer writer = threading.Thread( target=writer_thread, args=(write_to, to_client_queue, "write to client"), name="Write to client (dap __main__)", ) reader = threading.Thread( target=reader_thread, args=(read_from, comm.from_client, to_client_queue, b"read from client"), name="Read from client (dap __main__)", ) reader.start() writer.start() reader.join() log.debug("Exited reader.\n") to_client_queue.put(STOP_WRITER_THREAD) writer.join() log.debug("Exited writer.\n") except: if log is not None: log.exception("Error") # Critical error (the logging may not be set up properly). # Print to file and stderr. with open(_critical_error_log_file, "a+") as stream: traceback.print_exc(file=stream) traceback.print_exc() finally: if log is not None: log.debug("Exited main.\n")
import traceback __file__ = os.path.abspath(__file__) if not os.path.exists(os.path.join(os.path.abspath("."), "dev.py")): raise RuntimeError( 'Please execute commands from the directory containing "dev.py"') try: import robocorp_code except ImportError: # I.e.: add relative path (the cwd must be the directory containing this file). sys.path.append("src") import robocorp_code robocorp_code.import_robocorp_ls_core() def _fix_contents_version(contents, version): import re contents = re.sub(r"(version\s*=\s*)\"\d+\.\d+\.\d+", r'\1"%s' % (version, ), contents) contents = re.sub(r"(__version__\s*=\s*)\"\d+\.\d+\.\d+", r'\1"%s' % (version, ), contents) contents = re.sub(r"(\"version\"\s*:\s*)\"\d+\.\d+\.\d+", r'\1"%s' % (version, ), contents) return contents