Skip to content

Commit

Permalink
repoquery: Implemented recursive dependency printout. Closes: #1242
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Strunk authored and Timo Strunk committed Feb 12, 2023
1 parent baf3c48 commit 940b66b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
8 changes: 6 additions & 2 deletions docs/source/user_guide/mamba.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
9 changes: 5 additions & 4 deletions libmamba/include/mamba/core/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions libmamba/src/api/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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" });
Expand Down
5 changes: 4 additions & 1 deletion libmambapy/libmambapy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,8 @@ class QueryFormat:
TABLE
PRETTY
RECURSIVETABLE
"""

def __eq__(self, other: object) -> bool: ...
Expand All @@ -1147,7 +1149,8 @@ class QueryFormat:
PRETTY: libmambapy.bindings.QueryFormat # value = <QueryFormat.PRETTY: 3>
TABLE: libmambapy.bindings.QueryFormat # value = <QueryFormat.TABLE: 2>
TREE: libmambapy.bindings.QueryFormat # value = <QueryFormat.TREE: 1>
__members__: dict # value = {'JSON': <QueryFormat.JSON: 0>, 'TREE': <QueryFormat.TREE: 1>, 'TABLE': <QueryFormat.TABLE: 2>, 'PRETTY': <QueryFormat.PRETTY: 3>}
RECURSIVETABLE: libmambapy.bindings.QueryFormat # value = <QueryFormat.RECURSIVETABLE: 4>
__members__: dict # value = {'JSON': <QueryFormat.JSON: 0>, 'TREE': <QueryFormat.TREE: 1>, 'TABLE': <QueryFormat.TABLE: 2>, 'PRETTY': <QueryFormat.PRETTY: 3>, 'RECURSIVETABLE': <QueryFormat.RECURSIVETABLE: 4>}
pass

class Repo:
Expand Down
17 changes: 11 additions & 6 deletions libmambapy/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ namespace query
{
enum RESULT_FORMAT
{
JSON,
TREE,
TABLE,
PRETTY
JSON = 0,
TREE = 1,
TABLE= 2,
PRETTY = 3,
RECURSIVETABLE = 4,
};
}

Expand Down Expand Up @@ -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_<Query>(m, "Query")
.def(py::init<MPool&>())
Expand All @@ -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:
Expand All @@ -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" });
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions mamba/mamba/mamba.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions micromamba/src/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)");

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 940b66b

Please sign in to comment.