<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def launcher(deploy_mode, args, working_dir=".", cleanup=True):
 """Initializes arguments and starts up pyspark with the correct deploy mode and environment. Parameters deploy_mode : {"client", "cluster"} args : list Arguments to pass onwards to spark submit. working_dir : str, optional Path to working directory to use for creating conda environments. Defaults to the current working directory. cleanup : bool, optional Clean up extracted / generated files. This defaults to true since conda environments can be rather large. Returns ------- This call will spawn a child process and block until that is complete. """

    spark_args = args.copy()
    # Scan through the arguments to find --conda
    # TODO: make this optional,  if not specified ignore all the python stuff
    # Is this double dash in front of conda env correct?
    i = spark_args.index("--conda-env")
    # pop off the '--conda-env' portion and just drop it on the floor
    spark_args.pop(i)
    # Now pop off the actual conda env var passed to the launcher
    conda_env = spark_args.pop(i)
    cleanup_functions = []
    # What else could this possibly be other than a string here?
    assert isinstance(conda_env, str)
    func_kwargs = {'conda_env': conda_env,
                   'deploy_mode': deploy_mode,
                   'working_dir': working_dir,
                   'cleanup_functions': cleanup_functions}
    if conda_env.startswith("hdfs:/"):
        # "hadoop fs -ls" can return URLs with only a single "/" after the "hdfs:" scheme
        env_name, env_dir, env_archive = _conda_from_hdfs(**func_kwargs)
    elif conda_env.endswith(".zip"):
        # We have a precreated conda environment around.
        env_name, env_dir, conda_env = _conda_from_zip(**func_kwargs)
    elif conda_env.endswith(".yaml"):
        # The case where we have to CREATE the environment ourselves
        env_name, env_dir, env_archive = _conda_from_yaml(**func_kwargs)
    else:
        raise NotImplementedError("Can only run launcher if your conda env is on hdfs (starts "
                                  "with 'hdfs:/', is already a zip (ends with '.zip'), or is "
                                  "coming from a yaml specification (ends with '.yaml' and "
                                  "conforms to the conda environment.yaml spec)")
    del func_kwargs

    func_kwargs = dict(env_dir=env_dir, env_name=env_name, env_archive=env_archive, args=spark_args)
    funcs = {'client': run_pyspark_yarn_client, 'cluster': run_pyspark_yarn_cluster}
    try:
        funcs[deploy_mode](**func_kwargs)
    finally:
        if not cleanup:
            return
        # iterate over and call all cleanup functions
        for function in cleanup_functions:
            try:
                function()
            except:
                log.exception("Cleanup function %s failed", function)