Configure a Py4J gateway.

        :param launch_jvm: ``True`` to spawn a Java Virtual Machine in a subprocess and connect to
            it, ``False`` to connect to an existing Py4J enabled JVM
        :param gateway: either a :class:`~py4j.java_gateway.GatewayParameters` object or a
            dictionary of keyword arguments for it
        :param callback_server: callback server parameters or a boolean indicating if a
            callback server is wanted
        :param javaopts: options passed to Java itself
        :param classpath: path or iterable of paths to pass to the JVM launcher as the class path

def configure_gateway(
            cls, launch_jvm: bool = True,
            gateway: Union[GatewayParameters, Dict[str, Any]] = None,
            callback_server: Union[CallbackServerParameters, Dict[str, Any]] = False,
            javaopts: Iterable[str] = (), classpath: Iterable[str] = ''):
        """
        Configure a Py4J gateway.

        :param launch_jvm: ``True`` to spawn a Java Virtual Machine in a subprocess and connect to
            it, ``False`` to connect to an existing Py4J enabled JVM
        :param gateway: either a :class:`~py4j.java_gateway.GatewayParameters` object or a
            dictionary of keyword arguments for it
        :param callback_server: callback server parameters or a boolean indicating if a
            callback server is wanted
        :param javaopts: options passed to Java itself
        :param classpath: path or iterable of paths to pass to the JVM launcher as the class path

        """
        assert check_argument_types()
        classpath = classpath if isinstance(classpath, str) else os.pathsep.join(classpath)
        javaopts = list(javaopts)

        # Substitute package names with their absolute directory paths
        for match in package_re.finditer(classpath):
            pkgname = match.group(1)
            module = import_module(pkgname)
            module_dir = os.path.dirname(module.__file__)
            classpath = classpath.replace(match.group(0), module_dir)

        if gateway is None:
            gateway = {}
        if isinstance(gateway, dict):
            gateway.setdefault('eager_load', True)
            gateway.setdefault('auto_convert', True)
            gateway = GatewayParameters(**gateway)

        if isinstance(callback_server, dict):
            callback_server = CallbackServerParameters(**callback_server)
        elif callback_server is True:
            callback_server = CallbackServerParameters()

        return launch_jvm, gateway, callback_server, classpath, javaopts