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

repoquery: Implemented recursive dependency printout. Closes: #1242 #2283

Merged
merged 1 commit into from
Feb 13, 2023
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
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 (i.e. transitive) 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
10 changes: 8 additions & 2 deletions libmamba/src/api/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ 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 +89,15 @@ 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 +108,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 @@ -1145,9 +1147,10 @@ class QueryFormat:
"""
JSON: libmambapy.bindings.QueryFormat # value = <QueryFormat.JSON: 0>
PRETTY: libmambapy.bindings.QueryFormat # value = <QueryFormat.PRETTY: 3>
RECURSIVETABLE: libmambapy.bindings.QueryFormat # value = <QueryFormat.RECURSIVETABLE: 4>
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>}
__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
18 changes: 12 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,8 @@ 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 +402,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
7 changes: 7 additions & 0 deletions micromamba/src/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ 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 (i.e. transitive dependencies).");

static bool pretty_print = false;
subcom->add_flag("--pretty", pretty_print, "Pretty print result (only for search)");

Expand Down Expand Up @@ -83,6 +87,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