Replace MTransaction::m_remove with Solution (#2603)

* Replace MTransaction m_to_remove with m_solution

* Add MSolver filters to Solution

* Add conversion test and accessor to flat_set

* Fix solution filtering in MTransaction

* Use Solution in MTransaction::print

* Ue m_solution in MTransaction::execute

* Fix Json logging

* MTransaction fix python search

* Fix transaction-to_solution topological order

* Fix MTransaction::execute reinstalls

* Remove MTransaction::m_transaction

* Remove MTransaction::filter

* Remove MTransaction::m_filter_name_id

* Add control flow in ObjTransaction loops

* Refactor find_python_versions

* Remove copies in iterations

* Review comments from @JohanMabille
This commit is contained in:
Antoine Prouvost 2023-07-07 00:33:05 +02:00 committed by GitHub
parent c926198af8
commit 3b6e10159f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 494 additions and 455 deletions

View File

@ -7,8 +7,6 @@
#ifndef MAMBA_CORE_TRANSACTION_HPP
#define MAMBA_CORE_TRANSACTION_HPP
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <vector>
@ -19,31 +17,20 @@
#include "match_spec.hpp"
#include "package_cache.hpp"
#include "package_info.hpp"
#include "pool.hpp"
#include "prefix_data.hpp"
#include "solver.hpp"
#include "solution.hpp"
#include "transaction_context.hpp"
namespace mamba::solv
{
class ObjTransaction;
class ObjSolvableViewConst;
}
namespace mamba
{
class ChannelContext;
class MSolver;
class MTransaction
{
public:
enum class FilterType
{
none,
keep_only,
ignore
};
MTransaction(
MPool& pool,
const std::vector<MatchSpec>& specs_to_remove,
@ -55,11 +42,9 @@ namespace mamba
// Only use if the packages have been solved previously already.
MTransaction(MPool& pool, const std::vector<PackageInfo>& packages, MultiPackageCache& caches);
~MTransaction();
MTransaction(const MTransaction&) = delete;
MTransaction& operator=(const MTransaction&) = delete;
MTransaction(MTransaction&&) = delete;
MTransaction& operator=(const MTransaction&) = delete;
MTransaction& operator=(MTransaction&&) = delete;
using to_install_type = std::vector<std::tuple<std::string, std::string, std::string>>;
@ -75,32 +60,19 @@ namespace mamba
void print();
bool execute(PrefixData& prefix);
std::pair<std::string, std::string> find_python_version();
[[deprecated]] std::pair<std::string, std::string> py_find_python_version() const;
private:
MPool m_pool;
FilterType m_filter_type = FilterType::none;
std::set<Id> m_filter_name_ids;
TransactionContext m_transaction_context;
MultiPackageCache m_multi_cache;
const fs::u8path m_cache_path;
std::vector<PackageInfo> m_to_install;
std::vector<PackageInfo> m_to_remove;
Solution m_solution;
History::UserRequest m_history_entry = History::UserRequest::prefilled();
// Temporarily using Pimpl for encapsulation
std::unique_ptr<solv::ObjTransaction> m_transaction;
std::vector<MatchSpec> m_requested_specs;
void init();
bool filter(const solv::ObjSolvableViewConst& s) const;
auto trans() -> solv::ObjTransaction&;
auto trans() const -> const solv::ObjTransaction&;
};
MTransaction create_explicit_transaction_from_urls(

View File

@ -72,6 +72,8 @@ namespace mamba::util
bool contains(const value_type&) const;
const value_type& front() const noexcept;
const value_type& back() const noexcept;
const value_type& operator[](size_type pos) const;
const value_type& at(size_type pos) const;
const_iterator begin() const noexcept;
const_iterator end() const noexcept;
@ -195,6 +197,18 @@ namespace mamba::util
return Base::back();
}
template <typename K, typename C, typename A>
auto flat_set<K, C, A>::operator[](size_type pos) const -> const value_type&
{
return Base::operator[](pos);
}
template <typename K, typename C, typename A>
auto flat_set<K, C, A>::at(size_type pos) const -> const value_type&
{
return Base::at(pos);
}
template <typename K, typename C, typename A>
auto flat_set<K, C, A>::begin() const noexcept -> const_iterator
{

File diff suppressed because it is too large Load Diff

View File

@ -84,7 +84,7 @@ namespace mamba::solv
auto ObjTransaction::size() const -> std::size_t
{
assert(raw()->steps.count);
assert(raw()->steps.count >= 0);
return static_cast<std::size_t>(raw()->steps.count);
}

View File

@ -157,7 +157,18 @@ namespace mamba::solv
const auto count = static_cast<std::size_t>(steps.count);
for (std::size_t i = 0; i < count; ++i)
{
func(steps.elements[i]);
const auto id = steps.elements[i];
if constexpr (std::is_same_v<decltype(func(id)), LoopControl>)
{
if (func(id) == LoopControl::Break)
{
break;
}
}
else
{
func(id);
}
}
}
@ -176,7 +187,18 @@ namespace mamba::solv
for (std::size_t n = types.size(), i = 0; i < n; i += 4)
{
const TransactionStepType type = types[i];
func(type, classify_pkgs(pool, type, types[i + 2], types[i + 3], mode));
auto ids = classify_pkgs(pool, type, types[i + 2], types[i + 3], mode);
if constexpr (std::is_same_v<decltype(func(type, std::move(ids))), LoopControl>)
{
if (func(type, std::move(ids)) == LoopControl::Break)
{
break;
}
}
else
{
func(type, std::move(ids));
}
}
}
}

View File

@ -4,7 +4,9 @@
//
// The full license is in the file LICENSE, distributed with this software.
#include <array>
#include <type_traits>
#include <vector>
#include <doctest/doctest.h>
@ -61,6 +63,16 @@ TEST_SUITE("flat_set")
CHECK_EQ(s, flat_set<int>({ 0, 17, 22, 33 }));
}
TEST_CASE("insert conversion")
{
auto s = flat_set<std::string>();
const auto v = std::array<std::string_view, 2>{ "hello", "world" };
s.insert(v.cbegin(), v.cend());
REQUIRE_EQ(s.size(), 2);
CHECK_EQ(s.at(0), "hello");
CHECK_EQ(s.at(1), "world");
}
TEST_CASE("erase")
{
auto s = flat_set<int>{ 4, 3, 2, 1 };

View File

@ -219,7 +219,7 @@ PYBIND11_MODULE(bindings, m)
.def("print", &MTransaction::print)
.def("fetch_extract_packages", &MTransaction::fetch_extract_packages)
.def("prompt", &MTransaction::prompt)
.def("find_python_version", &MTransaction::find_python_version)
.def("find_python_version", &MTransaction::py_find_python_version)
.def("execute", &MTransaction::execute);
pySolver.def(py::init<MPool&, std::vector<std::pair<int, int>>>(), py::keep_alive<1, 2>())