def solve(self, specs): """Solve given a set of specs. Parameters ---------- specs : list of str A list of package specs. You can use `conda.models.match_spec.MatchSpec` to get them to the right form by calling `MatchSpec(mypec).conda_build_form()` Returns ------- solvable : bool True if the set of specs has a solution, False otherwise. """ solver_options = [(api.SOLVER_FLAG_ALLOW_DOWNGRADE, 1)] solver = api.Solver(self.pool, solver_options) _specs = [_norm_spec(s) for s in specs] solver.add_jobs(_specs, api.SOLVER_INSTALL) success = solver.solve() if not success: logger.warning( "MAMBA failed to solve specs \n\n%s\n\nfor channels " "\n\n%s\n\nThe reported errors are:\n\n%s", pprint.pformat(_specs), pprint.pformat(self.channels), solver.problems_to_str(), ) return success
def solve( self, specs, get_run_exports=False, ignore_run_exports_from=None, ignore_run_exports=None, ) -> Tuple[bool, List[str]]: """Solve given a set of specs. Parameters ---------- specs : list of str A list of package specs. You can use `conda.models.match_spec.MatchSpec` to get them to the right form by calling `MatchSpec(mypec).conda_build_form()` get_run_exports : bool, optional If True, return run exports else do not. ignore_run_exports_from : list, optional A list of packages from which to ignore the run exports. ignore_run_exports : list, optional A list of things that should be ignore in the run exports. Returns ------- solvable : bool True if the set of specs has a solution, False otherwise. err : str The errors as a string. If no errors, is None. solution : list of str A list of concrete package specs for the env. run_exports : dict of list of str A dictionary with the weak and strong run exports for the packages. Only returned if get_run_exports is True. """ ignore_run_exports_from = ignore_run_exports_from or [] ignore_run_exports = ignore_run_exports or [] solver_options = [(api.SOLVER_FLAG_ALLOW_DOWNGRADE, 1)] solver = api.Solver(self.pool, solver_options) _specs = [_norm_spec(s) for s in specs] logger.debug("MAMBA running solver for specs \n\n%s\n", pprint.pformat(_specs)) solver.add_jobs(_specs, api.SOLVER_INSTALL) success = solver.solve() err = None if not success: logger.warning( "MAMBA failed to solve specs \n\n%s\n\nfor channels " "\n\n%s\n\nThe reported errors are:\n\n%s\n", pprint.pformat(_specs), pprint.pformat(self.channels), solver.problems_to_str(), ) err = solver.problems_to_str() solution = None run_exports = copy.deepcopy(DEFAULT_RUN_EXPORTS) else: t = api.Transaction( solver, PACKAGE_CACHE, self.repos, ) solution = [] _, to_link, _ = t.to_conda() for _, _, jdata in to_link: data = json.loads(jdata) solution.append( " ".join([data["name"], data["version"], data["build"]]), ) if get_run_exports: logger.debug( "MAMBA getting run exports for \n\n%s\n", pprint.pformat(solution), ) run_exports = self._get_run_exports( to_link, _specs, ignore_run_exports_from, ignore_run_exports, ) if get_run_exports: return success, err, solution, run_exports else: return success, err, solution