diff --git a/docs/source/user_guide/mamba.rst b/docs/source/user_guide/mamba.rst index bc14514475..d2faf70b7e 100644 --- a/docs/source/user_guide/mamba.rst +++ b/docs/source/user_guide/mamba.rst @@ -68,10 +68,14 @@ Here are some examples: # you can also specify more constraints on this search query $ mamba repoquery search "xtensor>=0.18" - # will show you a list of the dependencies of xtensor. + # will show you a list of the direct dependencies of xtensor. $ mamba repoquery depends xtensor -With the ``-t,--tree`` flag, you can get the same information in a tree. + # will show you a list of the dependencies (including dependencies of dependencies). + $ mamba repoquery depends xtensor --recursive + +The flag ``--recursive`` shows also recursive dependencies of dependent packages instead of only direct dependencies. +With the ``-t,--tree`` flag, you can get the same information of a recursive query in a tree. .. code:: diff --git a/libmamba/include/mamba/core/query.hpp b/libmamba/include/mamba/core/query.hpp index fffc246480..8b9b03386b 100644 --- a/libmamba/include/mamba/core/query.hpp +++ b/libmamba/include/mamba/core/query.hpp @@ -58,10 +58,11 @@ namespace mamba enum class QueryResultFormat { - kJSON, - kTREE, - kTABLE, - kPRETTY + kJSON = 0, + kTREE = 1, + kTABLE= 2, + kPRETTY = 3, + kRECURSIVETABLE = 4, }; class query_result diff --git a/libmamba/src/api/repoquery.cpp b/libmamba/src/api/repoquery.cpp index e406771f2e..e7a8c54b87 100644 --- a/libmamba/src/api/repoquery.cpp +++ b/libmamba/src/api/repoquery.cpp @@ -76,7 +76,7 @@ namespace mamba } else if (type == QueryType::kDEPENDS) { - auto res = q.depends(query, format == QueryResultFormat::kTREE); + auto res = q.depends(query, format == QueryResultFormat::kTREE || format == QueryResultFormat::kRECURSIVETABLE); switch (format) { case QueryResultFormat::kTREE: @@ -87,12 +87,13 @@ namespace mamba std::cout << res.json().dump(4); break; case QueryResultFormat::kTABLE: + case QueryResultFormat::kRECURSIVETABLE: res.sort("name").table(std::cout); } } else if (type == QueryType::kWHONEEDS) { - auto res = q.whoneeds(query, format == QueryResultFormat::kTREE); + auto res = q.whoneeds(query, format == QueryResultFormat::kTREE || format == QueryResultFormat::kRECURSIVETABLE); switch (format) { case QueryResultFormat::kTREE: @@ -103,6 +104,7 @@ namespace mamba std::cout << res.json().dump(4); break; case QueryResultFormat::kTABLE: + case QueryResultFormat::kRECURSIVETABLE: res.sort("name").table( std::cout, { "Name", "Version", "Build", concat("Depends:", query), "Channel" }); diff --git a/libmambapy/libmambapy/__init__.pyi b/libmambapy/libmambapy/__init__.pyi index 799c2b752f..0e90247113 100644 --- a/libmambapy/libmambapy/__init__.pyi +++ b/libmambapy/libmambapy/__init__.pyi @@ -1122,6 +1122,8 @@ class QueryFormat: TABLE PRETTY + + RECURSIVETABLE """ def __eq__(self, other: object) -> bool: ... @@ -1147,7 +1149,8 @@ class QueryFormat: PRETTY: libmambapy.bindings.QueryFormat # value = TABLE: libmambapy.bindings.QueryFormat # value = TREE: libmambapy.bindings.QueryFormat # value = - __members__: dict # value = {'JSON': , 'TREE': , 'TABLE': , 'PRETTY': } + RECURSIVETABLE: libmambapy.bindings.QueryFormat # value = + __members__: dict # value = {'JSON': , 'TREE': , 'TABLE': , 'PRETTY': , 'RECURSIVETABLE': } pass class Repo: diff --git a/libmambapy/src/main.cpp b/libmambapy/src/main.cpp index a6d4df99a1..0ee65d107a 100644 --- a/libmambapy/src/main.cpp +++ b/libmambapy/src/main.cpp @@ -43,10 +43,11 @@ namespace query { enum RESULT_FORMAT { - JSON, - TREE, - TABLE, - PRETTY + JSON = 0, + TREE = 1, + TABLE= 2, + PRETTY = 3, + RECURSIVETABLE = 4, }; } @@ -332,7 +333,8 @@ PYBIND11_MODULE(bindings, m) .value("JSON", query::RESULT_FORMAT::JSON) .value("TREE", query::RESULT_FORMAT::TREE) .value("TABLE", query::RESULT_FORMAT::TABLE) - .value("PRETTY", query::RESULT_FORMAT::PRETTY); + .value("PRETTY", query::RESULT_FORMAT::PRETTY) + .value("RECURSIVETABLE", query::RESULT_FORMAT::RECURSIVETABLE); py::class_(m, "Query") .def(py::init()) @@ -349,6 +351,7 @@ PYBIND11_MODULE(bindings, m) break; case query::TREE: case query::TABLE: + case query::RECURSIVETABLE: q.find(query).groupby("name").table(res_stream); break; case query::PRETTY: @@ -374,6 +377,7 @@ PYBIND11_MODULE(bindings, m) res_stream << res.json().dump(4); break; case query::TABLE: + case query::RECURSIVETABLE: res.table( res_stream, { "Name", "Version", "Build", concat("Depends:", query), "Channel" }); @@ -385,7 +389,7 @@ PYBIND11_MODULE(bindings, m) const std::string& query, const query::RESULT_FORMAT format) -> std::string { - query_result res = q.depends(query, (format == query::TREE)); + query_result res = q.depends(query, (format == query::TREE || format == query::RECURSIVETABLE)); std::stringstream res_stream; switch (format) { @@ -397,6 +401,7 @@ PYBIND11_MODULE(bindings, m) res_stream << res.json().dump(4); break; case query::TABLE: + case query::RECURSIVETABLE: // res.table(res_stream, {"Name", "Version", "Build", concat("Depends:", // query), "Channel"}); res.table(res_stream); diff --git a/mamba/mamba/mamba.py b/mamba/mamba/mamba.py index e722568dfe..e420f66278 100644 --- a/mamba/mamba/mamba.py +++ b/mamba/mamba/mamba.py @@ -694,6 +694,8 @@ def repoquery(args, parser): fmt = api.QueryFormat.JSON elif hasattr(args, "tree") and args.tree: fmt = api.QueryFormat.TREE + elif hasattr(args, "recursive") and args.recursive: + fmt = api.QueryFormat.RECURSIVETABLE elif hasattr(args, "pretty") and args.pretty: fmt = api.QueryFormat.PRETTY else: @@ -818,6 +820,7 @@ def configure_parser_repoquery(sub_parsers): view_cmds = argparse.ArgumentParser(add_help=False) view_cmds.add_argument("-t", "--tree", action="store_true") + view_cmds.add_argument("--recursive", action="store_true") c1 = subsub_parser.add_parser( "whoneeds", diff --git a/micromamba/src/repoquery.cpp b/micromamba/src/repoquery.cpp index f4a8c00467..4d4333189b 100644 --- a/micromamba/src/repoquery.cpp +++ b/micromamba/src/repoquery.cpp @@ -50,6 +50,9 @@ set_common_search(CLI::App* subcom, bool is_repoquery) static bool show_as_tree = false; subcom->add_flag("-t,--tree", show_as_tree, "Show result as a tree"); + static bool recursive = false; + subcom->add_flag("--recursive", recursive, "Show dependencies recursively."); + static bool pretty_print = false; subcom->add_flag("--pretty", pretty_print, "Pretty print result (only for search)"); @@ -83,6 +86,9 @@ set_common_search(CLI::App* subcom, bool is_repoquery) local = (local == 0) ? true : local > 0; break; } + if (qtype == QueryType::kDEPENDS && recursive) + format = QueryResultFormat::kRECURSIVETABLE; + if (qtype == QueryType::kDEPENDS && show_as_tree) format = QueryResultFormat::kTREE;