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)
def execute(args, parser): import os from os.path import basename, dirname import conda import conda.config as config import conda.misc as misc from conda.resolve import Resolve, MatchSpec from conda.cli.main_init import is_initialized from conda.api import get_index, get_package_versions if args.root: if args.json: common.stdout_json({'root_prefix': config.root_dir}) else: print(config.root_dir) return if args.packages: if args.json: results = defaultdict(list) for arg in args.packages: for pkg in get_package_versions(arg): results[arg].append(pkg._asdict()) common.stdout_json(results) return index = get_index() r = Resolve(index) specs = map(common.arg2spec, args.packages) for spec in specs: versions = r.get_pkgs(MatchSpec(spec)) for pkg in versions: pretty_package(pkg) return options = 'envs', 'system', 'license' try: import requests requests_version = requests.__version__ except ImportError: requests_version = "could not import" except Exception as e: requests_version = "Error %s" % e try: import conda_build except ImportError: conda_build_version = "not installed" except Exception as e: conda_build_version = "Error %s" % e else: conda_build_version = conda_build.__version__ info_dict = dict(platform=config.subdir, conda_version=conda.__version__, conda_build_version=conda_build_version, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, user_rc_path=config.user_rc_path, sys_rc_path=config.sys_rc_path, is_foreign=bool(config.foreign), envs=[], python_version='.'.join(map(str, sys.version_info)), requests_version=requests_version, ) if args.all or args.json: for option in options: setattr(args, option, True) info_dict['channels'] = [config.hide_binstar_tokens(c) for c in info_dict['channels']] if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s conda-build version : %(conda_build_version)s python version : %(python_version)s requests version : %(requests_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' is uninitialized""" % config.root_dir) if args.envs: common.handle_envs_list(info_dict['envs'], not args.json) if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable('conda-' + cmd))) print("user site dirs: ", end='') site_dirs = get_user_site() if site_dirs: print(site_dirs[0]) else: print() for site_dir in site_dirs[1:]: print(' %s' % site_dir) print() evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH'] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could not import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
def execute(args, parser): import os from os.path import basename, dirname import conda import conda.config as config import conda.misc as misc from conda.resolve import Resolve, MatchSpec from conda.cli.main_init import is_initialized from conda.api import get_index, get_package_versions if args.root: if args.json: common.stdout_json({'root_prefix': config.root_dir}) else: print(config.root_dir) return if args.packages: if args.json: results = defaultdict(list) for arg in args.packages: for pkg in get_package_versions(arg): results[arg].append(pkg._asdict()) common.stdout_json(results) return index = get_index() r = Resolve(index) specs = map(common.arg2spec, args.packages) for spec in specs: versions = r.get_pkgs(MatchSpec(spec)) for pkg in versions: pretty_package(pkg) return options = 'envs', 'system', 'license' try: import requests requests_version = requests.__version__ except ImportError: requests_version = "could not import" except Exception as e: requests_version = "Error %s" % e try: import conda_build except ImportError: conda_build_version = "not installed" except Exception as e: conda_build_version = "Error %s" % e else: conda_build_version = conda_build.__version__ info_dict = dict( platform=config.subdir, conda_version=conda.__version__, conda_build_version=conda_build_version, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, user_rc_path=config.user_rc_path, sys_rc_path=config.sys_rc_path, is_foreign=bool(config.foreign), envs=[], python_version='.'.join(map(str, sys.version_info)), requests_version=requests_version, ) if args.all or args.json: for option in options: setattr(args, option, True) info_dict['channels_disp'] = [ config.hide_binstar_tokens(c) for c in info_dict['channels'] ] if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels_disp': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s conda-build version : %(conda_build_version)s python version : %(python_version)s requests version : %(requests_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels_disp)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' is uninitialized""" % config.root_dir) del info_dict['channels_disp'] if args.envs: common.handle_envs_list(info_dict['envs'], not args.json) if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable('conda-' + cmd))) print("user site dirs: ", end='') site_dirs = get_user_site() if site_dirs: print(site_dirs[0]) else: print() for site_dir in site_dirs[1:]: print(' %s' % site_dir) print() evars = [ 'PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH' ] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could not import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
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
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) 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)
def execute(args, parser): import os from os.path import basename, dirname, isdir, join import conda import conda.config as config from conda.cli.main_init import is_initialized options = 'envs', 'system', 'license' info_dict = dict(platform=config.subdir, conda_version=conda.__version__, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, envs=[]) if args.all or args.json: for option in options: setattr(args, option, True) if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels)s config file : %(rc_path)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' uninitalized, # use 'conda init' to initialize.""" % config.root_dir) if args.envs: if not args.json: print("# conda environments:") print("#") def disp_env(prefix): fmt = '%-20s %s %s' default = '*' if prefix == config.default_prefix else ' ' name = (config.root_env_name if prefix == config.root_dir else basename(prefix)) if not args.json: print(fmt % (name, default, prefix)) for envs_dir in config.envs_dirs: if not isdir(envs_dir): continue for dn in sorted(os.listdir(envs_dir)): if dn.startswith('.'): continue prefix = join(envs_dir, dn) if isdir(prefix): prefix = join(envs_dir, dn) disp_env(prefix) info_dict['envs'].append(prefix) disp_env(config.root_dir) print() if args.system and not args.json: import sys print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) print() evars = ['PATH', 'PYTHONPATH', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH'] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
def execute(args, parser): if args.args: for arg in args.args: if isfile(arg): from conda.misc import which_package path = arg for dist in which_package(path): print('%-50s %s' % (path, dist)) else: show_pkg_info(arg) return import os from os.path import basename, dirname, isdir, join import conda import conda.config as config from conda.cli.main_init import is_initialized options = 'envs', 'system', 'license' info_dict = dict( platform=config.subdir, conda_version=conda.__version__, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, is_foreign=bool(config.foreign), envs=[], python_version='.'.join(map(str, sys.version_info)), ) if args.all or args.json: for option in options: setattr(args, option, True) if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s python version : %(python_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' uninitalized, # use 'conda init' to initialize.""" % config.root_dir) if args.envs: if not args.json: print("# conda environments:") print("#") def disp_env(prefix): fmt = '%-20s %s %s' default = '*' if prefix == config.default_prefix else ' ' name = (config.root_env_name if prefix == config.root_dir else basename(prefix)) if not args.json: print(fmt % (name, default, prefix)) for envs_dir in config.envs_dirs: if not isdir(envs_dir): continue for dn in sorted(os.listdir(envs_dir)): if dn.startswith('.'): continue prefix = join(envs_dir, dn) if isdir(prefix): prefix = join(envs_dir, dn) disp_env(prefix) info_dict['envs'].append(prefix) disp_env(config.root_dir) print() if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable(cmd))) print() evars = [ 'PATH', 'PYTHONPATH', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH' ] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
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)
def execute(args, parser): import os from os.path import dirname import conda from conda.config import (root_dir, get_channel_urls, subdir, pkgs_dirs, root_writable, envs_dirs, default_prefix, rc_path, user_rc_path, sys_rc_path, foreign, hide_binstar_tokens, platform, offline) from conda.resolve import Resolve from conda.cli.main_init import is_initialized from conda.api import get_index if args.root: if args.json: stdout_json({'root_prefix': root_dir}) else: print(root_dir) return if args.packages: index = get_index() r = Resolve(index) if args.json: stdout_json({ package: [p._asdict() for p in sorted(r.get_pkgs(arg2spec(package)))] for package in args.packages }) else: for package in args.packages: versions = r.get_pkgs(arg2spec(package)) for pkg in sorted(versions): pretty_package(pkg) return options = 'envs', 'system', 'license' try: from conda.install import linked_data root_pkgs = linked_data(sys.prefix) except: root_pkgs = None try: import requests requests_version = requests.__version__ except ImportError: requests_version = "could not import" except Exception as e: requests_version = "Error %s" % e try: cenv = [p for p in itervalues(root_pkgs) if p['name'] == 'conda-env'] conda_env_version = cenv[0]['version'] except: conda_env_version = "not installed" try: import conda_build except ImportError: conda_build_version = "not installed" except Exception as e: conda_build_version = "Error %s" % e else: conda_build_version = conda_build.__version__ channels = get_channel_urls(offline=offline) info_dict = dict( platform=subdir, conda_version=conda.__version__, conda_env_version=conda_env_version, conda_build_version=conda_build_version, root_prefix=root_dir, root_writable=root_writable, pkgs_dirs=pkgs_dirs, envs_dirs=envs_dirs, default_prefix=default_prefix, channels=channels, rc_path=rc_path, user_rc_path=user_rc_path, sys_rc_path=sys_rc_path, is_foreign=bool(foreign), offline=offline, envs=[], python_version='.'.join(map(str, sys.version_info)), requests_version=requests_version, ) if args.unsafe_channels: if not args.json: print("\n".join(info_dict["channels"])) else: print(json.dumps({"channels": info_dict["channels"]})) return 0 else: info_dict['channels'] = [hide_binstar_tokens(c) for c in info_dict['channels']] if args.all or args.json: for option in options: setattr(args, option, True) if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s conda-env version : %(conda_env_version)s conda-build version : %(conda_build_version)s python version : %(python_version)s requests version : %(requests_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels)s config file : %(rc_path)s offline mode : %(offline)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' is uninitialized""" % root_dir) if args.envs: handle_envs_list(info_dict['envs'], not args.json) if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable('conda-' + cmd))) print("user site dirs: ", end='') site_dirs = get_user_site() if site_dirs: print(site_dirs[0]) else: print() for site_dir in site_dirs[1:]: print(' %s' % site_dir) print() evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH'] if platform == 'linux': evars.append('LD_LIBRARY_PATH') elif platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could not import _license.show_info # try: # $ conda install -n root _license""") if args.json: stdout_json(info_dict)
def execute(args, parser): import os from os.path import dirname import conda import conda.config as config from conda.resolve import Resolve from conda.cli.main_init import is_initialized from conda.api import get_index if args.root: if args.json: common.stdout_json({'root_prefix': config.root_dir}) else: print(config.root_dir) return if args.packages: index = get_index() r = Resolve(index) if args.json: common.stdout_json({ package: [p._asdict() for p in sorted(r.get_pkgs(common.arg2spec(package)))] for package in args.packages }) else: for package in args.packages: versions = r.get_pkgs(common.arg2spec(package)) for pkg in sorted(versions): pretty_package(pkg) return options = 'envs', 'system', 'license' try: import requests requests_version = requests.__version__ except ImportError: requests_version = "could not import" except Exception as e: requests_version = "Error %s" % e try: import conda_build except ImportError: conda_build_version = "not installed" except Exception as e: conda_build_version = "Error %s" % e else: conda_build_version = conda_build.__version__ # this is a hack associated with channel weight until we get the package cache reworked # in a future release # for now, just ordering the channels for display in a semi-plausible way d = defaultdict(list) any(d[v[1]].append(k) for k, v in iteritems(config.get_channel_urls())) channels = list(chain.from_iterable(d[q] for q in sorted(d, reverse=True))) info_dict = dict( platform=config.subdir, conda_version=conda.__version__, conda_build_version=conda_build_version, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=channels, rc_path=config.rc_path, user_rc_path=config.user_rc_path, sys_rc_path=config.sys_rc_path, is_foreign=bool(config.foreign), envs=[], python_version='.'.join(map(str, sys.version_info)), requests_version=requests_version, ) if args.unsafe_channels: if not args.json: print("\n".join(info_dict["channels"])) else: print(json.dumps({"channels": info_dict["channels"]})) return 0 else: info_dict['channels'] = [config.hide_binstar_tokens(c) for c in info_dict['channels']] if args.all or args.json: for option in options: setattr(args, option, True) if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s conda-build version : %(conda_build_version)s python version : %(python_version)s requests version : %(requests_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' is uninitialized""" % config.root_dir) if args.envs: common.handle_envs_list(info_dict['envs'], not args.json) if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable('conda-' + cmd))) print("user site dirs: ", end='') site_dirs = get_user_site() if site_dirs: print(site_dirs[0]) else: print() for site_dir in site_dirs[1:]: print(' %s' % site_dir) print() evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH'] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could not import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
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)
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)
def execute(args, parser): import os from os.path import basename, dirname import conda import conda.config as config import conda.misc as misc from conda.cli.main_init import is_initialized from conda.api import get_package_versions, app_is_installed from conda.install import is_linked if args.args: results = defaultdict(list) for arg in args.args: if isfile(arg): from conda.misc import which_package path = arg for dist in which_package(path): if args.json: results[arg].append(dist) else: print('%-50s %s' % (path, dist)) elif arg.endswith('.tar.bz2'): info = None for prefix in misc.list_prefixes(): info = is_linked(prefix, arg[:-8]) if info: break if not info: if args.json: results[arg] = {'installed': []} else: print("Package %s is not installed" % arg) continue info['installed'] = app_is_installed(arg) if args.json: results[arg] = info else: print(arg) print(' %-15s %30s' % ('installed', bool(info.get('installed')))) for key in ('name', 'version', 'build', 'license', 'platform', 'arch', 'size', 'summary'): print(' %-15s %30s' % (key, info.get(key))) else: if args.json: for pkg in get_package_versions(arg): results[arg].append(pkg._asdict()) else: show_pkg_info(arg) if args.json: common.stdout_json(results) return options = 'envs', 'system', 'license' try: import requests requests_version = requests.__version__ except ImportError: requests_version = "could not import" except Exception as e: requests_version = "Error %s" % e try: import conda_build except ImportError: conda_build_version = "not installed" except Exception as e: conda_build_version = "Error %s" % e else: conda_build_version = conda_build.__version__ info_dict = dict( platform=config.subdir, conda_version=conda.__version__, conda_build_version=conda_build_version, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, is_foreign=bool(config.foreign), envs=[], python_version='.'.join(map(str, sys.version_info)), requests_version=requests_version, ) if args.all or args.json: for option in options: setattr(args, option, True) info_dict['channels_disp'] = [ config.hide_binstar_tokens(c) for c in info_dict['channels'] ] if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels_disp': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s conda-build version : %(conda_build_version)s python version : %(python_version)s requests version : %(requests_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels_disp)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' uninitalized, # use 'conda init' to initialize.""" % config.root_dir) del info_dict['channels_disp'] if args.envs: if not args.json: print("# conda environments:") print("#") def disp_env(prefix): fmt = '%-20s %s %s' default = '*' if prefix == config.default_prefix else ' ' name = (config.root_env_name if prefix == config.root_dir else basename(prefix)) if not args.json: print(fmt % (name, default, prefix)) for prefix in misc.list_prefixes(): disp_env(prefix) if prefix != config.root_dir: info_dict['envs'].append(prefix) print() if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable(cmd))) print("user site dirs: ", end='') site_dirs = get_user_site() if site_dirs: print(site_dirs[0]) else: print() for site_dir in site_dirs[1:]: print(' %s' % site_dir) print() evars = [ 'PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH' ] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
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
def execute(args, parser): if args.args: for arg in args.args: if isfile(arg): from conda.misc import which_package path = arg for dist in which_package(path): print("%-50s %s" % (path, dist)) else: show_pkg_info(arg) return import os from os.path import basename, dirname, isdir, join import conda import conda.config as config from conda.cli.main_init import is_initialized options = "envs", "system", "license" info_dict = dict( platform=config.subdir, conda_version=conda.__version__, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, is_foreign=bool(config.foreign), envs=[], ) if args.all or args.json: for option in options: setattr(args, option, True) if args.all or all(not getattr(args, opt) for opt in options): for key in "pkgs_dirs", "envs_dirs", "channels": info_dict["_" + key] = ("\n" + 24 * " ").join(info_dict[key]) info_dict["_rtwro"] = "writable" if info_dict["root_writable"] else "read only" print( """\ Current conda install: platform : %(platform)s conda version : %(conda_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict ) if not is_initialized(): print( """\ # NOTE: # root directory '%s' uninitalized, # use 'conda init' to initialize.""" % config.root_dir ) if args.envs: if not args.json: print("# conda environments:") print("#") def disp_env(prefix): fmt = "%-20s %s %s" default = "*" if prefix == config.default_prefix else " " name = config.root_env_name if prefix == config.root_dir else basename(prefix) if not args.json: print(fmt % (name, default, prefix)) for envs_dir in config.envs_dirs: if not isdir(envs_dir): continue for dn in sorted(os.listdir(envs_dir)): if dn.startswith("."): continue prefix = join(envs_dir, dn) if isdir(prefix): prefix = join(envs_dir, dn) disp_env(prefix) info_dict["envs"].append(prefix) disp_env(config.root_dir) print() if args.system and not args.json: import sys from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ["build"])): print("conda-%s: %s" % (cmd, find_executable(cmd))) print() evars = ["PATH", "PYTHONPATH", "CONDA_DEFAULT_ENV", "CIO_TEST", "CONDA_ENVS_PATH"] if config.platform == "linux": evars.append("LD_LIBRARY_PATH") elif config.platform == "osx": evars.append("DYLD_LIBRARY_PATH") for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, "<not set>"))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print( """\ WARNING: could import _license.show_info # try: # $ conda install -n root _license""" ) if args.json: common.stdout_json(info_dict)
def execute(args, parser): from conda import config from conda.api import get_package_versions, app_is_installed from conda.install import is_linked if args.args: results = defaultdict(list) for arg in args.args: if isfile(arg): from conda.misc import which_package path = arg for dist in which_package(path): if args.json: results[arg].append(dist) else: print('%-50s %s' % (path, dist)) elif arg.endswith('.tar.bz2'): info = is_linked(config.root_dir, arg[:-8]) if not info: if args.json: results[arg] = { 'installed': [] } else: print("Package %s is not installed" % arg) continue info['installed'] = app_is_installed(arg) if args.json: results[arg] = info else: print(arg) print(' %-15s %30s' % ('installed', bool(info.get('installed')))) for key in ('name', 'version', 'build', 'license', 'platform', 'arch', 'size', 'summary'): print(' %-15s %30s' % (key, info.get(key))) else: if args.json: for pkg in get_package_versions(arg): results[arg].append(pkg._asdict()) else: show_pkg_info(arg) if args.json: common.stdout_json(results) return import os from os.path import basename, dirname, isdir, join import conda import conda.config as config from conda.cli.main_init import is_initialized options = 'envs', 'system', 'license' info_dict = dict(platform=config.subdir, conda_version=conda.__version__, root_prefix=config.root_dir, root_writable=config.root_writable, pkgs_dirs=config.pkgs_dirs, envs_dirs=config.envs_dirs, default_prefix=config.default_prefix, channels=config.get_channel_urls(), rc_path=config.rc_path, is_foreign=bool(config.foreign), envs=[], python_version='.'.join(map(str, sys.version_info)), ) if args.all or args.json: for option in options: setattr(args, option, True) t_pat = re.compile(r'binstar\.org/(t/[0-9a-f\-]{4,})') info_dict['channels_disp'] = [t_pat.sub('binstar.org/t/<TOKEN>', c) for c in info_dict['channels']] if args.all or all(not getattr(args, opt) for opt in options): for key in 'pkgs_dirs', 'envs_dirs', 'channels_disp': info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key]) info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else 'read only') print("""\ Current conda install: platform : %(platform)s conda version : %(conda_version)s python version : %(python_version)s root environment : %(root_prefix)s (%(_rtwro)s) default environment : %(default_prefix)s envs directories : %(_envs_dirs)s package cache : %(_pkgs_dirs)s channel URLs : %(_channels_disp)s config file : %(rc_path)s is foreign system : %(is_foreign)s """ % info_dict) if not is_initialized(): print("""\ # NOTE: # root directory '%s' uninitalized, # use 'conda init' to initialize.""" % config.root_dir) del info_dict['channels_disp'] if args.envs: if not args.json: print("# conda environments:") print("#") def disp_env(prefix): fmt = '%-20s %s %s' default = '*' if prefix == config.default_prefix else ' ' name = (config.root_env_name if prefix == config.root_dir else basename(prefix)) if not args.json: print(fmt % (name, default, prefix)) for envs_dir in config.envs_dirs: if not isdir(envs_dir): continue for dn in sorted(os.listdir(envs_dir)): if dn.startswith('.'): continue prefix = join(envs_dir, dn) if isdir(prefix): prefix = join(envs_dir, dn) disp_env(prefix) info_dict['envs'].append(prefix) disp_env(config.root_dir) print() if args.system and not args.json: from conda.cli.find_commands import find_commands, find_executable print("sys.version: %s..." % (sys.version[:40])) print("sys.prefix: %s" % sys.prefix) print("sys.executable: %s" % sys.executable) print("conda location: %s" % dirname(conda.__file__)) for cmd in sorted(set(find_commands() + ['build'])): print("conda-%s: %s" % (cmd, find_executable(cmd))) print() evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV', 'CIO_TEST', 'CONDA_ENVS_PATH'] if config.platform == 'linux': evars.append('LD_LIBRARY_PATH') elif config.platform == 'osx': evars.append('DYLD_LIBRARY_PATH') for ev in sorted(evars): print("%s: %s" % (ev, os.getenv(ev, '<not set>'))) print() if args.license and not args.json: try: from _license import show_info show_info() except ImportError: print("""\ WARNING: could import _license.show_info # try: # $ conda install -n root _license""") if args.json: common.stdout_json(info_dict)
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)