-
Notifications
You must be signed in to change notification settings - Fork 382
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
feat: add base flag to info command #3779
base: main
Are you sure you want to change the base?
Conversation
libmamba/src/api/info.cpp
Outdated
std::cout << ctx.prefix_params.root_prefix.string() << std::endl; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to early return in this case, also LOG_INFO
is preferred generally I think.
std::cout << ctx.prefix_params.root_prefix.string() << std::endl; | |
} | |
else | |
LOG_INFO << ctx.prefix_params.root_prefix.string() << std::endl; | |
return; | |
} |
and remove the parenthesis of the blocks and unindent the code to use the previous identation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand which parenthesis you are talking about.
If I just make this change (replacing std::cout
with LOG_INFO
and adding return;
), the output is not printed in the terminal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad: I meant curly brackets, and let's use std::cout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I leave it as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually part of my previous comment can be addressed: can you early return on the first case so that the block from line 99 to line 193 can keep the same level of indentation?
micromamba/src/info.cpp
Outdated
using namespace mamba; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for Configurable
, which is a mamba::Configurable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, in this case I propose https://github.com/mamba-org/mamba/pull/3779/files#r1936931327.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, using namespace
directive should be avoided as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done in /mamba/micromamba/src/list.cpp , which is why I originally went for it in /mamba/micromamba/src/info.cpp (but it used only once here, and more in list.cpp).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, we can remove (broad) using namespace
directives in another PR.
micromamba/src/info.cpp
Outdated
@@ -22,6 +25,11 @@ set_info_command(CLI::App* subcom, mamba::Configuration& config) | |||
init_info_parser(subcom, config); | |||
static bool print_licenses; | |||
|
|||
auto& base = config.insert( | |||
Configurable("base", false).group("cli").description("Display base environment path.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using this if this is possible?
Configurable("base", false).group("cli").description("Display base environment path.") | |
mamba::Configurable("base", false).group("cli").description("Display base environment path.") |
Co-authored-by: Klaim <[email protected]>
Signed-off-by: Julien Jerphanion <[email protected]> Co-authored-by: Johan Mabille <[email protected]> Co-authored-by: Hind Montassif <[email protected]>
…mamba-org#3792) Signed-off-by: Julien Jerphanion <[email protected]>
Signed-off-by: Julien Jerphanion <[email protected]>
…rg#3788) Signed-off-by: Julien Jerphanion <[email protected]>
libmamba/src/api/info.cpp
Outdated
std::cout << ctx.prefix_params.root_prefix.string() << std::endl; | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually part of my previous comment can be addressed: can you early return on the first case so that the block from line 99 to line 193 can keep the same level of indentation?
libmamba/src/api/info.cpp
Outdated
namespace detail | ||
{ | ||
struct list_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was a bad copy/paste?
struct list_options | |
struct info_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I just realized that this is using snake case (as in list_options
) but we are rather using camel case in mamba code base (RepoqueryOptions
, ContextOptions
, etc). So for consistency, I would say to change to ListOptions
and InfoOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted!
{ | ||
assert(&ctx == &config.context()); | ||
|
||
if (options.base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also handle the --json
case.
if base_flag == "--base": | ||
assert all(f"{i} :" not in infos for i in items) | ||
base_environment_path = infos.strip() | ||
assert os.path.exists(base_environment_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add a check for the base_environment_path
being tmp_root_prefix
?
@@ -78,3 +78,40 @@ def test_not_env(tmp_home, tmp_root_prefix, prefix_selection, existing_prefix): | |||
assert f"env location : {location}" in infos | |||
assert f"user config files : {tmp_home / '.mambarc'}" in infos | |||
assert f"base environment : {tmp_root_prefix}" in infos | |||
|
|||
|
|||
@pytest.mark.parametrize("base_flag", ["", "--base"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add --json
case.
libmamba/src/api/info.cpp
Outdated
|
||
if (options.base) | ||
{ | ||
if (ctx.output_params.json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, after looking at the original code, we shouldn't use this condition here (and no cout
either).
We are using info_json_print
for json case, and info_pretty_print
for regular output where they internally handle the previous condition.
We should modify items
depending on the base
flag instead.
else: | ||
items += ["base environment"] | ||
if json_flag == "--json": | ||
assert all(i in infos.keys() for i in items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This tests that items
is a subset of infos.keys()
but I guess this is sufficient
This comment also applies elsewhere.
@@ -20,7 +20,7 @@ namespace mamba | |||
|
|||
namespace detail | |||
{ | |||
struct list_options | |||
struct ListOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the current *_options
structs should be PascalCase-named.
Adds one of the missing sub-command #3535