Example #1
0
def jedi_epc_server(address='localhost', port=0, port_file=sys.stdout,
                    sys_path=[], virtual_env=[],
                    debugger=None, log=None, log_level=None,
                    log_traceback=None):
    default_venv = os.getenv('VIRTUAL_ENV')
    if default_venv:
        add_virtualenv_path(default_venv)

    for p in virtual_env:
        add_virtualenv_path(path_expand_vars_and_user(p))
    sys_path = map(path_expand_vars_and_user, sys_path)
    sys.path = [''] + list(filter(None, itertools.chain(sys_path, sys.path)))
    # Workaround Jedi's module cache.  Use this workaround until Jedi
    # got an API to set module paths.
    # See also: https://github.com/davidhalter/jedi/issues/36
    import_jedi()
    import epc.server
    server = epc.server.EPCServer((address, port))
    server.register_function(complete)
    server.register_function(get_in_function_call)
    server.register_function(goto)
    server.register_function(related_names)
    server.register_function(get_definition)
    server.register_function(defined_names)
    server.register_function(get_jedi_version)

    @server.register_function
    def toggle_log_traceback():
        server.log_traceback = not server.log_traceback
        return server.log_traceback

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    # This is not supported Python-EPC API, but I am using this for
    # backward compatibility for Python-EPC < 0.0.4.  In the future,
    # it should be passed to the constructor.
    server.log_traceback = bool(log_traceback)

    if log:
        handler = logging.FileHandler(filename=log, mode='w')
        if log_level:
            log_level = getattr(logging, log_level.upper())
            handler.setLevel(log_level)
            server.logger.setLevel(log_level)
        server.logger.addHandler(handler)
    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)

    return server
Example #2
0
def jedi_epc_server(
    address="localhost",
    port=0,
    port_file=sys.stdout,
    sys_path=[],
    virtual_env=[],
    debugger=None,
    log=None,
    log_level=None,
):
    add_virtualenv_path()
    for p in virtual_env:
        add_virtualenv_path(p)
    sys_path = map(os.path.expandvars, map(os.path.expanduser, sys_path))
    sys.path = [""] + list(filter(None, itertools.chain(sys_path, sys.path)))
    # Workaround Jedi's module cache.  Use this workaround until Jedi
    # got an API to set module paths.
    # See also: https://github.com/davidhalter/jedi/issues/36
    import_jedi()
    import epc.server

    server = epc.server.EPCServer((address, port))
    server.register_function(complete)
    server.register_function(get_in_function_call)
    server.register_function(goto)
    server.register_function(related_names)
    server.register_function(get_definition)
    server.register_function(defined_names)
    server.register_function(get_jedi_version)

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    if log:
        server.log_traceback = True
        handler = logging.FileHandler(filename=log, mode="w")
        if log_level:
            log_level = getattr(logging, log_level.upper())
            handler.setLevel(log_level)
            server.logger.setLevel(log_level)
        server.logger.addHandler(handler)
    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)

    server.serve_forever()
    server.logger.info("exit")
    return server
Example #3
0
def jedi_epc_server(address='localhost',
                    port=0,
                    port_file=sys.stdout,
                    sys_path=[],
                    virtual_env=[],
                    debugger=None,
                    log=None,
                    log_level=None):
    add_virtualenv_path()
    for p in virtual_env:
        add_virtualenv_path(p)
    sys_path = map(os.path.expandvars, map(os.path.expanduser, sys_path))
    sys.path = [''] + list(filter(None, itertools.chain(sys_path, sys.path)))
    # Workaround Jedi's module cache.  Use this workaround until Jedi
    # got an API to set module paths.
    # See also: https://github.com/davidhalter/jedi/issues/36
    import_jedi()
    import epc.server
    server = epc.server.EPCServer((address, port))
    server.register_function(complete)
    server.register_function(get_in_function_call)
    server.register_function(goto)
    server.register_function(related_names)
    server.register_function(get_definition)
    server.register_function(defined_names)
    server.register_function(get_jedi_version)

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    if log:
        server.log_traceback = True
        handler = logging.FileHandler(filename=log, mode='w')
        if log_level:
            log_level = getattr(logging, log_level.upper())
            handler.setLevel(log_level)
            server.logger.setLevel(log_level)
        server.logger.addHandler(handler)
    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)

    server.serve_forever()
    server.logger.info('exit')
    return server
Example #4
0
def jedi_epc_server(
        address='localhost',
        port=0,
        port_file=sys.stdout,
        sys_path=[],
        virtual_env=[],
        sys_path_append=[],
        debugger=None,
        log_traceback=None,
):
    """Start EPC server.

    :type log_settings: LogSettings

    """
    logger.debug(
        'jedi_epc_server: sys_path=%r virtual_env=%r sys_path_append=%r',
        sys_path, virtual_env, sys_path_append,
    )

    if not virtual_env and os.getenv('VIRTUAL_ENV'):
        logger.debug(
            'Taking virtual env from VIRTUAL_ENV: %r',
            os.environ['VIRTUAL_ENV'],
        )
        virtual_env = [os.environ['VIRTUAL_ENV']]

    handler = JediEPCHandler(
        sys_path=sys_path,
        virtual_envs=virtual_env,
        sys_path_append=sys_path_append,
    )
    logger.debug(
        'Starting Jedi EPC server with the following sys.path: %r',
        handler.get_sys_path(),
    )
    server = epc.server.EPCServer((address, port))
    server.register_function(handler.complete)
    server.register_function(handler.get_in_function_call)
    server.register_function(handler.goto)
    server.register_function(handler.related_names)
    server.register_function(handler.get_definition)
    server.register_function(handler.defined_names)
    server.register_function(handler.get_jedi_version)

    @server.register_function
    def toggle_log_traceback():
        server.log_traceback = not server.log_traceback
        return server.log_traceback

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    # This is not supported Python-EPC API, but I am using this for
    # backward compatibility for Python-EPC < 0.0.4.  In the future,
    # it should be passed to the constructor.
    server.log_traceback = bool(log_traceback)

    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        fmter = logging.Formatter('%(asctime)s:' + logging.BASIC_FORMAT)
        handler.setFormatter(fmter)
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)
    return server
def jedi_epc_server(
        address='localhost',
        port=0,
        port_file=sys.stdout,
        sys_path=[],
        virtual_env=[],
        sys_path_append=[],
        debugger=None,
        log_traceback=None,
):
    """Start EPC server.

    :type log_settings: LogSettings

    """
    logger.debug(
        'jedi_epc_server: sys_path=%r virtual_env=%r sys_path_append=%r',
        sys_path, virtual_env, sys_path_append,
    )

    if not virtual_env and os.getenv('VIRTUAL_ENV'):
        logger.debug(
            'Taking virtual env from VIRTUAL_ENV: %r',
            os.environ['VIRTUAL_ENV'],
        )
        virtual_env = [os.environ['VIRTUAL_ENV']]

    handler = JediEPCHandler(
        sys_path=sys_path,
        virtual_envs=virtual_env,
        sys_path_append=sys_path_append,
    )
    logger.debug(
        'Starting Jedi EPC server with the following sys.path: %r',
        handler.get_sys_path(),
    )
    server = epc.server.EPCServer((address, port))
    server.register_function(handler.complete)
    server.register_function(handler.get_in_function_call)
    server.register_function(handler.goto)
    server.register_function(handler.related_names)
    server.register_function(handler.get_definition)
    server.register_function(handler.defined_names)
    server.register_function(handler.get_jedi_version)

    @server.register_function
    def toggle_log_traceback():
        server.log_traceback = not server.log_traceback
        return server.log_traceback

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    # This is not supported Python-EPC API, but I am using this for
    # backward compatibility for Python-EPC < 0.0.4.  In the future,
    # it should be passed to the constructor.
    server.log_traceback = bool(log_traceback)

    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        fmter = logging.Formatter('%(asctime)s:' + logging.BASIC_FORMAT)
        handler.setFormatter(fmter)
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)
    return server
Example #6
0
def fortpy_epc_server(address='localhost',
                      port=0,
                      port_file=sys.stdout,
                      sys_path=[],
                      virtual_env=[],
                      debugger=None,
                      log=None,
                      log_level=None,
                      log_traceback=None):
    add_virtualenv_path()
    for p in virtual_env:
        add_virtualenv_path(p)
    sys_path = map(os.path.expandvars, map(os.path.expanduser, sys_path))
    sys.path = [''] + list(filter(None, itertools.chain(sys_path, sys.path)))

    import_fortpy()
    import epc.server
    server = epc.server.EPCServer((address, port))
    server.register_function(complete)
    server.register_function(get_in_function_call)
    server.register_function(goto)
    server.register_function(related_names)
    server.register_function(get_definition)
    server.register_function(defined_names)
    server.register_function(get_fortpy_version)
    server.register_function(bracket_complete)
    server.register_function(reparse_module)

    @server.register_function
    def toggle_log_traceback():
        server.log_traceback = not server.log_traceback
        return server.log_traceback

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    # This is not supported Python-EPC API, but I am using this for
    # backward compatibility for Python-EPC < 0.0.4.  In the future,
    # it should be passed to the constructor.
    server.log_traceback = bool(log_traceback)

    if log:
        handler = logging.FileHandler(filename=log, mode='w')
        if log_level:
            log_level = getattr(logging, log_level.upper())
            handler.setLevel(log_level)
            server.logger.setLevel(log_level)
        server.logger.addHandler(handler)
    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)

    server.serve_forever()
    server.logger.info('exit')
    return server
Example #7
0
def fortpy_epc_server(
    address="localhost",
    port=0,
    port_file=sys.stdout,
    sys_path=[],
    virtual_env=[],
    debugger=None,
    log=None,
    log_level=None,
    log_traceback=None,
):
    add_virtualenv_path()
    for p in virtual_env:
        add_virtualenv_path(p)
    sys_path = map(os.path.expandvars, map(os.path.expanduser, sys_path))
    sys.path = [""] + list(filter(None, itertools.chain(sys_path, sys.path)))

    import_fortpy()
    import epc.server

    server = epc.server.EPCServer((address, port))
    server.register_function(complete)
    server.register_function(get_in_function_call)
    server.register_function(goto)
    server.register_function(related_names)
    server.register_function(get_definition)
    server.register_function(defined_names)
    server.register_function(get_fortpy_version)
    server.register_function(bracket_complete)
    server.register_function(reparse_module)

    @server.register_function
    def toggle_log_traceback():
        server.log_traceback = not server.log_traceback
        return server.log_traceback

    port_file.write(str(server.server_address[1]))  # needed for Emacs client
    port_file.write("\n")
    port_file.flush()
    if port_file is not sys.stdout:
        port_file.close()

    # This is not supported Python-EPC API, but I am using this for
    # backward compatibility for Python-EPC < 0.0.4.  In the future,
    # it should be passed to the constructor.
    server.log_traceback = bool(log_traceback)

    if log:
        handler = logging.FileHandler(filename=log, mode="w")
        if log_level:
            log_level = getattr(logging, log_level.upper())
            handler.setLevel(log_level)
            server.logger.setLevel(log_level)
        server.logger.addHandler(handler)
    if debugger:
        server.set_debugger(debugger)
        handler = logging.StreamHandler()
        handler.setLevel(logging.DEBUG)
        server.logger.addHandler(handler)
        server.logger.setLevel(logging.DEBUG)

    server.serve_forever()
    server.logger.info("exit")
    return server