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

feat: add base flag to info command #3779

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

SandrineP
Copy link
Collaborator

Adds one of the missing sub-command #3535

@SandrineP SandrineP added the release::enhancements For enhancements PRs or implementing features label Jan 30, 2025
@SandrineP SandrineP marked this pull request as ready for review January 30, 2025 16:19
Comment on lines 95 to 97
std::cout << ctx.prefix_params.root_prefix.string() << std::endl;
}
else
Copy link
Member

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.

Suggested change
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.

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member

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 Show resolved Hide resolved
Comment on lines 13 to 14
using namespace mamba;

Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Collaborator Author

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).

Copy link
Member

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.

@@ -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.")
Copy link
Member

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?

Suggested change
Configurable("base", false).group("cli").description("Display base environment path.")
mamba::Configurable("base", false).group("cli").description("Display base environment path.")

libmamba/src/api/info.cpp Outdated Show resolved Hide resolved
Comment on lines 95 to 97
std::cout << ctx.prefix_params.root_prefix.string() << std::endl;
}
else
Copy link
Member

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/tests/test_info.py Outdated Show resolved Hide resolved
micromamba/tests/test_info.py Outdated Show resolved Hide resolved
micromamba/tests/test_info.py Outdated Show resolved Hide resolved
micromamba/tests/test_info.py Outdated Show resolved Hide resolved
@jjerphan jjerphan added release::bug_fixes For PRs fixing bugs and removed release::enhancements For enhancements PRs or implementing features labels Feb 13, 2025
namespace detail
{
struct list_options
Copy link
Member

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?

Suggested change
struct list_options
struct info_options

Copy link
Member

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.

Copy link
Collaborator Author

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)
Copy link
Member

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)
Copy link
Member

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"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add --json case.


if (options.base)
{
if (ctx.output_params.json)
Copy link
Member

@Hind-M Hind-M Feb 18, 2025

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)
Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release::bug_fixes For PRs fixing bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants