Пример #1
0
def main(*args):
    if not args:
        args = sys.argv

    if not args:
        args = sys.argv

    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('shell.'):
                from ..activate import main as activator_main
                return activator_main()
            elif argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
            if argv1 in ('activate', 'deactivate'):
                from ..exceptions import CommandNotFoundError
                raise CommandNotFoundError(argv1)
        except Exception as e:
            from ..exceptions import handle_exception
            from ..gateways import initialize_logging
            initialize_logging()
            return handle_exception(e)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args)
Пример #2
0
def main(*args):
    # conda.common.compat contains only stdlib imports
    from ..common.compat import ensure_text_type  # , init_std_stream_encoding

    # init_std_stream_encoding()
    if not args:
        args = sys.argv

    args = tuple(ensure_text_type(s) for s in args)

    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('shell.'):
                from ..activate import main as activator_main
                return activator_main()
            elif argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
            elif argv1 in ('activate', 'deactivate'):
                from ..exceptions import CommandNotFoundError
                raise CommandNotFoundError(argv1)
        except Exception as e:
            _, exc_val, exc_tb = sys.exc_info()
            init_loggers()
            from ..exceptions import ExceptionHandler
            return ExceptionHandler().handle_exception(exc_val, exc_tb)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args)
Пример #3
0
Файл: main.py Проект: ESSS/conda
def main(*args):
    if not args:
        args = sys.argv

    if not args:
        args = sys.argv

    log.debug("conda.cli.main called with %s", args)
    if len(args) > 1:
        argv1 = args[1].strip()
        if argv1.startswith('..'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):

            message = "'%s' is not a conda command.\n" % argv1
            from ..common.compat import on_win
            if not on_win:
                message += ' Did you mean "source %s" ?\n' % ' '.join(args[1:])

            from ..exceptions import CommandNotFoundError
            raise CommandNotFoundError(argv1, message)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args)
Пример #4
0
def main(*args):
    if not args:
        args = sys.argv

    if not args:
        args = sys.argv

    log.debug("conda.cli.main called with %s", args)
    if len(args) > 1:
        argv1 = args[1].strip()
        if argv1.startswith('..'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):

            message = "'%s' is not a conda command.\n" % argv1
            from ..common.compat import on_win
            if not on_win:
                message += ' Did you mean "source %s" ?\n' % ' '.join(args[1:])

            from ..exceptions import CommandNotFoundError
            raise CommandNotFoundError(argv1, message)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args)
Пример #5
0
def main(*args, **kwargs):
    # conda.common.compat contains only stdlib imports
    from ..common.compat import ensure_text_type, init_std_stream_encoding

    init_std_stream_encoding()

    if not args:
        if sys.platform == 'win32' and sys.version_info[0] == 2:
            args = sys.argv = win32_unicode_argv()
        else:
            args = sys.argv

    args = tuple(ensure_text_type(s) for s in args)

    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('shell.'):
                from ..activate import main as activator_main
                return activator_main()
            elif argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
        except Exception:
            _, exc_val, exc_tb = sys.exc_info()
            init_loggers()
            from ..exceptions import ExceptionHandler
            return ExceptionHandler().handle_exception(exc_val, exc_tb)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args, **kwargs)
Пример #6
0
def main(*args, **kwargs):
    # conda.common.compat contains only stdlib imports
    from ..common.compat import ensure_text_type, init_std_stream_encoding

    init_std_stream_encoding()

    if not args:
        args = sys.argv

    args = tuple(ensure_text_type(s) for s in args)

    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('shell.'):
                from ..activate import main as activator_main
                return activator_main()
            elif argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
        except Exception as e:
            _, exc_val, exc_tb = sys.exc_info()
            init_loggers()
            from ..exceptions import ExceptionHandler
            return ExceptionHandler().handle_exception(exc_val, exc_tb)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args, **kwargs)
Пример #7
0
def main(*args):
    if not args:
        args = sys.argv

    args = tuple(_ensure_text_type(s) for s in args)

    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('shell.'):
                from ..activate import main as activator_main
                return activator_main()
            elif argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
            elif argv1 in ('activate', 'deactivate'):
                from ..exceptions import CommandNotFoundError
                raise CommandNotFoundError(argv1)
        except Exception as e:
            from ..exceptions import handle_exception
            init_loggers()
            return handle_exception(e)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args)
Пример #8
0
def _main():
    log.debug("conda.cli.main called with %s", sys.argv)
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv', '..changeps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):

            message = "'%s' is not a conda command.\n" % argv1
            if not on_win:
                message += ' Did you mean "source %s" ?\n' % ' '.join(sys.argv[1:])

            raise CommandNotFoundError(argv1, message)

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    p, sub_parsers = generate_parser()

    main_modules = ["info", "help", "list", "search", "create", "install", "update",
                    "remove", "config", "clean"]
    modules = ["conda.cli.main_"+suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands

    def completer(prefix, **kwargs):
        return [i for i in list(sub_parsers.choices) + find_commands()
                if i.startswith(prefix)]

    sub_parsers.completer = completer
    args = p.parse_args()

    context._add_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)

    if context.debug:
        set_all_logger_level(DEBUG)
    elif context.verbosity:
        set_verbosity(context.verbosity)
        log.debug("verbosity set to %s", context.verbosity)

    exit_code = args.func(args, p)
    if isinstance(exit_code, int):
        return exit_code
Пример #9
0
def main(*args, **kwargs):
    # conda.common.compat contains only stdlib imports
    from ..common.compat import ensure_text_type, init_std_stream_encoding

    init_std_stream_encoding()

    if not args:
        args = sys.argv

    args = tuple(ensure_text_type(s) for s in args)

    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('shell.'):
                from ..activate import main as activator_main
                return activator_main()
            elif argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
        except Exception:
            _, exc_val, exc_tb = sys.exc_info()
            init_loggers()
            from ..exceptions import ExceptionHandler
            return ExceptionHandler().handle_exception(exc_val, exc_tb)

    from ..exceptions import conda_exception_handler
    # on Windows, we need to add to PATH so that we find the libraries
    #   associated with this specific env Without this, we see lots of openssl
    #   HTTPErrors because either incorrect libraries or no libraries are
    #   present
    if sys.platform == "win32":
        from ..activate import _Activator
        from ..base.context import context
        import os
        os.environ["PATH"] = (';'.join(_Activator._get_path_dirs(context.root_prefix)) + ';' +
                              os.environ["PATH"])
    return conda_exception_handler(_main, *args, **kwargs)
Пример #10
0
def main(*args):
    if not args:
        args = sys.argv

    if not args:
        args = sys.argv

    log.debug("conda.cli.main called with %s", args)
    if len(args) > 1:
        try:
            argv1 = args[1].strip()
            if argv1.startswith('..'):
                import conda.cli.activate as activate
                activate.main()
                return
            if argv1 in ('activate', 'deactivate'):
                from ..exceptions import CommandNotFoundError
                raise CommandNotFoundError(argv1)
        except Exception as e:
            from ..exceptions import handle_exception
            return handle_exception(e)

    from ..exceptions import conda_exception_handler
    return conda_exception_handler(_main, *args)
Пример #11
0
Файл: main.py Проект: 3kwa/conda
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv', '..setps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing and deploying applications,'
                    ' environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action='version',
        version='conda %s' % conda.__version__,
        help="Show the conda version number and exit."
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = "Show debug output."
    )
    p.add_argument(
        "--json",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_modules = ["info", "help", "list", "search", "create", "install", "update",
                    "remove", "run", "config", "init", "clean", "package", "bundle"]
    modules = ["conda.cli.main_"+suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands
    sub_parsers.completer = lambda prefix, **kwargs: [i for i in
        list(sub_parsers.choices) + find_commands() if i.startswith(prefix)]
    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    args_func(args, p)
Пример #12
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if argv1 == 'pip':
            sys.exit("""ERROR:
The "conda pip" command has been removed from conda (as of version 1.8) for
the following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
""")
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ['share', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.builder.share import old_create_bundle
            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings),
                      sys.stdout, indent=2, sort_keys=True)
            return
        if sys.argv[1:4] == ['clone', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.builder.share import old_clone_bundle
            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action = 'version',
        version = 'conda %s' % conda.__version__,
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_info.configure_parser(sub_parsers)
    main_help.configure_parser(sub_parsers)
    main_list.configure_parser(sub_parsers)
    main_search.configure_parser(sub_parsers)
    main_create.configure_parser(sub_parsers)
    main_install.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers)
    main_config.configure_parser(sub_parsers)
    main_init.configure_parser(sub_parsers)
    main_clean.configure_parser(sub_parsers)
    main_build.configure_parser(sub_parsers)
    main_skeleton.configure_parser(sub_parsers)
    main_package.configure_parser(sub_parsers)
    main_bundle.configure_parser(sub_parsers)
    main_index.configure_parser(sub_parsers)

    try:
        import argcomplete
        argcomplete.autocomplete(p)
    except ImportError:
        pass
    except AttributeError:
        # On Python 3.3, argcomplete can be an empty namespace package when
        # argcomplete is not installed. Not sure why, but this fixes it.
        pass

    args = p.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)

    if (not main_init.is_initialized() and
        'init' not in sys.argv and 'info' not in sys.argv):
        sys.exit("Error: conda is not initalized yet, try: conda init")

    try:
        args.func(args, p)
    except RuntimeError as e:
        sys.exit("Error: %s" % e)
    except Exception as e:
        if e.__class__.__name__ not in ('ScannerError', 'ParserError'):
            print("""\
An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

    https://github.com/ContinuumIO/conda/issues

Include the output of the command 'conda info' in your report.

""")
        raise  # as if we did not catch it
Пример #13
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ("..activate", "..deactivate", "..activateroot", "..checkenv"):
            import conda.cli.activate as activate

            activate.main()
            return
        if argv1 in ("..changeps1"):
            import conda.cli.misc as misc

            misc.main()
            return
        if argv1 == "pip":
            sys.exit(
                """ERROR:
The "conda pip" command has been removed from conda (as of version 1.8) for
the following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
"""
            )
        if argv1 in ("activate", "deactivate"):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != "win32":
                sys.stderr.write('Did you mean "source %s" ?\n' % " ".join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ["share", "--json", "--prefix"]:
            import json
            from os.path import abspath
            from conda.share import old_create_bundle

            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings), sys.stdout, indent=2, sort_keys=True)
            return
        if sys.argv[1:4] == ["clone", "--json", "--prefix"]:
            import json
            from os.path import abspath
            from conda.share import old_clone_bundle

            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append("-h")

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description="conda is a tool for managing and deploying applications, environments and packages."
    )
    p.add_argument(
        "-V",
        "--version",
        action="version",
        version="conda %s" % conda.__version__,
        help="Show the conda version number and exit.",
    )
    p.add_argument("--debug", action="store_true", help="Show debug output.")
    p.add_argument("--json", action="store_true", help=argparse.SUPPRESS)
    sub_parsers = p.add_subparsers(metavar="command", dest="cmd")

    from conda.cli import main_info

    main_info.configure_parser(sub_parsers)
    from conda.cli import main_help

    main_help.configure_parser(sub_parsers)
    from conda.cli import main_list

    main_list.configure_parser(sub_parsers)
    from conda.cli import main_search

    main_search.configure_parser(sub_parsers)
    from conda.cli import main_create

    main_create.configure_parser(sub_parsers)
    from conda.cli import main_install

    main_install.configure_parser(sub_parsers)
    from conda.cli import main_update

    main_update.configure_parser(sub_parsers)
    from conda.cli import main_remove

    main_remove.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers, name="uninstall")
    from conda.cli import main_run

    main_run.configure_parser(sub_parsers)
    from conda.cli import main_config

    main_config.configure_parser(sub_parsers)
    from conda.cli import main_init

    main_init.configure_parser(sub_parsers)
    from conda.cli import main_clean

    main_clean.configure_parser(sub_parsers)
    from conda.cli import main_package

    main_package.configure_parser(sub_parsers)
    from conda.cli import main_bundle

    main_bundle.configure_parser(sub_parsers)

    from conda.cli.find_commands import find_commands

    sub_parsers.completer = lambda prefix, **kwargs: [
        i for i in list(sub_parsers.choices) + find_commands() if i.startswith(prefix)
    ]
    args = p.parse_args()

    if getattr(args, "json", False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ("fetch", "progress"):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    if not main_init.is_initialized() and "init" not in sys.argv and "info" not in sys.argv:
        if hasattr(args, "name") and hasattr(args, "prefix"):
            import conda.config as config
            from conda.cli import common

            if common.get_prefix(args) == config.root_dir:
                sys.exit(
                    """\
Error: This installation of conda is not initialized. Use 'conda create -n
envname' to create a conda environment and 'source activate envname' to
activate it.

# Note that pip installing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html"""
                )

    args_func(args, p)
Пример #14
0
def _main():
    log.debug("conda.cli.main called with %s", sys.argv)
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv',
                     '..changeps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):

            message = "'%s' is not a conda command.\n" % argv1
            if not on_win:
                message += ' Did you mean "source %s" ?\n' % ' '.join(
                    sys.argv[1:])

            raise CommandNotFoundError(argv1, message)

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    p, sub_parsers = generate_parser()

    main_modules = [
        "info", "help", "list", "search", "create", "install", "update",
        "remove", "config", "clean", "package"
    ]
    modules = ["conda.cli.main_" + suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands

    def completer(prefix, **kwargs):
        return [
            i for i in list(sub_parsers.choices) + find_commands()
            if i.startswith(prefix)
        ]

    sub_parsers.completer = completer
    args = p.parse_args()

    context._add_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)

    if context.debug:
        set_all_logger_level(DEBUG)
    elif context.verbosity:
        set_verbosity(context.verbosity)
        log.debug("verbosity set to %s", context.verbosity)

    exit_code = args.func(args, p)
    if isinstance(exit_code, int):
        return exit_code
Пример #15
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..activateroot',
                     '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if argv1 == 'pip':
            sys.exit("""ERROR:
The "conda pip" command has been removed from conda (as of version 1.8) for
the following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
""")
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ['share', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_create_bundle
            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings),
                      sys.stdout,
                      indent=2,
                      sort_keys=True)
            return
        if sys.argv[1:4] == ['clone', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_clone_bundle
            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing environments and packages.')
    p.add_argument(
        '-V',
        '--version',
        action='version',
        version='conda %s' % conda.__version__,
    )
    p.add_argument(
        "--debug",
        action="store_true",
        help=argparse.SUPPRESS,
    )
    p.add_argument(
        "--json",
        action="store_true",
        help=argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar='command',
        dest='cmd',
    )

    main_info.configure_parser(sub_parsers)
    main_help.configure_parser(sub_parsers)
    main_list.configure_parser(sub_parsers)
    main_search.configure_parser(sub_parsers)
    main_create.configure_parser(sub_parsers)
    main_install.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers)
    main_run.configure_parser(sub_parsers)
    main_config.configure_parser(sub_parsers)
    main_init.configure_parser(sub_parsers)
    main_clean.configure_parser(sub_parsers)
    main_package.configure_parser(sub_parsers)
    main_bundle.configure_parser(sub_parsers)

    try:
        import argcomplete
        argcomplete.autocomplete(p)
    except ImportError:
        pass
    except AttributeError:
        # On Python 3.3, argcomplete can be an empty namespace package when
        # we are in the conda-recipes directory.
        pass

    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        import logging
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    if (not main_init.is_initialized() and 'init' not in sys.argv
            and 'info' not in sys.argv):
        if hasattr(args, 'name') and hasattr(args, 'prefix'):
            import conda.config as config
            if common.get_prefix(args) == config.root_dir:
                sys.exit("""\
Error: This installation of conda is not initialized. Use 'conda create -n
envname' to create a conda environment and 'source activate envname' to
activate it.

# Note that pip installing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html""")

    args_func(args, p)
Пример #16
0
def _main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv', '..changeps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):

            message = "Error: '%s' is not a conda command.\n" % argv1
            if sys.platform != 'win32':
                message += ' Did you mean "source %s" ?\n' % ' '.join(sys.argv[1:])

            raise CommandNotFoundError(message)

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing and deploying applications,'
                    ' environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action='version',
        version='conda %s' % conda.__version__,
        help="Show the conda version number and exit."
    )
    p.add_argument(
        "--debug",
        action="store_true",
        help="Show debug output."
    )
    p.add_argument(
        "--json",
        action="store_true",
        help=argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar='command',
        dest='cmd',
    )
    # http://bugs.python.org/issue9253
    # http://stackoverflow.com/a/18283730/1599393
    sub_parsers.required = True

    main_modules = ["info", "help", "list", "search", "create", "install", "update",
                    "remove", "config", "clean"]
    modules = ["conda.cli.main_"+suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands

    def completer(prefix, **kwargs):
        return [i for i in list(sub_parsers.choices) + find_commands()
                if i.startswith(prefix)]

    sub_parsers.completer = completer
    args = p.parse_args()

    conda.config.output_json = args.json

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    exit_code = args.func(args, p)
    if isinstance(exit_code, int):
        return exit_code
Пример #17
0
def _main(*args):
    from ..base.constants import SEARCH_PATH
    from ..base.context import context
    from ..common.compat import on_win
    from ..gateways.logging import set_all_logger_level, set_verbosity
    from ..exceptions import CommandNotFoundError
    if not args:
        args = sys.argv

    if not args:
        args = sys.argv

    log.debug("conda.cli.main called with %s", args)
    if len(args) > 1:
        argv1 = args[1].strip()
        if argv1 in ('..activate', '..deactivate', '..checkenv',
                     '..changeps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):

            message = "'%s' is not a conda command.\n" % argv1
            if not on_win:
                message += ' Did you mean "source %s" ?\n' % ' '.join(args[1:])

            raise CommandNotFoundError(argv1, message)

    if len(args) == 1:
        args.append('-h')

    p, sub_parsers = generate_parser()

    main_modules = [
        "info", "help", "list", "search", "create", "install", "update",
        "remove", "config", "clean", "package"
    ]
    modules = ["conda.cli.main_" + suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands

    def completer(prefix, **kwargs):
        return [
            i for i in list(sub_parsers.choices) + find_commands()
            if i.startswith(prefix)
        ]

    # when using sys.argv, first argument is generally conda or __main__.py.  Ignore it.
    if (any(sname in args[0] for sname in ('conda', 'conda.exe', '__main__.py',
                                           'conda-script.py'))
            and (args[1] in main_modules + find_commands()
                 or args[1].startswith('-'))):
        log.debug("Ignoring first argument (%s), as it is not a subcommand",
                  args[0])
        args = args[1:]

    sub_parsers.completer = completer
    args = p.parse_args(args)

    context.__init__(SEARCH_PATH, 'conda', 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)

    if context.debug:
        set_all_logger_level(DEBUG)
    elif context.verbosity:
        set_verbosity(context.verbosity)
        log.debug("verbosity set to %s", context.verbosity)

    exit_code = args.func(args, p)
    if isinstance(exit_code, int):
        return exit_code
Пример #18
0
def main():
    if len(sys.argv) > 1:
        if sys.argv[1] in ('..activate', '..deactivate', '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if sys.argv[1] in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if sys.argv[1] == 'pip':
            sys.exit("""ERROR:
The "conda pip" command has been removed from conda version 1.8 for the
following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
""")
    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action = 'version',
        version = 'conda %s' % conda.__version__,
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_info.configure_parser(sub_parsers)
    main_help.configure_parser(sub_parsers)
    main_list.configure_parser(sub_parsers)
    main_search.configure_parser(sub_parsers)
    main_create.configure_parser(sub_parsers)
    main_install.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers)
    main_config.configure_parser(sub_parsers)
    main_clean.configure_parser(sub_parsers)
    main_build.configure_parser(sub_parsers)
    main_skeleton.configure_parser(sub_parsers)
    main_package.configure_parser(sub_parsers)
    main_index.configure_parser(sub_parsers)

    try:
        import argcomplete
        argcomplete.autocomplete(p)
    except ImportError:
        pass
    except AttributeError:
        # On Python 3.3, argcomplete can be an empty namespace package when
        # argcomplete is not installed. Not sure why, but this fixes it.
        pass

    args = p.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)

    try:
        args.func(args, p)
    except RuntimeError as e:
        sys.exit("Error: %s" % e)
    except Exception as e:
        if e.__class__.__name__ not in ('ScannerError', 'ParserError'):
            print("""\
An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

    https://github.com/ContinuumIO/conda/issues

Include the output of the command 'conda info' in your report.

""")
        raise  # as if we did not catch it
Пример #19
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..activateroot', '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if argv1 == 'pip':
            sys.exit("""ERROR:
The "conda pip" command has been removed from conda (as of version 1.8) for
the following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
""")
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ['share', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_create_bundle
            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings),
                      sys.stdout, indent=2, sort_keys=True)
            return
        if sys.argv[1:4] == ['clone', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_clone_bundle
            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action = 'version',
        version = 'conda %s' % conda.__version__,
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_info.configure_parser(sub_parsers)
    main_help.configure_parser(sub_parsers)
    main_list.configure_parser(sub_parsers)
    main_search.configure_parser(sub_parsers)
    main_create.configure_parser(sub_parsers)
    main_install.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers)
    main_config.configure_parser(sub_parsers)
    main_init.configure_parser(sub_parsers)
    main_clean.configure_parser(sub_parsers)
    main_package.configure_parser(sub_parsers)
    main_bundle.configure_parser(sub_parsers)

    try:
        import argcomplete
        argcomplete.autocomplete(p)
    except ImportError:
        pass
    except AttributeError:
        # On Python 3.3, argcomplete can be an empty namespace package when
        # we are in the conda-recipes directory.
        pass

    args = p.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)

    if (not main_init.is_initialized() and
        'init' not in sys.argv and 'info' not in sys.argv):
        sys.exit("""Error: conda is not initialized yet, try: conda init
# Note that initializing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html""")

    try:
        args.func(args, p)
    except RuntimeError as e:
        sys.exit("Error: %s" % e)
    except Exception as e:
        if e.__class__.__name__ not in ('ScannerError', 'ParserError'):
            print("""\
An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

    https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.

""")
        raise  # as if we did not catch it
Пример #20
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..activateroot', '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if argv1 == 'pip':
            sys.exit("""ERROR:
The "conda pip" command has been removed from conda (as of version 1.8) for
the following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
""")
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ['share', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_create_bundle
            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings),
                      sys.stdout, indent=2, sort_keys=True)
            return
        if sys.argv[1:4] == ['clone', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_clone_bundle
            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action = 'version',
        version = 'conda %s' % conda.__version__,
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    p.add_argument(
        "--json",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_info.configure_parser(sub_parsers)
    main_help.configure_parser(sub_parsers)
    main_list.configure_parser(sub_parsers)
    main_search.configure_parser(sub_parsers)
    main_create.configure_parser(sub_parsers)
    main_install.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers)
    main_run.configure_parser(sub_parsers)
    main_config.configure_parser(sub_parsers)
    main_init.configure_parser(sub_parsers)
    main_clean.configure_parser(sub_parsers)
    main_package.configure_parser(sub_parsers)
    main_bundle.configure_parser(sub_parsers)

    try:
        import argcomplete
        argcomplete.autocomplete(p)
    except ImportError:
        pass
    except AttributeError:
        # On Python 3.3, argcomplete can be an empty namespace package when
        # we are in the conda-recipes directory.
        pass

    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        import logging
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    if (not main_init.is_initialized() and
        'init' not in sys.argv and 'info' not in sys.argv):
        sys.exit("""Error: conda is not initialized yet, try: conda init
# Note that initializing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html""")

    args_func(args, p)
Пример #21
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv', '..setps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 == 'pip':
            sys.exit("""ERROR:
The "conda pip" command has been removed from conda (as of version 1.8) for
the following reasons:
  * users get the wrong impression that you *must* use conda pip (instead
    of simply pip) when using Anaconda
  * there should only be one preferred way to build packages, and that is
    the conda build command
  * the command did too many things at once, i.e. build a package and
    then also install it
  * the command is Python centric, whereas conda (from a package management
    perspective) is Python agnostic
  * packages created with conda pip are not robust, i.e. they will maybe
    not work on other people's systems

In short:
  * use "conda build" if you want to build a conda package
  * use "conda install" if you want to install something
  * use "pip" if you want to install something that is on PyPI for which there
    isn't a conda package.
""")
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ['share', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_create_bundle
            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings),
                      sys.stdout, indent=2, sort_keys=True)
            return
        if sys.argv[1:4] == ['clone', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_clone_bundle
            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing and deploying applications,'
                    ' environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action='version',
        version='conda %s' % conda.__version__,
        help="Show the conda version number and exit."
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = "Show debug output."
    )
    p.add_argument(
        "--json",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_modules = ["info", "help", "list", "search", "create", "install", "update",
                    "remove", "run", "config", "init", "clean", "package", "bundle"]
    modules = ["conda.cli.main_"+suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands
    sub_parsers.completer = lambda prefix, **kwargs: [i for i in
        list(sub_parsers.choices) + find_commands() if i.startswith(prefix)]
    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    from conda.cli import main_init
    if (not main_init.is_initialized() and
        'init' not in sys.argv and 'info' not in sys.argv):
        if hasattr(args, 'name') and hasattr(args, 'prefix'):
            import conda.config as config
            from conda.cli import common
            if common.get_prefix(args) == config.root_dir:
                sys.exit("""\
Error: This installation of conda is not initialized. Use 'conda create -n
envname' to create a conda environment and 'source activate envname' to
activate it.

# Note that pip installing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html""")

    args_func(args, p)
Пример #22
0
def main():
    if len(sys.argv) > 1 and sys.argv[1] in ('..activate', '..deactivate', '..changeps1'):
        import conda.cli.activate as activate
        activate.main()
        return
    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action = 'version',
        version = 'conda %s' % conda.__version__,
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    main_info.configure_parser(sub_parsers)
    main_help.configure_parser(sub_parsers)
    main_list.configure_parser(sub_parsers)
    main_search.configure_parser(sub_parsers)
    main_create.configure_parser(sub_parsers)
    main_install.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers)
    main_package.configure_parser(sub_parsers)
    main_pip.configure_parser(sub_parsers)
    main_skeleton.configure_parser(sub_parsers)
    main_share.configure_parser(sub_parsers)
    main_clone.configure_parser(sub_parsers)
    main_build.configure_parser(sub_parsers)
    main_index.configure_parser(sub_parsers)
    main_config.configure_parser(sub_parsers)

    args = p.parse_args()

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)

    try:
        args.func(args, p)
    except RuntimeError as e:
        sys.exit(filldedent("Error: %s" % e))
    except Exception as e:
        if e.__class__.__name__ not in ('ScannerError', 'ParserError'):
            print("""\
An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

    https://github.com/ContinuumIO/conda/issues"

""")
        raise  # as if we did not catch it
Пример #23
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate',
                     '..activateroot', '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing and deploying applications, environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action='version',
        version='conda %s' % conda.__version__,
        help="Show the conda version number and exit."
    )
    p.add_argument(
        "--debug",
        action = "store_true",
        help = "Show debug output."
    )
    p.add_argument(
        "--json",
        action = "store_true",
        help = argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar = 'command',
        dest = 'cmd',
    )

    from conda.cli import main_info
    main_info.configure_parser(sub_parsers)
    from conda.cli import main_help
    main_help.configure_parser(sub_parsers)
    from conda.cli import main_list
    main_list.configure_parser(sub_parsers)
    from conda.cli import main_search
    main_search.configure_parser(sub_parsers)
    from conda.cli import main_create
    main_create.configure_parser(sub_parsers)
    from conda.cli import main_install
    main_install.configure_parser(sub_parsers)
    from conda.cli import main_update
    main_update.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers, name='upgrade')
    from conda.cli import main_remove
    main_remove.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers, name='uninstall')
    from conda.cli import main_run
    main_run.configure_parser(sub_parsers)
    from conda.cli import main_config
    main_config.configure_parser(sub_parsers)
    from conda.cli import main_init
    main_init.configure_parser(sub_parsers)
    from conda.cli import main_clean
    main_clean.configure_parser(sub_parsers)
    from conda.cli import main_package
    main_package.configure_parser(sub_parsers)
    from conda.cli import main_bundle
    main_bundle.configure_parser(sub_parsers)

    from conda.cli.find_commands import find_commands
    sub_parsers.completer = lambda prefix, **kwargs: [i for i in
        list(sub_parsers.choices) + find_commands() if i.startswith(prefix)]
    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    if (not main_init.is_initialized() and
        'init' not in sys.argv and 'info' not in sys.argv):
        if hasattr(args, 'name') and hasattr(args, 'prefix'):
            import conda.config as config
            from conda.cli import common
            if common.get_prefix(args) == config.root_dir:
                sys.exit("""\
Error: This installation of conda is not initialized. Use 'conda create -n
envname' to create a conda environment and 'source activate envname' to
activate it.

# Note that pip installing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html""")

    args_func(args, p)
Пример #24
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..checkenv', '..setps1'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description='conda is a tool for managing and deploying applications,'
                    ' environments and packages.'
    )
    p.add_argument(
        '-V', '--version',
        action='version',
        version='conda %s' % conda.__version__,
        help="Show the conda version number and exit."
    )
    p.add_argument(
        "--debug",
        action="store_true",
        help="Show debug output."
    )
    p.add_argument(
        "--json",
        action="store_true",
        help=argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar='command',
        dest='cmd',
    )

    main_modules = ["info", "help", "list", "search", "create", "install", "update",
                    "remove", "run", "config", "init", "clean", "package", "bundle"]
    modules = ["conda.cli.main_"+suffix for suffix in main_modules]
    for module in modules:
        imported = importlib.import_module(module)
        imported.configure_parser(sub_parsers)
        if "update" in module:
            imported.configure_parser(sub_parsers, name='upgrade')
        if "remove" in module:
            imported.configure_parser(sub_parsers, name='uninstall')

    from conda.cli.find_commands import find_commands

    def completer(prefix, **kwargs):
        return [i for i in list(sub_parsers.choices) + find_commands()
                if i.startswith(prefix)]

    sub_parsers.completer = completer
    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    args_func(args, p)
Пример #25
0
def main():
    if len(sys.argv) > 1:
        argv1 = sys.argv[1]
        if argv1 in ('..activate', '..deactivate', '..activateroot',
                     '..checkenv'):
            import conda.cli.activate as activate
            activate.main()
            return
        if argv1 in ('..changeps1'):
            import conda.cli.misc as misc
            misc.main()
            return
        if argv1 in ('activate', 'deactivate'):
            sys.stderr.write("Error: '%s' is not a conda command.\n" % argv1)
            if sys.platform != 'win32':
                sys.stderr.write('Did you mean "source %s" ?\n' %
                                 ' '.join(sys.argv[1:]))
            sys.exit(1)

        # for backwards compatibility of conda-api
        if sys.argv[1:4] == ['share', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_create_bundle
            prefix = sys.argv[4]
            path, warnings = old_create_bundle(abspath(prefix))
            json.dump(dict(path=path, warnings=warnings),
                      sys.stdout,
                      indent=2,
                      sort_keys=True)
            return
        if sys.argv[1:4] == ['clone', '--json', '--prefix']:
            import json
            from os.path import abspath
            from conda.share import old_clone_bundle
            prefix, path = sys.argv[4:6]
            old_clone_bundle(path, abspath(prefix))
            json.dump(dict(warnings=[]), sys.stdout, indent=2)
            return

    if len(sys.argv) == 1:
        sys.argv.append('-h')

    import logging
    from conda.cli import conda_argparse
    import argparse
    import conda

    p = conda_argparse.ArgumentParser(
        description=
        'conda is a tool for managing and deploying applications, environments and packages.'
    )
    p.add_argument('-V',
                   '--version',
                   action='version',
                   version='conda %s' % conda.__version__,
                   help="Show the conda version number and exit.")
    p.add_argument("--debug", action="store_true", help="Show debug output.")
    p.add_argument(
        "--json",
        action="store_true",
        help=argparse.SUPPRESS,
    )
    sub_parsers = p.add_subparsers(
        metavar='command',
        dest='cmd',
    )

    from conda.cli import main_info
    main_info.configure_parser(sub_parsers)
    from conda.cli import main_help
    main_help.configure_parser(sub_parsers)
    from conda.cli import main_list
    main_list.configure_parser(sub_parsers)
    from conda.cli import main_search
    main_search.configure_parser(sub_parsers)
    from conda.cli import main_create
    main_create.configure_parser(sub_parsers)
    from conda.cli import main_install
    main_install.configure_parser(sub_parsers)
    from conda.cli import main_update
    main_update.configure_parser(sub_parsers)
    main_update.configure_parser(sub_parsers, name='upgrade')
    from conda.cli import main_remove
    main_remove.configure_parser(sub_parsers)
    main_remove.configure_parser(sub_parsers, name='uninstall')
    from conda.cli import main_run
    main_run.configure_parser(sub_parsers)
    from conda.cli import main_config
    main_config.configure_parser(sub_parsers)
    from conda.cli import main_init
    main_init.configure_parser(sub_parsers)
    from conda.cli import main_clean
    main_clean.configure_parser(sub_parsers)
    from conda.cli import main_package
    main_package.configure_parser(sub_parsers)
    from conda.cli import main_bundle
    main_bundle.configure_parser(sub_parsers)

    from conda.cli.find_commands import find_commands
    sub_parsers.completer = lambda prefix, **kwargs: [
        i for i in list(sub_parsers.choices) + find_commands()
        if i.startswith(prefix)
    ]
    args = p.parse_args()

    if getattr(args, 'json', False):
        # Silence logging info to avoid interfering with JSON output
        for logger in logging.Logger.manager.loggerDict:
            if logger not in ('fetch', 'progress'):
                logging.getLogger(logger).setLevel(logging.CRITICAL + 1)

    if args.debug:
        logging.disable(logging.NOTSET)
        logging.basicConfig(level=logging.DEBUG)

    if (not main_init.is_initialized() and 'init' not in sys.argv
            and 'info' not in sys.argv):
        if hasattr(args, 'name') and hasattr(args, 'prefix'):
            import conda.config as config
            from conda.cli import common
            if common.get_prefix(args) == config.root_dir:
                sys.exit("""\
Error: This installation of conda is not initialized. Use 'conda create -n
envname' to create a conda environment and 'source activate envname' to
activate it.

# Note that pip installing conda is not the recommended way for setting up your
# system.  The recommended way for setting up a conda system is by installing
# Miniconda, see: http://repo.continuum.io/miniconda/index.html""")

    args_func(args, p)