Ejemplo n.º 1
0
def run_env_command(command, prefix, *arguments):
    """
        Run conda env commands
    Args:
        command: The command, create, remove, export
        prefix: The prefix, for remove and create
        *arguments: The extra arguments
    """

    arguments = massage_arguments(arguments)
    arguments.insert(0, command)

    if command is Commands.ENV_EXPORT:
        arguments[1:1] = ['-n', prefix]
    elif command is Commands.ENV_CREATE:  # CREATE
        if prefix:
            arguments[1:1] = ['-n', prefix]
    elif command is Commands.ENV_REMOVE:  # REMOVE
        arguments[1:1] = ['--yes', '-n', prefix]
    elif command is Commands.ENV_UPDATE:
        arguments[1:1] = ['-n', prefix]
    else:
        command_line = " --help "
    p = create_parser()
    args = p.parse_args(arguments)
    context._set_argparse_args(args)

    with captured() as c:
        do_call_conda_env(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 2
0
def run_command(command, prefix, *arguments, **kwargs):
    use_exception_handler = kwargs.get('use_exception_handler', False)
    arguments = list(arguments)
    p, sub_parsers = generate_parser()
    parser_config[command](sub_parsers)

    if command is Commands.CONFIG:
        arguments.append("--file {0}".format(join(prefix, 'condarc')))
    if command in (Commands.LIST, Commands.CREATE, Commands.INSTALL,
                   Commands.REMOVE, Commands.UPDATE):
        arguments.append("-p {0}".format(prefix))
    if command in (Commands.CREATE, Commands.INSTALL, Commands.REMOVE, Commands.UPDATE):
        arguments.extend(["-y", "-q"])

    arguments = list(map(escape_for_winpath, arguments))
    command_line = "{0} {1}".format(command, " ".join(arguments))

    args = p.parse_args(split(command_line))
    context._set_argparse_args(args)
    print("\n\nEXECUTING COMMAND >>> $ conda %s\n\n" % command_line, file=sys.stderr)
    with stderr_log_level(TEST_LOG_LEVEL, 'conda'), stderr_log_level(TEST_LOG_LEVEL, 'requests'):
        with captured() as c, replace_log_streams():
            if use_exception_handler:
                conda_exception_handler(args.func, args, p)
            else:
                args.func(args, p)
    print(c.stderr, file=sys.stderr)
    print(c.stdout, file=sys.stderr)
    if command is Commands.CONFIG:
        reload_config(prefix)
    return c.stdout, c.stderr
Ejemplo n.º 3
0
def run_conda_command(command, prefix, *arguments):
    """
        Run conda command,
    Args:
        command: conda create, list, info
        prefix: The prefix or the name of environment
        *arguments: Extra arguments
    """
    p = generate_parser()

    prefix = escape_for_winpath(prefix)
    if arguments:
        arguments = list(map(escape_for_winpath, arguments))
    if command is Commands.INFO:  # INFO
        command_line = "{0} {1}".format(command, " ".join(arguments))
    elif command is Commands.LIST:  # LIST
        command_line = "{0} -n {1} {2}".format(command, prefix,
                                               " ".join(arguments))
    else:  # CREATE
        command_line = "{0} -y -q -n {1} {2}".format(command, prefix,
                                                     " ".join(arguments))

    from conda._vendor.auxlib.compat import shlex_split_unicode
    commands = shlex_split_unicode(command_line)
    args = p.parse_args(commands)
    context._set_argparse_args(args)
    with captured() as c:
        do_call(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 4
0
def run_conda_command(command, prefix, *arguments):
    """
        Run conda command,
    Args:
        command: conda create , list, info
        prefix: The prefix or the name of environment
        *arguments: Extra arguments
    """
    p, sub_parsers = generate_parser()
    assert command in parser_config, "Wrong command for conda {0}".format(
        command)
    parser_config[command](sub_parsers)

    prefix = escape_for_winpath(prefix)
    if arguments:
        arguments = list(map(escape_for_winpath, arguments))
    if command is Commands.INFO:  # INFO
        command_line = "{0} {1}".format(command, " ".join(arguments))
    elif command is Commands.LIST:  # LIST
        command_line = "{0} -n {1} {2}".format(command, prefix,
                                               " ".join(arguments))
    else:  # CREATE
        command_line = "{0} -y -q -n {1} {2}".format(command, prefix,
                                                     " ".join(arguments))

    args = p.parse_args(split(command_line))
    context._set_argparse_args(args)
    with captured() as c:
        args.func(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 5
0
def run_env_command(command, prefix, *arguments):
    """
        Run conda env commands
    Args:
        command: The command, create, remove, export
        prefix: The prefix, for remove and create
        *arguments: The extra arguments
    """
    p = create_parser()
    prefix = escape_for_winpath(prefix)

    if arguments:
        arguments = list(map(escape_for_winpath, arguments))

    if command is Commands.ENV_EXPORT:
        command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments))
    elif command is Commands.ENV_CREATE: # CREATE
        if prefix :
            command_line = "{0} -f {1}  {2}".format(command, prefix, " ".join(arguments))
        else:
            command_line = "{0} ".format(command)
    elif command is Commands.ENV_REMOVE:  # REMOVE
        command_line = "{0} --yes -n {1} {2}".format(command, prefix, " ".join(arguments))
    elif command is Commands.ENV_UPDATE:
        command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments))
    else:
        command_line = " --help "

    args = p.parse_args(split(command_line))
    context._set_argparse_args(args)

    with captured() as c:
        args.func(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 6
0
def run_conda_command(command, prefix, *arguments):
    """
        Run conda command,
    Args:
        command: conda create , list, info
        prefix: The prefix or the name of environment
        *arguments: Extra arguments
    """
    p = generate_parser()

    prefix = escape_for_winpath(prefix)
    if arguments:
        arguments = list(map(escape_for_winpath, arguments))
    if command is Commands.INFO:    # INFO
        command_line = "{0} {1}".format(command, " ".join(arguments))
    elif command is Commands.LIST:  # LIST
        command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments))
    else:  # CREATE
        command_line = "{0} -y -q -n {1} {2}".format(command, prefix, " ".join(arguments))

    args = p.parse_args(split(command_line))
    context._set_argparse_args(args)
    with captured() as c:
        do_call(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 7
0
def run_env_command(command, prefix, *arguments):
    """
        Run conda env commands
    Args:
        command: The command, create, remove, export
        prefix: The prefix, for remove and create
        *arguments: The extra arguments
    """
    p = create_parser()
    prefix = escape_for_winpath(prefix)

    if arguments:
        arguments = list(map(escape_for_winpath, arguments))

    if command is Commands.ENV_EXPORT:
        command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments))
    elif command is Commands.ENV_CREATE: # CREATE
        if prefix :
            command_line = "{0} -f {1}  {2}".format(command, prefix, " ".join(arguments))
        else:
            command_line = "{0} ".format(command)
    elif command is Commands.ENV_REMOVE:  # REMOVE
        command_line = "{0} --yes -n {1} {2}".format(command, prefix, " ".join(arguments))
    elif command is Commands.ENV_UPDATE:
        command_line = "{0} -n {1} {2}".format(command, prefix, " ".join(arguments))
    else:
        command_line = " --help "

    args = p.parse_args(split(command_line))
    context._set_argparse_args(args)

    with captured() as c:
        do_call_conda_env(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 8
0
def run_command(command, prefix, *arguments, **kwargs):
    use_exception_handler = kwargs.get('use_exception_handler', False)
    arguments = list(arguments)
    p, sub_parsers = generate_parser()
    parser_config[command](sub_parsers)

    if command is Commands.CONFIG:
        arguments.append("--file {0}".format(join(prefix, 'condarc')))
    if command in (Commands.LIST, Commands.CREATE, Commands.INSTALL,
                   Commands.REMOVE, Commands.UPDATE):
        arguments.append("-p {0}". format(prefix))
    if command in (Commands.CREATE, Commands.INSTALL, Commands.REMOVE, Commands.UPDATE):
        arguments.extend(["-y", "-q"])

    arguments = list(map(escape_for_winpath, arguments))
    command_line = "{0} {1}".format(command, " ".join(arguments))

    args = p.parse_args(split(command_line))
    context._set_argparse_args(args)
    print("\n\nEXECUTING COMMAND >>> $ conda %s\n\n" % command_line, file=sys.stderr)
    with stderr_log_level(TEST_LOG_LEVEL, 'conda'), stderr_log_level(TEST_LOG_LEVEL, 'requests'):
        with captured() as c, replace_log_streams():
            if use_exception_handler:
                conda_exception_handler(args.func, args, p)
            else:
                args.func(args, p)
    print(c.stderr, file=sys.stderr)
    print(c.stdout, file=sys.stderr)
    if command is Commands.CONFIG:
        reload_config(prefix)
    return c.stdout, c.stderr
Ejemplo n.º 9
0
def run_env_command(command, prefix, *arguments):
    """
        Run conda env commands
    Args:
        command: The command, create, remove, export
        prefix: The prefix, for remove and create
        *arguments: The extra arguments
    """

    arguments = massage_arguments(arguments)
    arguments.insert(0, command)

    if command is Commands.ENV_EXPORT:
        arguments[1:1] = ['-n', prefix]
    elif command is Commands.ENV_CREATE: # CREATE
        if prefix:
            arguments[1:1] = ['-f', prefix]
    elif command is Commands.ENV_REMOVE:  # REMOVE
        arguments[1:1] = ['--yes', '-n', prefix]
    elif command is Commands.ENV_UPDATE:
        arguments[1:1] = ['-n', prefix]
    else:
        command_line = " --help "
    p = create_parser()
    args = p.parse_args(arguments)
    context._set_argparse_args(args)

    with captured() as c:
        do_call_conda_env(args, p)

    return c.stdout, c.stderr
Ejemplo n.º 10
0
Archivo: main.py Proyecto: ESSS/conda
def main():
    parser = create_parser()
    args = parser.parse_args()
    context._set_argparse_args(args)
    if getattr(args, 'json', False):
        # # Silence logging info to avoid interfering with JSON output
        # for logger in Logger.manager.loggerDict:
        #     if logger not in ('fetch', 'progress'):
        #         getLogger(logger).setLevel(CRITICAL + 1)
        for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'):
            getLogger(logger).setLevel(CRITICAL + 1)

    return conda_exception_handler(args.func, args, parser)
def main():
    parser = create_parser()
    args = parser.parse_args()
    context._set_argparse_args(args)
    if getattr(args, 'json', False):
        # # Silence logging info to avoid interfering with JSON output
        # for logger in Logger.manager.loggerDict:
        #     if logger not in ('fetch', 'progress'):
        #         getLogger(logger).setLevel(CRITICAL + 1)
        for logger in ('print', 'dotupdate', 'stdoutlog', 'stderrlog'):
            getLogger(logger).setLevel(CRITICAL + 1)

    return conda_exception_handler(args.func, args, parser)
Ejemplo n.º 12
0
def run_command(command, prefix, *arguments, **kwargs):

    assert isinstance(arguments,
                      tuple), "run_command() arguments must be tuples"
    arguments = massage_arguments(arguments)

    use_exception_handler = kwargs.get("use_exception_handler", False)
    # These commands require 'dev' mode to be enabled during testing because
    # they end up calling run_script() in link.py and that uses wrapper scripts for e.g. activate.
    # Setting `dev` means that, in these scripts, conda is executed via:
    #   `sys.prefix/bin/python -m conda` (or the Windows equivalent).
    # .. and the source code for `conda` is put on `sys.path` via `PYTHONPATH` (a bit gross but
    # less so than always requiring `cwd` to be the root of the conda source tree in every case).
    # If you do not want this to happen for some test you must pass dev=False as a kwarg, though
    # for nearly all tests, you want to make sure you are running *this* conda and not some old
    # conda (it was random which you'd get depending on the initial values of PATH and PYTHONPATH
    # - and likely more variables - before `dev` came along). Setting CONDA_EXE is not enough
    # either because in the 4.5 days that would just run whatever Python was found first on PATH.
    command_defaults_to_dev = command in (
        Commands.CREATE,
        Commands.INSTALL,
        Commands.REMOVE,
        Commands.RUN,
    )
    dev = kwargs.get("dev", True if command_defaults_to_dev else False)
    debug = kwargs.get("debug_wrapper_scripts", False)

    p = generate_parser()

    if command is Commands.CONFIG:
        arguments.append("--file")
        arguments.append(join(prefix, "condarc"))
    if command in (
            Commands.LIST,
            Commands.COMPARE,
            Commands.CREATE,
            Commands.INSTALL,
            Commands.REMOVE,
            Commands.UPDATE,
            Commands.RUN,
    ):
        arguments.insert(0, "-p")
        arguments.insert(1, prefix)
    if command in (Commands.CREATE, Commands.INSTALL, Commands.REMOVE,
                   Commands.UPDATE):
        arguments.extend(["-y", "-q"])

    arguments.insert(0, command)
    if dev:
        arguments.insert(1, "--dev")
    if debug:
        arguments.insert(1, "--debug-wrapper-scripts")

    # It would be nice at this point to re-use:
    # from conda.cli.python_api import run_command as python_api_run_command
    # python_api_run_command
    # .. but that does not support no_capture and probably more stuff.

    args = p.parse_args(arguments)
    context._set_argparse_args(args)
    init_loggers(context)
    cap_args = tuple() if not kwargs.get("no_capture") else (None, None)
    # list2cmdline is not exact, but it is only informational.
    print("\n\nEXECUTING COMMAND >>> $ conda %s\n\n" % " ".join(arguments),
          file=sys.stderr)
    with stderr_log_level(TEST_LOG_LEVEL,
                          "conda"), stderr_log_level(TEST_LOG_LEVEL,
                                                     "requests"):
        arguments = encode_arguments(arguments)
        is_run = arguments[0] == "run"
        if is_run:
            cap_args = (None, None)
        with argv(["python_api"] + arguments), captured(*cap_args) as c:
            if use_exception_handler:
                result = conda_exception_handler(do_call, args, p)
            else:
                result = do_call(args, p)
        if is_run:
            stdout = result.stdout
            stderr = result.stderr
            result = result.rc
        else:
            stdout = c.stdout
            stderr = c.stderr
        print(stdout, file=sys.stdout)
        print(stderr, file=sys.stderr)

    # Unfortunately there are other ways to change context, such as Commands.CREATE --offline.
    # You will probably end up playing whack-a-bug here adding more and more the tuple here.
    if command in (Commands.CONFIG, ):
        reset_context([os.path.join(prefix + os.sep, "condarc")], args)
    return stdout, stderr, result