def start_host(session=None):
plugins = []<EOL>for arg in sys.argv:<EOL><INDENT>_, ext = os.path.splitext(arg)<EOL>if ext == '<STR_LIT>':<EOL><INDENT>plugins.append(arg)<EOL><DEDENT>elif os.path.isdir(arg):<EOL><INDENT>init = os.path.join(arg, '<STR_LIT>')<EOL>if os.path.isfile(init):<EOL><INDENT>plugins.append(arg)<EOL><DEDENT><DEDENT><DEDENT>for path in list(plugins):<EOL><INDENT>dup = path + "<STR_LIT>"<EOL>if os.path.isdir(path) and dup in plugins:<EOL><INDENT>plugins.remove(dup)<EOL><DEDENT><DEDENT>if plugins == ["<STR_LIT>"]:<EOL><INDENT>name = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>name = "<STR_LIT>"<EOL><DEDENT>setup_logging(name)<EOL>if not session:<EOL><INDENT>session = stdio_session()<EOL><DEDENT>nvim = Nvim.from_session(session)<EOL>if nvim.version.api_level < <NUM_LIT:1>:<EOL><INDENT>sys.stderr.write("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>host = Host(nvim)<EOL>host.start(plugins)<EOL>
Promote the current process into python plugin host for Nvim.

    Start msgpack-rpc event loop for `session`, listening for Nvim requests
    and notifications. It registers Nvim commands for loading/unloading
    python plugins.

    The sys.stdout and sys.stderr streams are redirected to Nvim through
    `session`. That means print statements probably won't work as expected
    while this function doesn't return.

    This function is normally called at program startup and could have been
    defined as a separate executable. It is exposed as a library function for
    testing purposes only.