From dfe1fc4d07f4804b33efdf9e89c5a5915a755ffb Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 1 Aug 2024 12:01:24 +0200 Subject: [PATCH 1/3] maint: Move solver::libsolv::repo_info to solver::repo_info Signed-off-by: Julien Jerphanion --- libmamba/CMakeLists.txt | 4 ++-- .../include/mamba/core/package_database_loader.hpp | 6 +++--- libmamba/include/mamba/solver/libsolv/database.hpp | 2 +- .../include/mamba/solver/{libsolv => }/repo_info.hpp | 11 +++++++---- libmamba/src/api/channel_loader.cpp | 6 +++--- libmamba/src/api/remove.cpp | 2 +- libmamba/src/api/repoquery.cpp | 2 +- libmamba/src/core/package_database_loader.cpp | 8 ++++---- libmamba/src/solver/libsolv/database.cpp | 2 +- libmamba/src/solver/{libsolv => }/repo_info.cpp | 8 ++++---- libmamba/tests/src/solver/test_problems_graph.cpp | 2 +- libmambapy/src/libmambapy/bindings/solver_libsolv.cpp | 2 +- 12 files changed, 29 insertions(+), 26 deletions(-) rename libmamba/include/mamba/solver/{libsolv => }/repo_info.hpp (89%) rename libmamba/src/solver/{libsolv => }/repo_info.cpp (88%) diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index 16716339ce..8b54d8cfbe 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -183,12 +183,12 @@ set( # Solver generic interface ${LIBMAMBA_SOURCE_DIR}/solver/helpers.cpp ${LIBMAMBA_SOURCE_DIR}/solver/problems_graph.cpp + ${LIBMAMBA_SOURCE_DIR}/solver/repo_info.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 @@ -325,12 +325,12 @@ set( ${LIBMAMBA_INCLUDE_DIR}/mamba/specs/version_spec.hpp # Solver generic interface ${LIBMAMBA_INCLUDE_DIR}/mamba/solver/problems_graph.hpp + ${LIBMAMBA_INCLUDE_DIR}/mamba/solver/repo_info.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/solver/request.hpp ${LIBMAMBA_INCLUDE_DIR}/mamba/solver/solution.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 diff --git a/libmamba/include/mamba/core/package_database_loader.hpp b/libmamba/include/mamba/core/package_database_loader.hpp index b4a4eb6927..64f2d1ec89 100644 --- a/libmamba/include/mamba/core/package_database_loader.hpp +++ b/libmamba/include/mamba/core/package_database_loader.hpp @@ -8,7 +8,7 @@ #define MAMBA_CORE_PACKAGE_DATABASE_LOADER_HPP #include "mamba/core/error_handling.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/specs/channel.hpp" namespace mamba @@ -28,12 +28,12 @@ namespace mamba const Context& ctx, solver::libsolv::Database& db, const SubdirData& subdir - ) -> expected_t; + ) -> expected_t; auto load_installed_packages_in_database( const Context& ctx, solver::libsolv::Database& db, const PrefixData& prefix - ) -> solver::libsolv::RepoInfo; + ) -> solver::RepoInfo; } #endif diff --git a/libmamba/include/mamba/solver/libsolv/database.hpp b/libmamba/include/mamba/solver/libsolv/database.hpp index 7dc4a0ecc0..81287e6c1f 100644 --- a/libmamba/include/mamba/solver/libsolv/database.hpp +++ b/libmamba/include/mamba/solver/libsolv/database.hpp @@ -14,7 +14,7 @@ #include "mamba/core/error_handling.hpp" #include "mamba/solver/libsolv/parameters.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/specs/channel.hpp" #include "mamba/specs/package_info.hpp" #include "mamba/util/loop_control.hpp" diff --git a/libmamba/include/mamba/solver/libsolv/repo_info.hpp b/libmamba/include/mamba/solver/repo_info.hpp similarity index 89% rename from libmamba/include/mamba/solver/libsolv/repo_info.hpp rename to libmamba/include/mamba/solver/repo_info.hpp index e0c0d313a3..0a18dae94f 100644 --- a/libmamba/include/mamba/solver/libsolv/repo_info.hpp +++ b/libmamba/include/mamba/solver/repo_info.hpp @@ -17,9 +17,12 @@ extern "C" using Repo = struct s_Repo; } -namespace mamba::solver::libsolv +namespace mamba::solver { - class Database; + namespace libsolv + { + class Database; + } /** * A libsolv repository descriptor. @@ -50,7 +53,7 @@ namespace mamba::solver::libsolv [[nodiscard]] auto package_count() const -> std::size_t; - [[nodiscard]] auto priority() const -> Priorities; + [[nodiscard]] auto priority() const -> libsolv::Priorities; private: @@ -58,7 +61,7 @@ namespace mamba::solver::libsolv explicit RepoInfo(::Repo* repo); - friend class Database; + friend class mamba::solver::libsolv::Database; friend auto operator==(RepoInfo lhs, RepoInfo rhs) -> bool; }; diff --git a/libmamba/src/api/channel_loader.cpp b/libmamba/src/api/channel_loader.cpp index b80c89450b..c982b29173 100644 --- a/libmamba/src/api/channel_loader.cpp +++ b/libmamba/src/api/channel_loader.cpp @@ -12,7 +12,7 @@ #include "mamba/core/prefix_data.hpp" #include "mamba/core/subdirdata.hpp" #include "mamba/solver/libsolv/database.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/specs/package_info.hpp" namespace mamba @@ -24,7 +24,7 @@ namespace mamba ChannelContext& channel_context, solver::libsolv::Database& pool, const fs::u8path& pkgs_dir - ) -> solver::libsolv::RepoInfo + ) -> solver::RepoInfo { if (!fs::exists(pkgs_dir)) { @@ -245,7 +245,7 @@ namespace mamba } load_subdir_in_database(ctx, pool, subdir) - .transform([&](solver::libsolv::RepoInfo&& repo) + .transform([&](solver::RepoInfo&& repo) { pool.set_repo_priority(repo, priorities[i]); }) .or_else( [&](const auto&) diff --git a/libmamba/src/api/remove.cpp b/libmamba/src/api/remove.cpp index 4e831af3b8..0520eb6735 100644 --- a/libmamba/src/api/remove.cpp +++ b/libmamba/src/api/remove.cpp @@ -12,8 +12,8 @@ #include "mamba/core/package_database_loader.hpp" #include "mamba/core/prefix_data.hpp" #include "mamba/core/transaction.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" #include "mamba/solver/libsolv/solver.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/solver/request.hpp" namespace mamba diff --git a/libmamba/src/api/repoquery.cpp b/libmamba/src/api/repoquery.cpp index e1a4b0a7e1..3197a15739 100644 --- a/libmamba/src/api/repoquery.cpp +++ b/libmamba/src/api/repoquery.cpp @@ -14,7 +14,7 @@ #include "mamba/core/package_database_loader.hpp" #include "mamba/core/prefix_data.hpp" #include "mamba/solver/libsolv/database.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/util/string.hpp" namespace mamba diff --git a/libmamba/src/core/package_database_loader.cpp b/libmamba/src/core/package_database_loader.cpp index 221c81f39b..59b7b3f435 100644 --- a/libmamba/src/core/package_database_loader.cpp +++ b/libmamba/src/core/package_database_loader.cpp @@ -20,7 +20,7 @@ #include "mamba/core/subdirdata.hpp" #include "mamba/core/virtual_packages.hpp" #include "mamba/solver/libsolv/database.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/util/build.hpp" #include "mamba/util/string.hpp" @@ -54,7 +54,7 @@ namespace mamba auto load_subdir_in_database(const Context& ctx, solver::libsolv::Database& db, const SubdirData& subdir) - -> expected_t + -> expected_t { const auto expected_cache_origin = solver::libsolv::RepodataOrigin{ /* .url= */ util::rsplit(subdir.metadata().url(), "/", 1).front(), @@ -110,7 +110,7 @@ namespace mamba } ) .transform( - [&](solver::libsolv::RepoInfo&& repo) -> solver::libsolv::RepoInfo + [&](solver::RepoInfo&& repo) -> solver::RepoInfo { if (!util::on_win) { @@ -134,7 +134,7 @@ namespace mamba const Context& ctx, solver::libsolv::Database& db, const PrefixData& prefix - ) -> solver::libsolv::RepoInfo + ) -> solver::RepoInfo { // TODO(C++20): We could do a PrefixData range that returns packages without storing thems. auto pkgs = prefix.sorted_records(); diff --git a/libmamba/src/solver/libsolv/database.cpp b/libmamba/src/solver/libsolv/database.cpp index c59b82eb3b..3fc11c3ee2 100644 --- a/libmamba/src/solver/libsolv/database.cpp +++ b/libmamba/src/solver/libsolv/database.cpp @@ -17,7 +17,7 @@ #include "mamba/fs/filesystem.hpp" #include "mamba/solver/libsolv/database.hpp" -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/specs/match_spec.hpp" #include "mamba/util/random.hpp" #include "solv-cpp/pool.hpp" diff --git a/libmamba/src/solver/libsolv/repo_info.cpp b/libmamba/src/solver/repo_info.cpp similarity index 88% rename from libmamba/src/solver/libsolv/repo_info.cpp rename to libmamba/src/solver/repo_info.cpp index edf52e66c3..c3277246b4 100644 --- a/libmamba/src/solver/libsolv/repo_info.cpp +++ b/libmamba/src/solver/repo_info.cpp @@ -7,10 +7,10 @@ #include #include -#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/solver/repo_info.hpp" #include "solv-cpp/repo.hpp" -namespace mamba::solver::libsolv +namespace mamba::solver { RepoInfo::RepoInfo(::Repo* repo) : m_ptr(repo) @@ -22,9 +22,9 @@ namespace mamba::solver::libsolv return solv::ObjRepoViewConst(*m_ptr).name(); } - auto RepoInfo::priority() const -> Priorities + auto RepoInfo::priority() const -> libsolv::Priorities { - static_assert(std::is_same_vpriority), Priorities::value_type>); + static_assert(std::is_same_vpriority), libsolv::Priorities::value_type>); return { /* .priority= */ m_ptr->priority, /* .subpriority= */ m_ptr->subpriority }; } diff --git a/libmamba/tests/src/solver/test_problems_graph.cpp b/libmamba/tests/src/solver/test_problems_graph.cpp index 87223292b2..d2302e4b67 100644 --- a/libmamba/tests/src/solver/test_problems_graph.cpp +++ b/libmamba/tests/src/solver/test_problems_graph.cpp @@ -21,10 +21,10 @@ #include "mamba/core/util.hpp" #include "mamba/fs/filesystem.hpp" #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/repo_info.hpp" #include "mamba/specs/package_info.hpp" #include "mamba/util/string.hpp" diff --git a/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp b/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp index a9d1fa7fe5..907faf41d8 100644 --- a/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp +++ b/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp @@ -10,9 +10,9 @@ #include "mamba/solver/libsolv/database.hpp" #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/repo_info.hpp" #include "bind_utils.hpp" #include "bindings.hpp" From fb917935e064de3f4f5ea24b8a76eb6b52101865 Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 1 Aug 2024 12:28:59 +0200 Subject: [PATCH 2/3] python: Adapt bindings accordingly Signed-off-by: Julien Jerphanion --- libmambapy/src/libmambapy/bindings/legacy.cpp | 3 +-- libmambapy/src/libmambapy/bindings/solver.cpp | 11 +++++++++++ .../src/libmambapy/bindings/solver_libsolv.cpp | 12 +----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libmambapy/src/libmambapy/bindings/legacy.cpp b/libmambapy/src/libmambapy/bindings/legacy.cpp index 17c48894e3..40a29238cf 100644 --- a/libmambapy/src/libmambapy/bindings/legacy.cpp +++ b/libmambapy/src/libmambapy/bindings/legacy.cpp @@ -512,8 +512,7 @@ bind_submodule_impl(pybind11::module_ m) py::class_(m, "SubdirData") .def( "create_repo", - [](SubdirData& self, Context& context, solver::libsolv::Database& db - ) -> solver::libsolv::RepoInfo + [](SubdirData& self, Context& context, solver::libsolv::Database& db) -> solver::RepoInfo { deprecated("Use libmambapy.load_subdir_in_database instead", "2.0"); return extract(load_subdir_in_database(context, db, self)); diff --git a/libmambapy/src/libmambapy/bindings/solver.cpp b/libmambapy/src/libmambapy/bindings/solver.cpp index 7e7176dd30..bae85ed6e9 100644 --- a/libmambapy/src/libmambapy/bindings/solver.cpp +++ b/libmambapy/src/libmambapy/bindings/solver.cpp @@ -8,6 +8,7 @@ #include #include "mamba/solver/problems_graph.hpp" +#include "mamba/solver/repo_info.hpp" #include "mamba/solver/request.hpp" #include "mamba/solver/solution.hpp" @@ -507,5 +508,15 @@ namespace mambapy } ) .def("tree_message", &problem_tree_msg, py::arg("format") = ProblemsMessageFormat()); + + py::class_(m, "RepoInfo") + .def_property_readonly("id", &RepoInfo::id) + .def_property_readonly("name", &RepoInfo::name) + .def_property_readonly("priority", &RepoInfo::priority) + .def("package_count", &RepoInfo::package_count) + .def(py::self == py::self) + .def(py::self != py::self) + .def("__copy__", ©) + .def("__deepcopy__", &deepcopy, py::arg("memo")); } } diff --git a/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp b/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp index 907faf41d8..a30c95dce9 100644 --- a/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp +++ b/libmambapy/src/libmambapy/bindings/solver_libsolv.cpp @@ -106,16 +106,6 @@ namespace mambapy .def("__copy__", ©) .def("__deepcopy__", &deepcopy, py::arg("memo")); - py::class_(m, "RepoInfo") - .def_property_readonly("id", &RepoInfo::id) - .def_property_readonly("name", &RepoInfo::name) - .def_property_readonly("priority", &RepoInfo::priority) - .def("package_count", &RepoInfo::package_count) - .def(py::self == py::self) - .def(py::self != py::self) - .def("__copy__", ©) - .def("__deepcopy__", &deepcopy, py::arg("memo")); - py::class_(m, "Database") .def(py::init(), py::arg("channel_params")) .def("set_logger", &Database::set_logger, py::call_guard()) @@ -169,7 +159,7 @@ namespace mambapy .def("package_count", &Database::package_count) .def( "packages_in_repo", - [](const Database& db, RepoInfo repo) + [](const Database& db, solver::RepoInfo repo) { // TODO(C++20): When Database function are refactored to use range, take the // opportunity here to make a Python iterator to avoid large alloc. From dbdb1c9070430135480c7fa0bbc340d71f38472a Mon Sep 17 00:00:00 2001 From: Julien Jerphanion Date: Thu, 1 Aug 2024 12:30:02 +0200 Subject: [PATCH 3/3] docs: Adapt documentation accordingly Signed-off-by: Julien Jerphanion --- docs/source/usage/solver.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/usage/solver.rst b/docs/source/usage/solver.rst index 91a045655e..20b4e3ac9d 100644 --- a/docs/source/usage/solver.rst +++ b/docs/source/usage/solver.rst @@ -26,7 +26,7 @@ Populating the Package Database ------------------------------- The first thing needed is a |Database| of all the packages and their dependencies. Packages are organised in repositories, described by a -:cpp:type:`RepoInfo `. +:cpp:type:`RepoInfo `. This serves to resolve explicit channel requirements or channel priority. As such, the database constructor takes a set of :cpp:type:`ChannelResolveParams `