Add missing MatchSpec equality operator

This commit is contained in:
AntoinePrv 2025-07-30 18:16:44 +02:00
parent 4185322d51
commit b2e3f2d147
4 changed files with 14 additions and 25 deletions

View File

@ -124,16 +124,9 @@ namespace mamba::specs
*/
[[nodiscard]] auto contains(BuildNumber point) const -> bool;
// TODO(C++20): replace by the `= default` implementation of `operator==`
[[nodiscard]] auto operator==(const BuildNumberSpec& other) const -> bool
{
return m_predicate == other.m_predicate;
}
[[nodiscard]] auto operator==(const BuildNumberSpec& other) const -> bool = default;
[[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool
{
return !(*this == other);
}
[[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool = default;
private:

View File

@ -23,7 +23,6 @@
#include "mamba/specs/version_spec.hpp"
#include "mamba/util/flat_set.hpp"
#include "mamba/util/heap_optional.hpp"
#include "mamba/util/tuple_hash.hpp"
namespace mamba::specs
{
@ -142,22 +141,15 @@ namespace mamba::specs
*/
[[nodiscard]] auto contains_except_channel(const PackageInfo& pkg) const -> bool;
// TODO(C++20): replace by the `= default` implementation of `operator==`
[[nodiscard]] auto operator==(const MatchSpec& other) const -> bool
{
return m_channel == other.m_channel //
&& m_version == other.m_version //
&& m_name == other.m_name //
&& m_build_string == other.m_build_string //
&& m_name_space == other.m_name_space //
&& m_build_number == other.m_build_number //
&& m_extra == other.m_extra;
}
/**
* Naive attribute-wise comparison.
*
* @warning Some complex matchspec could compare to false but actually represent the same
* set of packages. This strong equality is hard to detect.
*/
[[nodiscard]] auto operator==(const MatchSpec& other) const -> bool = default;
[[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool
{
return !(*this == other);
}
[[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool = default;
auto extra_members_hash() const -> std::size_t;

View File

@ -897,6 +897,8 @@ namespace mambapy
.def("is_simple", &MatchSpec::is_simple)
.def("is_only_package_name", &MatchSpec::is_only_package_name)
.def("conda_build_form", &MatchSpec::conda_build_form)
.def(py::self == py::self)
.def(py::self != py::self)
.def("__str__", &MatchSpec::to_string)
.def("__copy__", &copy<MatchSpec>)
.def("__deepcopy__", &deepcopy<MatchSpec>, py::arg("memo"));

View File

@ -932,6 +932,8 @@ def test_MatchSpec():
assert ms.is_file()
assert str(ms.name) == "pkg"
assert ms.filename == "pkg-2-bld.conda"
assert ms == ms
assert ms != MatchSpec.parse("foo")
# Errors
with pytest.raises(libmambapy.specs.ParseError):