mirror of https://github.com/mamba-org/mamba.git
Add missing MatchSpec equality operator (#4033)
This commit is contained in:
parent
4185322d51
commit
28cf27362b
|
@ -124,16 +124,9 @@ namespace mamba::specs
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto contains(BuildNumber point) const -> bool;
|
[[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 = default;
|
||||||
[[nodiscard]] auto operator==(const BuildNumberSpec& other) const -> bool
|
|
||||||
{
|
|
||||||
return m_predicate == other.m_predicate;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool
|
[[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool = default;
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "mamba/specs/version_spec.hpp"
|
#include "mamba/specs/version_spec.hpp"
|
||||||
#include "mamba/util/flat_set.hpp"
|
#include "mamba/util/flat_set.hpp"
|
||||||
#include "mamba/util/heap_optional.hpp"
|
#include "mamba/util/heap_optional.hpp"
|
||||||
#include "mamba/util/tuple_hash.hpp"
|
|
||||||
|
|
||||||
namespace mamba::specs
|
namespace mamba::specs
|
||||||
{
|
{
|
||||||
|
@ -142,22 +141,15 @@ namespace mamba::specs
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] auto contains_except_channel(const PackageInfo& pkg) const -> bool;
|
[[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
|
* Naive attribute-wise comparison.
|
||||||
{
|
*
|
||||||
return m_channel == other.m_channel //
|
* @warning Some complex matchspec could compare to false but actually represent the same
|
||||||
&& m_version == other.m_version //
|
* set of packages. This strong equality is hard to detect.
|
||||||
&& m_name == other.m_name //
|
*/
|
||||||
&& m_build_string == other.m_build_string //
|
[[nodiscard]] auto operator==(const MatchSpec& other) const -> bool = default;
|
||||||
&& m_name_space == other.m_name_space //
|
|
||||||
&& m_build_number == other.m_build_number //
|
|
||||||
&& m_extra == other.m_extra;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool
|
[[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool = default;
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto extra_members_hash() const -> std::size_t;
|
auto extra_members_hash() const -> std::size_t;
|
||||||
|
|
||||||
|
|
|
@ -897,6 +897,8 @@ namespace mambapy
|
||||||
.def("is_simple", &MatchSpec::is_simple)
|
.def("is_simple", &MatchSpec::is_simple)
|
||||||
.def("is_only_package_name", &MatchSpec::is_only_package_name)
|
.def("is_only_package_name", &MatchSpec::is_only_package_name)
|
||||||
.def("conda_build_form", &MatchSpec::conda_build_form)
|
.def("conda_build_form", &MatchSpec::conda_build_form)
|
||||||
|
.def(py::self == py::self)
|
||||||
|
.def(py::self != py::self)
|
||||||
.def("__str__", &MatchSpec::to_string)
|
.def("__str__", &MatchSpec::to_string)
|
||||||
.def("__copy__", ©<MatchSpec>)
|
.def("__copy__", ©<MatchSpec>)
|
||||||
.def("__deepcopy__", &deepcopy<MatchSpec>, py::arg("memo"));
|
.def("__deepcopy__", &deepcopy<MatchSpec>, py::arg("memo"));
|
||||||
|
|
|
@ -932,6 +932,8 @@ def test_MatchSpec():
|
||||||
assert ms.is_file()
|
assert ms.is_file()
|
||||||
assert str(ms.name) == "pkg"
|
assert str(ms.name) == "pkg"
|
||||||
assert ms.filename == "pkg-2-bld.conda"
|
assert ms.filename == "pkg-2-bld.conda"
|
||||||
|
assert ms == ms
|
||||||
|
assert ms != MatchSpec.parse("foo")
|
||||||
|
|
||||||
# Errors
|
# Errors
|
||||||
with pytest.raises(libmambapy.specs.ParseError):
|
with pytest.raises(libmambapy.specs.ParseError):
|
||||||
|
|
Loading…
Reference in New Issue