Skip to content

Commit

Permalink
Bind solver::libsolv::UnSolvable
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Jan 31, 2024
1 parent d4c9f96 commit 496e0a9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
3 changes: 2 additions & 1 deletion libmamba/include/mamba/solver/libsolv/unsolvable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ namespace mamba::solver::libsolv

auto operator=(UnSolvable&&) -> UnSolvable&;

[[nodiscard]] auto problems(MPool& pool) const -> std::vector<std::string>;

[[nodiscard]] auto problems_to_str(MPool& pool) const -> std::string;
[[nodiscard]] auto all_problems(MPool& pool) const -> std::vector<std::string>;

[[nodiscard]] auto all_problems_to_str(MPool& pool) const -> std::string;

Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ namespace mamba
if (ctx.output_params.json)
{
Console::instance().json_write(
{ { "success", false }, { "solver_problems", unsolvable->all_problems(pool) } }
{ { "success", false }, { "solver_problems", unsolvable->problems(pool) } }
);
}
throw mamba_error(
Expand Down
6 changes: 3 additions & 3 deletions libmamba/src/api/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ namespace mamba
{
if (ctx.output_params.json)
{
Console::instance().json_write({ { "success", false },
{ "solver_problems",
unsolvable->all_problems(pool) } });
Console::instance().json_write(
{ { "success", false }, { "solver_problems", unsolvable->problems(pool) } }
);
}
throw mamba_error(
"Could not solve for environment specs",
Expand Down
5 changes: 2 additions & 3 deletions libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ namespace mamba
{
if (ctx.output_params.json)
{
Console::instance().json_write(
{ { "success", false }, { "solver_problems", unsolvable->all_problems(pool) } }
);
Console::instance().json_write({ { "success", false },
{ "solver_problems", unsolvable->problems(pool) } });
}
throw mamba_error(
"Could not solve for environment specs",
Expand Down
28 changes: 14 additions & 14 deletions libmamba/src/solver/libsolv/unsolvable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,14 @@ namespace mamba::solver::libsolv
return *m_solver;
}

auto UnSolvable::all_problems_to_str(MPool& pool) const -> std::string
auto UnSolvable::problems(MPool& pool) const -> std::vector<std::string>
{
std::stringstream problems;
std::vector<std::string> problems;
solver().for_each_problem_id(
[&](solv::ProblemId pb)
{
for (solv::RuleId const rule : solver().problem_rules(pb))
{
auto const info = solver().get_rule_info(pool.pool(), rule);
problems << " - " << solver().rule_info_to_string(pool.pool(), info) << "\n";
}
}
{ problems.emplace_back(solver().problem_to_string(pool.pool(), pb)); }
);
return problems.str();
return problems;
}

auto UnSolvable::problems_to_str(MPool& pool) const -> std::string
Expand All @@ -65,14 +59,20 @@ namespace mamba::solver::libsolv
return problems.str();
}

auto UnSolvable::all_problems(MPool& pool) const -> std::vector<std::string>
auto UnSolvable::all_problems_to_str(MPool& pool) const -> std::string
{
std::vector<std::string> problems;
std::stringstream problems;
solver().for_each_problem_id(
[&](solv::ProblemId pb)
{ problems.emplace_back(solver().problem_to_string(pool.pool(), pb)); }
{
for (solv::RuleId const rule : solver().problem_rules(pb))
{
auto const info = solver().get_rule_info(pool.pool(), rule);
problems << " - " << solver().rule_info_to_string(pool.pool(), info) << "\n";
}
}
);
return problems;
return problems.str();
}

namespace
Expand Down
9 changes: 9 additions & 0 deletions libmambapy/src/libmambapy/bindings/solver_libsolv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "mamba/solver/libsolv/parameters.hpp"
#include "mamba/solver/libsolv/repo_info.hpp"
#include "mamba/solver/libsolv/solver.hpp"
#include "mamba/solver/libsolv/unsolvable.hpp"

#include "bindings.hpp"
#include "expected_caster.hpp"
#include "utils.hpp"

namespace mambapy
Expand Down Expand Up @@ -89,6 +91,13 @@ namespace mambapy
.def("__copy__", &copy<RepoInfo>)
.def("__deepcopy__", &deepcopy<RepoInfo>, py::arg("memo"));

py::class_<UnSolvable>(m, "UnSolvable")
.def("problems", &UnSolvable::problems)
.def("problems_to_str", &UnSolvable::problems_to_str)
.def("all_problems_to_str", &UnSolvable::all_problems_to_str)
.def("problems_graph", &UnSolvable::problems_graph)
.def("explain_problems", &UnSolvable::explain_problems);

constexpr auto solver_flags_v2_migrator = [](Solver&, py::args, py::kwargs) {
throw std::runtime_error("All flags need to be passed in the libmambapy.solver.Request.");
};
Expand Down

0 comments on commit 496e0a9

Please sign in to comment.