def _create_env_conda_43(prefix, index, full_list_of_packages): assert CONDA_VERSION_MAJOR_MINOR >= (4, 3) from conda.core.package_cache import ProgressiveFetchExtract from conda.core.link import UnlinkLinkTransaction from conda.gateways.disk.create import mkdir_p pfe = ProgressiveFetchExtract(index, full_list_of_packages) pfe.execute() mkdir_p(prefix) txn = UnlinkLinkTransaction.create_from_dists(index, prefix, (), full_list_of_packages) txn.execute()
def to_txn( specs_to_add, specs_to_remove, prefix, to_link, to_unlink, installed_pkg_recs, index=None, ): if index is None: index = [] to_link_records, to_unlink_records = [], [] prefix_data = PrefixData(prefix) final_precs = IndexedSet(prefix_data.iter_records()) lookup_dict = {} for _, c in index: lookup_dict[c.url(with_credentials=True)] = c for _, pkg in to_unlink: for i_rec in installed_pkg_recs: if i_rec.fn == pkg: final_precs.remove(i_rec) to_unlink_records.append(i_rec) break else: print("No package record found!") for c, pkg, jsn_s in to_link: sdir = lookup_dict[split_anaconda_token(c)[0]] rec = to_package_record_from_subjson(sdir, pkg, jsn_s) final_precs.add(rec) to_link_records.append(rec) unlink_precs, link_precs = diff_for_unlink_link_precs( prefix, final_precs=IndexedSet(PrefixGraph(final_precs).graph), specs_to_add=specs_to_add, force_reinstall=context.force_reinstall, ) pref_setup = PrefixSetup( target_prefix=prefix, unlink_precs=unlink_precs, link_precs=link_precs, remove_specs=specs_to_remove, update_specs=specs_to_add, neutered_specs=(), ) conda_transaction = UnlinkLinkTransaction(pref_setup) return conda_transaction
def to_txn(specs_to_add, specs_to_remove, prefix, to_link, to_unlink, index=None): to_link_records, to_unlink_records = [], [] prefix_data = PrefixData(prefix) final_precs = IndexedSet(prefix_data.iter_records()) def get_channel(c): for _, chan in index: if str(chan) == c: return chan for c, pkg in to_unlink: for i_rec in installed_pkg_recs: if i_rec.fn == pkg: final_precs.remove(i_rec) to_unlink_records.append(i_rec) break else: print("No package record found!") for c, pkg, jsn_s in to_link: sdir = get_channel(c) rec = to_package_record_from_subjson(sdir, pkg, jsn_s) final_precs.add(rec) to_link_records.append(rec) final_precs, specs_to_add, specs_to_remove = post_solve_handling( context, prefix_data, final_precs, specs_to_add, specs_to_remove) unlink_precs, link_precs = diff_for_unlink_link_precs( prefix, final_precs=IndexedSet(PrefixGraph(final_precs).graph), specs_to_add=specs_to_add, force_reinstall=context.force_reinstall) pref_setup = PrefixSetup(target_prefix=prefix, unlink_precs=unlink_precs, link_precs=link_precs, remove_specs=specs_to_remove, update_specs=specs_to_add, neutered_specs=()) conda_transaction = UnlinkLinkTransaction(pref_setup) return conda_transaction
def to_txn_precs( specs_to_add, specs_to_remove, prefix, final_precs, ): unlink_precs, link_precs = diff_for_unlink_link_precs( prefix, final_precs=final_precs, specs_to_add=specs_to_add, force_reinstall=context.force_reinstall, ) pref_setup = PrefixSetup( target_prefix=prefix, unlink_precs=unlink_precs, link_precs=link_precs, remove_specs=specs_to_remove, update_specs=specs_to_add, neutered_specs=(), ) conda_transaction = UnlinkLinkTransaction(pref_setup) return conda_transaction
def create_env(repo, pkgs, target): with Locked(target): spec_fname = os.path.join(repo.working_dir, 'env.spec') with open(spec_fname, 'r') as fh: spec = yaml.safe_load(fh) channels = prioritize_channels(spec.get('channels', [])) # Build reverse look-up from channel URL to channel name. channel_by_url = {url: channel for url, (channel, _) in channels.items()} index = fetch_index(channels, use_cache=False) resolver = Resolve(index) # Create the package distribution from the manifest. Ensure to replace # channel-URLs with channel names, otherwise the fetch-extract may fail. dists = [Dist.from_string(pkg, channel_override=channel_by_url.get(url, url)) for url, pkg in pkgs] # Use the resolver to sort packages into the appropriate dependency # order. sorted_dists = resolver.dependency_sort({dist.name: dist for dist in dists}) pfe = ProgressiveFetchExtract(index, sorted_dists) pfe.execute() mkdir_p(target) txn = UnlinkLinkTransaction.create_from_dists(index, target, (), sorted_dists) txn.execute()
def remove(args, parser): if not (args.all or args.package_names): raise CondaValueError("no package names supplied,\n" ' try "mamba remove -h" for more details') prefix = context.target_prefix check_non_admin() init_api_context() if args.all and prefix == context.default_prefix: raise CondaEnvironmentError("cannot remove current environment. \ deactivate and run mamba remove again") if args.all and path_is_clean(prefix): # full environment removal was requested, but environment doesn't exist anyway return 0 if args.all: if prefix == context.root_prefix: raise CondaEnvironmentError( "cannot remove root environment,\n" " add -n NAME or -p PREFIX option") print("\nRemove all packages in environment %s:\n" % prefix, file=sys.stderr) if "package_names" in args: stp = PrefixSetup( target_prefix=prefix, unlink_precs=tuple(PrefixData(prefix).iter_records()), link_precs=(), remove_specs=(), update_specs=(), neutered_specs=(), ) txn = UnlinkLinkTransaction(stp) try: handle_txn(txn, prefix, args, False, True) except PackagesNotFoundError: print( "No packages found in %s. Continuing environment removal" % prefix) rm_rf(prefix, clean_empty_parents=True) unregister_env(prefix) return else: if args.features: specs = tuple( MatchSpec(track_features=f) for f in set(args.package_names)) else: specs = [s for s in specs_from_args(args.package_names)] if not context.quiet: print("Removing specs: {}".format( [s.conda_build_form() for s in specs])) installed_json_f, installed_pkg_recs = get_installed_jsonfile(prefix) mamba_solve_specs = [s.conda_build_form() for s in specs] solver_options.append((api.SOLVER_FLAG_ALLOW_UNINSTALL, 1)) if context.channel_priority is ChannelPriority.STRICT: solver_options.append((api.SOLVER_FLAG_STRICT_REPO_PRIORITY, 1)) pool = api.Pool() repos = [] # add installed if use_mamba_experimental: prefix_data = api.PrefixData(context.target_prefix) prefix_data.load() repo = api.Repo(pool, prefix_data) repos.append(repo) else: repo = api.Repo(pool, "installed", installed_json_f.name, "") repo.set_installed() repos.append(repo) solver = api.Solver(pool, solver_options) history = api.History(context.target_prefix) history_map = history.get_requested_specs_map() solver.add_jobs( [ms.conda_build_form() for ms in history_map.values()], api.SOLVER_USERINSTALLED, ) solver.add_jobs(mamba_solve_specs, api.SOLVER_ERASE | api.SOLVER_CLEANDEPS) success = solver.solve() if not success: print(solver.problems_to_str()) exit_code = 1 return exit_code package_cache = api.MultiPackageCache(context.pkgs_dirs) transaction = api.Transaction( solver, package_cache, PackageCacheData.first_writable().pkgs_dir) downloaded = transaction.prompt(repos) if not downloaded: exit(0) mmb_specs, to_link, to_unlink = transaction.to_conda() transaction.log_json() specs_to_add = [MatchSpec(m) for m in mmb_specs[0]] specs_to_remove = [MatchSpec(m) for m in mmb_specs[1]] conda_transaction = to_txn( specs_to_add, specs_to_remove, prefix, to_link, to_unlink, installed_pkg_recs, ) handle_txn(conda_transaction, prefix, args, False, True)
def install(args, parser, command='install'): """ mamba install, mamba update, and mamba create """ context.validate_configuration() check_non_admin() newenv = bool(command == 'create') isupdate = bool(command == 'update') isinstall = bool(command == 'install') if newenv: ensure_name_or_prefix(args, command) prefix = context.target_prefix if newenv: check_prefix(prefix, json=context.json) if context.force_32bit and prefix == context.root_prefix: raise CondaValueError("cannot use CONDA_FORCE_32BIT=1 in base env") if isupdate and not (args.file or args.packages or context.update_modifier == UpdateModifier.UPDATE_ALL): raise CondaValueError("""no package names supplied # If you want to update to a newer version of Anaconda, type: # # $ conda update --prefix %s anaconda """ % prefix) if not newenv: if isdir(prefix): delete_trash(prefix) if not isfile(join(prefix, 'conda-meta', 'history')): if paths_equal(prefix, context.conda_prefix): raise NoBaseEnvironmentError() else: if not path_is_clean(prefix): raise DirectoryNotACondaEnvironmentError(prefix) else: # fall-through expected under normal operation pass else: if args.mkdir: try: mkdir_p(prefix) except EnvironmentError as e: raise CondaOSError("Could not create directory: %s" % prefix, caused_by=e) else: raise EnvironmentLocationNotFound(prefix) # context.__init__(argparse_args=args) prepend = not args.override_channels prefix = context.target_prefix index_args = { 'use_cache': args.use_index_cache, 'channel_urls': context.channels, 'unknown': args.unknown, 'prepend': not args.override_channels, 'use_local': args.use_local } args_packages = [s.strip('"\'') for s in args.packages] if newenv and not args.no_default_packages: # Override defaults if they are specified at the command line # TODO: rework in 4.4 branch using MatchSpec args_packages_names = [pkg.replace(' ', '=').split('=', 1)[0] for pkg in args_packages] for default_pkg in context.create_default_packages: default_pkg_name = default_pkg.replace(' ', '=').split('=', 1)[0] if default_pkg_name not in args_packages_names: args_packages.append(default_pkg) num_cp = sum(s.endswith('.tar.bz2') for s in args_packages) if num_cp: if num_cp == len(args_packages): explicit(args_packages, prefix, verbose=not context.quiet) return else: raise CondaValueError("cannot mix specifications with conda package" " filenames") index = get_index(channel_urls=index_args['channel_urls'], prepend=index_args['prepend'], platform=None, use_local=index_args['use_local'], use_cache=index_args['use_cache'], unknown=index_args['unknown'], prefix=prefix) channel_json = [] for x in index: # add priority here if x.channel.name in index_args['channel_urls']: priority = len(index_args['channel_urls']) - index_args['channel_urls'].index(x.channel.name) else: priority = 0 channel_json.append((str(x.channel), x.cache_path_json, priority)) installed_pkg_recs, output = get_installed_packages(prefix, show_channel_urls=True) installed_json_f = tempfile.NamedTemporaryFile('w', delete=False) installed_json_f.write(json_dump(output)) installed_json_f.flush() specs = [] if args.file: for fpath in args.file: try: specs.extend(specs_from_url(fpath, json=context.json)) except Unicode: raise CondaError("Error reading file, file should be a text file containing" " packages \nconda create --help for details") if '@EXPLICIT' in specs: explicit(specs, prefix, verbose=not context.quiet, index_args=index_args) return specs.extend(specs_from_args(args_packages, json=context.json)) if isinstall and args.revision: get_revision(args.revision, json=context.json) elif isinstall and not (args.file or args_packages): raise CondaValueError("too few arguments, " "must supply command line package specs or --file") # for 'conda update', make sure the requested specs actually exist in the prefix # and that they are name-only specs if isupdate and context.update_modifier == UpdateModifier.UPDATE_ALL: print("Currently, mamba can only update explicit packages! (e.g. mamba update numpy python ...)") exit() if isupdate and context.update_modifier != UpdateModifier.UPDATE_ALL: prefix_data = PrefixData(prefix) for spec in specs: spec = MatchSpec(spec) if not spec.is_name_only_spec: raise CondaError("Invalid spec for 'conda update': %s\n" "Use 'conda install' instead." % spec) if not prefix_data.get(spec.name, None): raise PackageNotInstalledError(prefix, spec.name) if newenv and args.clone: if args.packages: raise TooManyArgumentsError(0, len(args.packages), list(args.packages), 'did not expect any arguments for --clone') clone(args.clone, prefix, json=context.json, quiet=context.quiet, index_args=index_args) touch_nonadmin(prefix) print_activate(args.name if args.name else prefix) return specs = [MatchSpec(s) for s in specs] mamba_solve_specs = [s.conda_build_form() for s in specs] print("\n\nLooking for: {}\n\n".format(mamba_solve_specs)) strict_priority = (context.channel_priority == ChannelPriority.STRICT) if strict_priority: raise Exception("Cannot use strict priority with mamba!") to_link, to_unlink = api.solve(channel_json, installed_json_f.name, mamba_solve_specs, isupdate, strict_priority) to_link_records, to_unlink_records = [], [] final_precs = IndexedSet(PrefixData(prefix).iter_records()) def get_channel(c): for x in index: if str(x.channel) == c: return x for c, pkg in to_unlink: for i_rec in installed_pkg_recs: if i_rec.fn == pkg: final_precs.remove(i_rec) to_unlink_records.append(i_rec) break else: print("No package record found!") for c, pkg, jsn_s in to_link: sdir = get_channel(c) rec = to_package_record_from_subjson(sdir, pkg, jsn_s) final_precs.add(rec) to_link_records.append(rec) unlink_precs, link_precs = diff_for_unlink_link_precs(prefix, final_precs=IndexedSet(PrefixGraph(final_precs).graph), specs_to_add=specs, force_reinstall=context.force_reinstall) pref_setup = PrefixSetup( target_prefix = prefix, unlink_precs = unlink_precs, link_precs = link_precs, remove_specs = [], update_specs = specs ) conda_transaction = UnlinkLinkTransaction(pref_setup) handle_txn(conda_transaction, prefix, args, newenv) try: installed_json_f.close() os.unlink(installed_json_f.name) except: pass
def to_txn( specs_to_add, specs_to_remove, prefix, to_link, to_unlink, installed_pkg_recs, index=None, ): if index is None: index = [] to_link_records, to_unlink_records = [], [] prefix_data = PrefixData(prefix) final_precs = IndexedSet(prefix_data.iter_records()) lookup_dict = {} for _, entry in index: lookup_dict[entry["channel"].platform_url( entry["platform"], with_credentials=False)] = entry for _, pkg in to_unlink: for i_rec in installed_pkg_recs: if i_rec.fn == pkg: final_precs.remove(i_rec) to_unlink_records.append(i_rec) break else: print("No package record found!") for c, pkg, jsn_s in to_link: if c.startswith("file://"): # The conda functions (specifically remove_auth) assume the input # is a url; a file uri on windows with a drive letter messes them # up. key = c else: key = split_anaconda_token(remove_auth(c))[0] if key not in lookup_dict: raise ValueError("missing key {} in channels: {}".format( key, lookup_dict)) sdir = lookup_dict[key] rec = to_package_record_from_subjson(sdir, pkg, jsn_s) final_precs.add(rec) to_link_records.append(rec) unlink_precs, link_precs = diff_for_unlink_link_precs( prefix, final_precs=IndexedSet(PrefixGraph(final_precs).graph), specs_to_add=specs_to_add, force_reinstall=context.force_reinstall, ) pref_setup = PrefixSetup( target_prefix=prefix, unlink_precs=unlink_precs, link_precs=link_precs, remove_specs=specs_to_remove, update_specs=specs_to_add, neutered_specs=(), ) conda_transaction = UnlinkLinkTransaction(pref_setup) return conda_transaction
def remove(args, parser): if not (args.all or args.package_names): raise CondaValueError('no package names supplied,\n' ' try "mamba remove -h" for more details') prefix = context.target_prefix check_non_admin() init_api_context() if args.all and prefix == context.default_prefix: raise CondaEnvironmentError("cannot remove current environment. \ deactivate and run mamba remove again") if args.all and path_is_clean(prefix): # full environment removal was requested, but environment doesn't exist anyway return 0 if args.all: if prefix == context.root_prefix: raise CondaEnvironmentError( 'cannot remove root environment,\n' ' add -n NAME or -p PREFIX option') print("\nRemove all packages in environment %s:\n" % prefix, file=sys.stderr) if 'package_names' in args: stp = PrefixSetup( target_prefix=prefix, unlink_precs=tuple(PrefixData(prefix).iter_records()), link_precs=(), remove_specs=(), update_specs=(), neutered_specs=(), ) txn = UnlinkLinkTransaction(stp) try: handle_txn(txn, prefix, args, False, True) except PackagesNotFoundError: print( "No packages found in %s. Continuing environment removal" % prefix) rm_rf(prefix, clean_empty_parents=True) unregister_env(prefix) return else: if args.features: specs = tuple( MatchSpec(track_features=f) for f in set(args.package_names)) else: specs = [s for s in specs_from_args(args.package_names)] if not context.quiet: print("Removing specs: {}".format( [s.conda_build_form() for s in specs])) installed_json_f = get_installed_jsonfile(prefix) mamba_solve_specs = [s.conda_build_form() for s in specs] solver_options.append((api.SOLVER_FLAG_ALLOW_UNINSTALL, 1)) pool = api.Pool() repos = [] # add installed if use_mamba_experimental: prefix_data = api.PrefixData(context.target_prefix) prefix_data.load() repo = api.Repo(pool, prefix_data) repos.append(repo) else: repo = api.Repo(pool, "installed", installed_json_f.name, "") repo.set_installed() repos.append(repo) solver = api.Solver(pool, solver_options) solver.add_jobs(mamba_solve_specs, api.SOLVER_ERASE) success = solver.solve() if not success: print(solver.problems_to_str()) exit_code = 1 return exit_code transaction = api.Transaction(solver) to_link, to_unlink = transaction.to_conda() transaction.log_json() conda_transaction = to_txn((), specs, prefix, to_link, to_unlink) handle_txn(conda_transaction, prefix, args, False, True)
def mamba_install(prefix, specs, args, env, *_, **kwargs): # TODO: support all various ways this happens init_api_context() # Including 'nodefaults' in the channels list disables the defaults channel_urls = [chan for chan in env.channels if chan != 'nodefaults'] if 'nodefaults' not in env.channels: channel_urls.extend(context.channels) _channel_priority_map = prioritize_channels(channel_urls) index = get_index(tuple(_channel_priority_map.keys())) channel_json = [] for subdir, chan in index: # add priority here priority = len(_channel_priority_map) - _channel_priority_map[chan.url( with_credentials=True)][1] subpriority = 0 if chan.platform == 'noarch' else 1 if subdir.loaded() == False and chan.platform != 'noarch': # ignore non-loaded subdir if channel is != noarch continue channel_json.append((chan, subdir.cache_path(), priority, subpriority)) specs = [MatchSpec(s) for s in specs] mamba_solve_specs = [s.conda_build_form() for s in specs] print("\n\nLooking for: {}\n\n".format(mamba_solve_specs)) solver_options = [(api.SOLVER_FLAG_ALLOW_DOWNGRADE, 1)] pool = api.Pool() repos = [] for channel, cache_file, priority, subpriority in channel_json: repo = api.Repo(pool, str(channel), cache_file, channel.url(with_credentials=True)) repo.set_priority(priority, subpriority) repos.append(repo) solver = api.Solver(pool, solver_options) solver.add_jobs(mamba_solve_specs, api.SOLVER_INSTALL) success = solver.solve() if not success: print(solver.problems_to_str()) package_cache = api.MultiPackageCache(context.pkgs_dirs) transaction = api.Transaction(solver, package_cache) to_link, to_unlink = transaction.to_conda() to_link_records, to_unlink_records = [], [] final_precs = IndexedSet(PrefixData(prefix).iter_records()) def get_channel(c): for _, chan in index: if str(chan) == c: return chan for c, pkg, jsn_s in to_link: sdir = get_channel(c) rec = to_package_record_from_subjson(sdir, pkg, jsn_s) final_precs.add(rec) to_link_records.append(rec) unlink_precs, link_precs = diff_for_unlink_link_precs( prefix, final_precs=IndexedSet(PrefixGraph(final_precs).graph), specs_to_add=specs, force_reinstall=context.force_reinstall) pref_setup = PrefixSetup(target_prefix=prefix, unlink_precs=unlink_precs, link_precs=link_precs, remove_specs=[], update_specs=specs, neutered_specs=()) conda_transaction = UnlinkLinkTransaction(pref_setup) pfe = conda_transaction._get_pfe() pfe.execute() conda_transaction.execute()
def remove(args, parser): if not (args.all or args.package_names): raise CondaValueError('no package names supplied,\n' ' try "mamba remove -h" for more details') prefix = context.target_prefix check_non_admin() if args.all and prefix == context.default_prefix: raise CondaEnvironmentError("cannot remove current environment. \ deactivate and run mamba remove again") if args.all and path_is_clean(prefix): # full environment removal was requested, but environment doesn't exist anyway return 0 if args.all: if prefix == context.root_prefix: raise CondaEnvironmentError( 'cannot remove root environment,\n' ' add -n NAME or -p PREFIX option') print("\nRemove all packages in environment %s:\n" % prefix, file=sys.stderr) if 'package_names' in args: stp = PrefixSetup( target_prefix=prefix, unlink_precs=tuple(PrefixData(prefix).iter_records()), link_precs=(), remove_specs=(), update_specs=(), ) txn = UnlinkLinkTransaction(stp) handle_txn(txn, prefix, args, False, True) rm_rf(prefix, clean_empty_parents=True) unregister_env(prefix) return else: if args.features: specs = tuple( MatchSpec(track_features=f) for f in set(args.package_names)) else: specs = [s for s in specs_from_args(args.package_names)] if not context.quiet: print("Removing specs: {}".format(specs)) channel_urls = () subdirs = () installed_json_f = get_installed_jsonfile(prefix) mamba_solve_specs = [s.conda_build_form() for s in specs] solver_options.append((api.SOLVER_FLAG_ALLOW_UNINSTALL, 1)) to_link, to_unlink = api.solve([], installed_json_f.name, mamba_solve_specs, solver_options, api.SOLVER_ERASE, False, context.quiet) conda_transaction = to_txn(specs, prefix, to_link, to_unlink) handle_txn(conda_transaction, prefix, args, False, True)
def mamba_install(prefix, specs, args, env, *_, **kwargs): # TODO: support all various ways this happens # Including 'nodefaults' in the channels list disables the defaults channel_urls = [chan for chan in env.channels if chan != 'nodefaults'] if 'nodefaults' not in env.channels: channel_urls.extend(context.channels) _channel_priority_map = prioritize_channels(channel_urls) index = get_env_index(_channel_priority_map) channel_json = [] for x in index: # add priority here priority = len(_channel_priority_map) - _channel_priority_map[ x.url_w_subdir][1] subpriority = 0 if x.channel.platform == 'noarch' else 1 if os.path.exists(x.cache_path_solv): cache_file = x.cache_path_solv else: cache_file = x.cache_path_json channel_json.append( (str(x.channel), cache_file, priority, subpriority)) specs = [MatchSpec(s) for s in specs] mamba_solve_specs = [s.conda_build_form() for s in specs] print("\n\nLooking for: {}\n\n".format(mamba_solve_specs)) # TODO! installed_json_f = tempfile.NamedTemporaryFile('w', delete=False) installed_json_f.write("") # stupid! installed_json_f.flush() solver_options = [(api.SOLVER_FLAG_ALLOW_DOWNGRADE, 1)] to_link, to_unlink = api.solve(channel_json, installed_json_f.name, mamba_solve_specs, solver_options, api.SOLVER_INSTALL, False, context.quiet) to_link_records, to_unlink_records = [], [] final_precs = IndexedSet(PrefixData(prefix).iter_records()) def get_channel(c): for x in index: if str(x.channel) == c: return x for c, pkg in to_unlink: for i_rec in installed_pkg_recs: if i_rec.fn == pkg: final_precs.remove(i_rec) to_unlink_records.append(i_rec) break else: print("No package record found!") for c, pkg, jsn_s in to_link: sdir = get_channel(c) rec = to_package_record_from_subjson(sdir, pkg, jsn_s) final_precs.add(rec) to_link_records.append(rec) unlink_precs, link_precs = diff_for_unlink_link_precs( prefix, final_precs=IndexedSet(PrefixGraph(final_precs).graph), specs_to_add=specs, force_reinstall=context.force_reinstall) pref_setup = PrefixSetup(target_prefix=prefix, unlink_precs=unlink_precs, link_precs=link_precs, remove_specs=[], update_specs=specs) conda_transaction = UnlinkLinkTransaction(pref_setup) pfe = conda_transaction._get_pfe() pfe.execute() conda_transaction.execute() try: installed_json_f.close() os.unlink(installed_json_f.name) except: pass
def bypass_satsolver_on_install( pkg_names, conda_channel="ggd-genomics", debug=False, prefix=None ): """Method to bypass the sat solver used by conda when a cached recipe is being installed bypass_satsolver_on_install ============================ This method is used to run the conda install steps to install a ggd aws cahced reicpe. The intsallation will skip the sat solver step, ignore packages that may be additionaly installed or uninstalled, and performs other steps in order to install the data package without using the sat solver. The majority of the work is still done by conda through the use of the conda module. This method should only be used when a cached recipe is being installed. Parameters: ----------- #1) pkg_name: The name of the ggd package to install. (Example: hg19-gaps) 1) pkg_names: A list of the names of the ggd packages to install. (Example: [hg19-gaps]) 2) conda_channel: The ggd conda channel that package is being installed from. (Example: ggd-genomics) """ # ------------------------------------------------------------------------- # import statments # ------------------------------------------------------------------------- from conda.base.context import context from conda.cli import common from conda.cli import install from conda.core.solve import Solver from conda.core.solve import SolverStateContainer from conda.common.io import Spinner from conda.core.link import PrefixSetup from conda.core.link import UnlinkLinkTransaction from argparse import Namespace from conda._vendor.boltons.setutils import IndexedSet from conda.models.prefix_graph import PrefixGraph from conda.core.solve import diff_for_unlink_link_precs from conda.common.compat import iteritems, itervalues, odict, text_type from conda._vendor.toolz import concat, concatv from conda.resolve import Resolve from conda.models.match_spec import MatchSpec from conda.base.constants import UpdateModifier from conda.common.io import ProgressBar from conda.gateways.logging import set_all_logger_level, set_conda_log_level from conda.gateways.logging import VERBOSITY_LEVELS from conda.gateways.logging import log from logging import ( DEBUG, ERROR, Filter, Formatter, INFO, StreamHandler, WARN, getLogger, ) import sys print( "\n:ggd:utils:bypass: Installing %s from the %s conda channel\n" % (", ".join(pkg_names), conda_channel) ) # ------------------------------------------------------------------------- # Nested functions # ------------------------------------------------------------------------- # def bypass_sat(package_name,ssc_object): ## Package_name will be used as a key def bypass_sat(package_names, ssc_object): ## Package_name will be used as a key """Method used to extract information during sat solving, but to bypass the sat solving step bypass_sat ========== This method is used to extract and process information that would have been done during the sat solvering step, (Solving Enviroment), bypass the sat solver, and return a filtered set of packages to install. Parameters: ----------- #1) package_name: The name of the package to extract. (This is the package that will be installed) 1) package_names: A list of package names of the packages to extract. (This is the package that will be installed) 2) ssc_object: A processed conda SolverStateContainer object. Returns: +++++++ 1) The updated ssc object based off the sat bypass and package filtering. """ ## From Solver.run_sat specs_map_set = set(itervalues(ssc_object.specs_map)) ## Get the specs from ssc filtered by the package name new_odict = odict( [(p_name, ssc_object.specs_map[p_name]) for p_name in package_names] ) final_environment_specs = IndexedSet( concatv( itervalues(new_odict), ssc_object.track_features_specs, ssc_object.pinned_specs, ) ) ## Run the resolve process and get info for desired package ssc_object.solution_precs = ssc_object.r.solve(tuple(final_environment_specs)) wanted_indices = [] for i, info in enumerate(ssc_object.solution_precs): for p_name in package_names: if p_name in ssc_object.solution_precs[i].namekey: wanted_indices.append(i) filtered_ssc_solution_precs = [ ssc_object.solution_precs[x] for x in wanted_indices ] ssc_object.solution_precs = filtered_ssc_solution_precs ## Add the final environment specs to ssc ssc_object.final_environment_specs = final_environment_specs return ssc_object # ------------------------------------------------------------------------- # Run install # ------------------------------------------------------------------------- ## Set the context.always_yes to True to bypass user input context.always_yes = True target_prefix = context.target_prefix if prefix == None else prefix # Setup solver object # solve = Solver(target_prefix, (conda_channel,u'default'), context.subdirs, [pkg_name]) solve = Solver( target_prefix, (conda_channel, u"default"), context.subdirs, pkg_names ) ## Create a solver state container ### Make sure to Freeze those packages already installed in the current env in order to bypass update checking. ssc = SolverStateContainer( prefix=target_prefix, update_modifier=UpdateModifier.FREEZE_INSTALLED, deps_modifier=context.deps_modifier, prune=True, ignore_pinned=context.ignore_pinned, force_remove=context.force_remove, should_retry_solve=False, ) ## Get channel metadata with Spinner( "Collecting package metadata", not context.verbosity and not context.quiet, context.json, ): ssc = solve._collect_all_metadata(ssc) ## Set specs map to an empty map. (No need to check other specs) add_spec = [] for p_name, spec in iteritems(ssc.specs_map): for pkg_name in pkg_names: if str(p_name) in pkg_name: add_spec.append((pkg_name, MatchSpec(pkg_name))) ssc.specs_map = odict(add_spec) ## Process the data in the solver state container with Spinner( "Processing data", not context.verbosity and not context.quiet, context.json ): ssc = solve._add_specs(ssc) ssc = bypass_sat(pkg_names, ssc) ssc = solve._post_sat_handling(ssc) ## create an IndexedSet from ssc.solution_precs ssc.solution_precs = IndexedSet(PrefixGraph(ssc.solution_precs).graph) ## Get linked and unlinked unlink_precs, link_precs = diff_for_unlink_link_precs( target_prefix, ssc.solution_precs, solve.specs_to_add ) # set unlinked to empty indexed set so we do not unlink/remove any pacakges unlink_precs = IndexedSet() ## Create a PrefixSetup stp = PrefixSetup( solve.prefix, unlink_precs, link_precs, solve.specs_to_remove, solve.specs_to_add, solve.neutered_specs, ) ## Create an UnlinkLinkTransaction with stp unlink_link_transaction = UnlinkLinkTransaction(stp) # create Namespace args = Namespace( channel=None, cmd="install", deps_modifier=context.deps_modifier, json=False, packages=pkg_names, ) ## Set logger level if debug: WARN, INFO, DEBUG, TRACE = VERBOSITY_LEVELS set_all_logger_level(DEBUG) ## Install package install.handle_txn(unlink_link_transaction, solve.prefix, args, False) ## Retrun True if finished return True