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

Bind text_style and graphic params #3266

Merged
merged 5 commits into from
Apr 8, 2024
Merged
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
1 change: 0 additions & 1 deletion libmamba/include/mamba/core/palette.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace mamba
/** Some action is unsafe or not trusted. */
fmt::text_style unsafe;


/** Reference to some input from the user. */
fmt::text_style user;
/** Input from the user was ignored or has no effect. */
Expand Down
4 changes: 2 additions & 2 deletions libmamba/include/mamba/solver/libsolv/unsolvable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace mamba::solver::libsolv
auto explain_problems_to( //
Database& pool,
std::ostream& out,
const Palette& palette
const ProblemsMessageFormat& format
) const -> std::ostream&;

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

private:

Expand Down
9 changes: 8 additions & 1 deletion libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,14 @@ namespace mamba

if (auto* unsolvable = std::get_if<solver::libsolv::UnSolvable>(&outcome))
{
unsolvable->explain_problems_to(db, LOG_ERROR, ctx.graphics_params.palette);
unsolvable->explain_problems_to(
db,
LOG_ERROR,
{
/* .unavailable= */ ctx.graphics_params.palette.failure,
/* .available= */ ctx.graphics_params.palette.success,
}
);
if (retry_clean_cache && !is_retry)
{
ctx.local_repodata_ttl = 2;
Expand Down
22 changes: 9 additions & 13 deletions libmamba/src/solver/libsolv/unsolvable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,30 +482,26 @@ namespace mamba::solver::libsolv
return ProblemsGraphCreator(Database::Impl::get(pool), *m_solver).problem_graph();
}

auto
UnSolvable::explain_problems_to(Database& pool, std::ostream& out, const Palette& palette) const
-> std::ostream&
auto UnSolvable::explain_problems_to(
Database& pool,
std::ostream& out,
const ProblemsMessageFormat& format
) const -> std::ostream&
{
out << "Could not solve for environment specs\n";
const auto pbs = problems_graph(pool);
const auto pbs_simplified = simplify_conflicts(pbs);
const auto cp_pbs = CompressedProblemsGraph::from_problems_graph(pbs_simplified);
print_problem_tree_msg(
out,
cp_pbs,
{
/* .unavailable= */ palette.failure,
/* .available= */ palette.success,
}
);
print_problem_tree_msg(out, cp_pbs, format);
return out;
}

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

{
std::stringstream ss;
explain_problems_to(pool, ss, palette);
explain_problems_to(pool, ss, format);
return ss.str();
}
}
1 change: 1 addition & 0 deletions libmambapy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pybind11_add_module(
# All bindings used to live in a global module
src/libmambapy/bindings/legacy.cpp
# Submodules
src/libmambapy/bindings/utils.cpp
src/libmambapy/bindings/specs.cpp
src/libmambapy/bindings/solver.cpp
src/libmambapy/bindings/solver_libsolv.cpp
Expand Down
1 change: 1 addition & 0 deletions libmambapy/src/libmambapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Import all submodules so that one can use them directly with `import libmambapy`
import libmambapy.utils
import libmambapy.version
import libmambapy.specs
import libmambapy.solver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// The full license is in the file LICENSE, distributed with this software.

#ifndef LIBMAMBAPY_UTILS_HPP
#define LIBMAMBAPY_UTILS_HPP
#ifndef LIBMAMBAPY_BIND_UTILS_HPP
#define LIBMAMBAPY_BIND_UTILS_HPP

#include <memory>

Expand Down
1 change: 1 addition & 0 deletions libmambapy/src/libmambapy/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

PYBIND11_MODULE(bindings, m)
{
mambapy::bind_submodule_utils(m.def_submodule("utils"));
mambapy::bind_submodule_specs(m.def_submodule("specs"));
auto solver_submodule = m.def_submodule("solver");
mambapy::bind_submodule_solver(solver_submodule);
Expand Down
1 change: 1 addition & 0 deletions libmambapy/src/libmambapy/bindings/bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace mambapy
{
void bind_submodule_utils(pybind11::module_ m);
void bind_submodule_specs(pybind11::module_ m);
void bind_submodule_solver(pybind11::module_ m);
void bind_submodule_solver_libsolv(pybind11::module_ m);
Expand Down
23 changes: 21 additions & 2 deletions libmambapy/src/libmambapy/bindings/legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
#include "mamba/validation/tools.hpp"
#include "mamba/validation/update_framework_v0_6.hpp"

#include "bind_utils.hpp"
#include "bindings.hpp"
#include "expected_caster.hpp"
#include "flat_set_caster.hpp"
#include "path_caster.hpp"
#include "utils.hpp"

namespace py = pybind11;

Expand Down Expand Up @@ -620,7 +620,25 @@ bind_submodule_impl(pybind11::module_ m)

py::class_<Palette>(m, "Palette")
.def_static("no_color", &Palette::no_color)
.def_static("terminal", &Palette::terminal);
.def_static("terminal", &Palette::terminal)
.def_readwrite("success", &Palette::success)
.def_readwrite("failure", &Palette::failure)
.def_readwrite("external", &Palette::external)
.def_readwrite("shown", &Palette::shown)
.def_readwrite("safe", &Palette::safe)
.def_readwrite("unsafe", &Palette::unsafe)
.def_readwrite("user", &Palette::user)
.def_readwrite("ignored", &Palette::ignored)
.def_readwrite("addition", &Palette::addition)
.def_readwrite("deletion", &Palette::deletion)
.def_readwrite("progress_bar_none", &Palette::progress_bar_none)
.def_readwrite("progress_bar_downloaded", &Palette::progress_bar_downloaded)
.def_readwrite("progress_bar_extracted", &Palette::progress_bar_extracted);

py::class_<Context::GraphicsParams>(m, "GraphicsParams")
.def(py::init())
.def_readwrite("no_progress_bars", &Context::GraphicsParams::no_progress_bars)
.def_readwrite("palette", &Context::GraphicsParams::palette);

py::class_<Context, std::unique_ptr<Context, py::nodelete>> ctx(m, "Context");
ctx //
Expand All @@ -641,6 +659,7 @@ bind_submodule_impl(pybind11::module_ m)
}
))
.def_static("use_default_signal_handler", &Context::use_default_signal_handler)
.def_readwrite("graphics_params", &Context::graphics_params)
.def_readwrite("offline", &Context::offline)
.def_readwrite("local_repodata_ttl", &Context::local_repodata_ttl)
.def_readwrite("use_index_cache", &Context::use_index_cache)
Expand Down
32 changes: 27 additions & 5 deletions libmambapy/src/libmambapy/bindings/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "mamba/solver/request.hpp"
#include "mamba/solver/solution.hpp"

#include "bind_utils.hpp"
#include "bindings.hpp"
#include "flat_set_caster.hpp"
#include "utils.hpp"

namespace mamba::solver
{
Expand Down Expand Up @@ -388,6 +388,31 @@ namespace mambapy
)
.def_static("simplify_conflicts", &solver::simplify_conflicts);

py::class_<ProblemsMessageFormat>(m, "ProblemsMessageFormat")
.def(py::init<>())
.def(
py::init(
[](fmt::text_style unavailable,
fmt::text_style available,
std::array<std::string_view, 4> indents) -> ProblemsMessageFormat
{
return {
/* .unavailable= */ unavailable,
/* .available= */ available,
/* .indents= */ indents,
};
}
),
py::arg("unavailable"),
py::arg("available"),
py::arg("indents")
)
.def_readwrite("unavailable", &ProblemsMessageFormat::unavailable)
.def_readwrite("available", &ProblemsMessageFormat::available)
.def_readwrite("indents", &ProblemsMessageFormat::indents)
.def("__copy__", &copy<ProblemsMessageFormat>)
.def("__deepcopy__", &deepcopy<ProblemsMessageFormat>, py::arg("memo"));

auto py_compressed_problems_graph = py::class_<CompressedProblemsGraph>(
m,
"CompressedProblemsGraph"
Expand Down Expand Up @@ -481,9 +506,6 @@ namespace mambapy
return std::pair(g.nodes(), g.edges());
}
)
.def(
"tree_message",
[](const CompressedProblemsGraph& self) { return problem_tree_msg(self); }
);
.def("tree_message", &problem_tree_msg, py::arg("format") = ProblemsMessageFormat());
}
}
5 changes: 2 additions & 3 deletions libmambapy/src/libmambapy/bindings/solver_libsolv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>

#include "mamba/core/palette.hpp"
#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 "bind_utils.hpp"
#include "bindings.hpp"
#include "expected_caster.hpp"
#include "path_caster.hpp"
#include "utils.hpp"

namespace mambapy
{
Expand Down Expand Up @@ -223,7 +222,7 @@ namespace mambapy
"explain_problems",
&UnSolvable::explain_problems,
py::arg("database"),
py::arg("palette")
py::arg("format")
);

constexpr auto solver_flags_v2_migrator = [](Solver&, py::args, py::kwargs) {
Expand Down
2 changes: 1 addition & 1 deletion libmambapy/src/libmambapy/bindings/specs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include "mamba/specs/version.hpp"
#include "mamba/specs/version_spec.hpp"

#include "bind_utils.hpp"
#include "bindings.hpp"
#include "expected_caster.hpp"
#include "flat_set_caster.hpp"
#include "utils.hpp"
#include "weakening_map_bind.hpp"

PYBIND11_MAKE_OPAQUE(mamba::specs::VersionPart);
Expand Down
Loading
Loading