Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maint: Move solver::libsolv::UnSolvable to solver::UnSolvable #3385

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ set(
# Solver generic interface
${LIBMAMBA_SOURCE_DIR}/solver/helpers.cpp
${LIBMAMBA_SOURCE_DIR}/solver/problems_graph.cpp
${LIBMAMBA_SOURCE_DIR}/solver/unsolvable.cpp
# Solver libsolv implementation
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/database.cpp
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/helpers.cpp
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/matcher.cpp
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/parameters.cpp
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/repo_info.cpp
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/solver.cpp
${LIBMAMBA_SOURCE_DIR}/solver/libsolv/unsolvable.cpp
# Artifacts validation
${LIBMAMBA_SOURCE_DIR}/validation/tools.cpp
${LIBMAMBA_SOURCE_DIR}/validation/errors.cpp
Expand Down Expand Up @@ -325,12 +325,12 @@ set(
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/problems_graph.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/request.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/solution.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/unsolvable.hpp
# Solver libsolv implementation
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/libsolv/database.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/libsolv/parameters.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/libsolv/repo_info.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/libsolv/solver.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/solver/libsolv/unsolvable.hpp
# Artifacts validation
${LIBMAMBA_INCLUDE_DIR}/mamba/validation/tools.hpp
${LIBMAMBA_INCLUDE_DIR}/mamba/validation/errors.hpp
Expand Down
8 changes: 6 additions & 2 deletions libmamba/include/mamba/solver/libsolv/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ namespace mamba
}
}

namespace mamba::solver
{
class UnSolvable;
}

namespace mamba::solver::libsolv
{
class Solver;
class UnSolvable;

/**
* Database of solvable involved in resolving en environment.
Expand Down Expand Up @@ -139,7 +143,7 @@ namespace mamba::solver::libsolv
[[nodiscard]] static auto get(const Database& pool) -> const solv::ObjPool&;

friend class Solver;
friend class UnSolvable;
friend class solver::UnSolvable;
};

private:
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/solver/libsolv/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#define MAMBA_SOLVER_LIBSOLV_SOLVER_HPP

#include "mamba/core/error_handling.hpp"
#include "mamba/solver/libsolv/unsolvable.hpp"
#include "mamba/solver/request.hpp"
#include "mamba/solver/solution.hpp"
#include "mamba/solver/unsolvable.hpp"

namespace mamba::solver::libsolv
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ namespace mamba
class Palette;
}

namespace mamba::solver::libsolv
namespace mamba::solver
{
class Solver;
class Database;
namespace libsolv
{
class Solver;
class Database;
}

class UnSolvable
{
Expand All @@ -39,22 +42,23 @@ namespace mamba::solver::libsolv

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

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

[[nodiscard]] auto problems_to_str(Database& pool) const -> std::string;
[[nodiscard]] auto problems_to_str(libsolv::Database& pool) const -> std::string;

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

[[nodiscard]] auto problems_graph(const Database& pool) const -> ProblemsGraph;
[[nodiscard]] auto problems_graph(const libsolv::Database& pool) const -> ProblemsGraph;

auto explain_problems_to( //
Database& pool,
libsolv::Database& pool,
std::ostream& out,
const ProblemsMessageFormat& format
) const -> std::ostream&;

[[nodiscard]] auto
explain_problems(Database& pool, const ProblemsMessageFormat& format) const -> std::string;
explain_problems(libsolv::Database& pool, const ProblemsMessageFormat& format) const
-> std::string;

private:

Expand All @@ -67,7 +71,7 @@ namespace mamba::solver::libsolv

[[nodiscard]] auto solver() const -> const solv::ObjSolver&;

friend class Solver;
friend class libsolv::Solver;
};
}
#endif
2 changes: 1 addition & 1 deletion libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ namespace mamba

auto outcome = solver::libsolv::Solver().solve(db, request).value();

if (auto* unsolvable = std::get_if<solver::libsolv::UnSolvable>(&outcome))
if (auto* unsolvable = std::get_if<solver::UnSolvable>(&outcome))
{
unsolvable->explain_problems_to(
db,
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace mamba
};

auto outcome = solver::libsolv::Solver().solve(pool, request).value();
if (auto* unsolvable = std::get_if<solver::libsolv::UnSolvable>(&outcome))
if (auto* unsolvable = std::get_if<solver::UnSolvable>(&outcome))
{
if (ctx.output_params.json)
{
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace mamba
}

auto outcome = solver::libsolv::Solver().solve(db, request).value();
if (auto* unsolvable = std::get_if<solver::libsolv::UnSolvable>(&outcome))
if (auto* unsolvable = std::get_if<solver::UnSolvable>(&outcome))
{
if (ctx.output_params.json)
{
Expand Down
5 changes: 5 additions & 0 deletions libmamba/src/solver/libsolv/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

#include "solver/libsolv/helpers.hpp"

namespace mamba::solver
{
class UnSolvable;
}

namespace mamba::solver::libsolv
{
namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#include "mamba/core/output.hpp"
#include "mamba/core/palette.hpp"
#include "mamba/solver/libsolv/database.hpp"
#include "mamba/solver/libsolv/unsolvable.hpp"
#include "mamba/solver/unsolvable.hpp"
#include "mamba/specs/match_spec.hpp"
#include "mamba/specs/package_info.hpp"
#include "solv-cpp/pool.hpp"
#include "solv-cpp/solver.hpp"

#include "solver/libsolv/helpers.hpp"

namespace mamba::solver::libsolv
namespace mamba::solver
{
UnSolvable::UnSolvable(std::unique_ptr<solv::ObjSolver>&& solver)
: m_solver(std::move(solver))
Expand All @@ -42,19 +42,19 @@ namespace mamba::solver::libsolv
return *m_solver;
}

auto UnSolvable::problems(Database& db) const -> std::vector<std::string>
auto UnSolvable::problems(libsolv::Database& db) const -> std::vector<std::string>
{
auto& pool = Database::Impl::get(db);
auto& pool = solver::libsolv::Database::Impl::get(db);
std::vector<std::string> problems;
solver().for_each_problem_id([&](solv::ProblemId pb)
{ problems.emplace_back(solver().problem_to_string(pool, pb)); }
);
return problems;
}

auto UnSolvable::problems_to_str(Database& db) const -> std::string
auto UnSolvable::problems_to_str(libsolv::Database& db) const -> std::string
{
auto& pool = Database::Impl::get(db);
auto& pool = solver::libsolv::Database::Impl::get(db);
std::stringstream problems;
problems << "Encountered problems while solving:\n";
solver().for_each_problem_id(
Expand All @@ -64,9 +64,9 @@ namespace mamba::solver::libsolv
return problems.str();
}

auto UnSolvable::all_problems_to_str(Database& db) const -> std::string
auto UnSolvable::all_problems_to_str(libsolv::Database& db) const -> std::string
{
auto& pool = Database::Impl::get(db);
auto& pool = libsolv::Database::Impl::get(db);
std::stringstream problems;
solver().for_each_problem_id(
[&](solv::ProblemId pb)
Expand Down Expand Up @@ -323,7 +323,7 @@ namespace mamba::solver::libsolv
{
if (solv_pin.type() == solv::SolvableType::Pin)
{
auto pin = make_package_info(pool, solv_pin);
auto pin = libsolv::make_package_info(pool, solv_pin);
// There should really just be one constraint
ms.set_name(specs::MatchSpec::NameSpec(
fmt::format("pin on {}", fmt::join(pin.constrains, " and "))
Expand Down Expand Up @@ -543,14 +543,14 @@ namespace mamba::solver::libsolv
}
}

auto UnSolvable::problems_graph(const Database& pool) const -> ProblemsGraph
auto UnSolvable::problems_graph(const libsolv::Database& pool) const -> ProblemsGraph
{
assert(m_solver != nullptr);
return ProblemsGraphCreator(Database::Impl::get(pool), *m_solver).problem_graph();
return ProblemsGraphCreator(libsolv::Database::Impl::get(pool), *m_solver).problem_graph();
}

auto UnSolvable::explain_problems_to(
Database& pool,
libsolv::Database& pool,
std::ostream& out,
const ProblemsMessageFormat& format
) const -> std::ostream&
Expand All @@ -564,7 +564,8 @@ namespace mamba::solver::libsolv
}

auto
UnSolvable::explain_problems(Database& pool, const ProblemsMessageFormat& format) const -> std::string
UnSolvable::explain_problems(libsolv::Database& pool, const ProblemsMessageFormat& format) const
-> std::string

{
std::stringstream ss;
Expand Down
12 changes: 6 additions & 6 deletions libmamba/tests/src/solver/libsolv/test_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST_SUITE("solver::libsolv::solver")
const auto outcome = libsolv::Solver().solve(db, request);

REQUIRE(outcome.has_value());
REQUIRE(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
REQUIRE(std::holds_alternative<UnSolvable>(outcome.value()));
}


Expand All @@ -207,7 +207,7 @@ TEST_SUITE("solver::libsolv::solver")
const auto outcome = libsolv::Solver().solve(db, request);

REQUIRE(outcome.has_value());
REQUIRE(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
REQUIRE(std::holds_alternative<UnSolvable>(outcome.value()));
}
}

Expand Down Expand Up @@ -652,7 +652,7 @@ TEST_SUITE("solver::libsolv::solver")
const auto outcome = libsolv::Solver().solve(db, request);

REQUIRE(outcome.has_value());
CHECK(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
CHECK(std::holds_alternative<UnSolvable>(outcome.value()));
}
}

Expand Down Expand Up @@ -847,7 +847,7 @@ TEST_SUITE("solver::libsolv::solver")
const auto outcome = libsolv::Solver().solve(db, request);

REQUIRE(outcome.has_value());
CHECK(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
CHECK(std::holds_alternative<UnSolvable>(outcome.value()));
}

SUBCASE("https://conda.anaconda.org/mamba-forge::foo")
Expand Down Expand Up @@ -899,7 +899,7 @@ TEST_SUITE("solver::libsolv::solver")
const auto outcome = libsolv::Solver().solve(db, request);

REQUIRE(outcome.has_value());
REQUIRE(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
REQUIRE(std::holds_alternative<UnSolvable>(outcome.value()));
}

SUBCASE("conda-forge::numpy[subdir=linux-64]")
Expand Down Expand Up @@ -1040,7 +1040,7 @@ TEST_SUITE("solver::libsolv::solver")
const auto outcome = libsolv::Solver().solve(db, request);

REQUIRE(outcome.has_value());
REQUIRE(std::holds_alternative<libsolv::UnSolvable>(outcome.value()));
REQUIRE(std::holds_alternative<UnSolvable>(outcome.value()));
}

SUBCASE("foo[build_string=bld]")
Expand Down
4 changes: 2 additions & 2 deletions libmamba/tests/src/solver/test_problems_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "mamba/solver/libsolv/database.hpp"
#include "mamba/solver/libsolv/repo_info.hpp"
#include "mamba/solver/libsolv/solver.hpp"
#include "mamba/solver/libsolv/unsolvable.hpp"
#include "mamba/solver/problems_graph.hpp"
#include "mamba/solver/unsolvable.hpp"
#include "mamba/specs/package_info.hpp"
#include "mamba/util/string.hpp"

Expand Down Expand Up @@ -627,7 +627,7 @@ TEST_CASE("Create problem graph")
auto [db, request] = factory(ctx, channel_context);
auto outcome = solver::libsolv::Solver().solve(db, request).value();
// REQUIRE(std::holds_alternative<solver::libsolv::UnSolvable>(outcome));
auto& unsolvable = std::get<solver::libsolv::UnSolvable>(outcome);
auto& unsolvable = std::get<solver::UnSolvable>(outcome);
const auto pbs_init = unsolvable.problems_graph(db);
const auto& graph_init = pbs_init.graph();

Expand Down
14 changes: 14 additions & 0 deletions libmambapy/src/libmambapy/bindings/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>

#include "mamba/solver/libsolv/database.hpp"
#include "mamba/solver/problems_graph.hpp"
#include "mamba/solver/request.hpp"
#include "mamba/solver/solution.hpp"
#include "mamba/solver/unsolvable.hpp"

#include "bind_utils.hpp"
#include "bindings.hpp"
Expand Down Expand Up @@ -41,6 +43,18 @@ namespace mambapy

auto py_request = py::class_<Request>(m, "Request");

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

py::class_<Request::Install>(py_request, "Install")
.def(
py::init(
Expand Down
14 changes: 1 addition & 13 deletions libmambapy/src/libmambapy/bindings/solver_libsolv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#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 "mamba/solver/unsolvable.hpp"

#include "bind_utils.hpp"
#include "bindings.hpp"
Expand Down Expand Up @@ -213,18 +213,6 @@ namespace mambapy
py::arg("spec")
);

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

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
Loading
Loading