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 15 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?

auto& base = config.insert(
Configurable("base", false).group("cli").description("Display base environment path.")
);
subcom->add_flag("--base", base.get_cli_config<bool>(), base.description());
Copy link
Member

Choose a reason for hiding this comment

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

Can mamba info --base be tested?

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 have no idea how to test it. Open to suggestions!

Copy link
Member

Choose a reason for hiding this comment

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

What do you think of testing that the usual information is not present and that an existing path is output?

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

namespace detail
{
struct list_options
{
bool base;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool base;
bool base = false;

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?

"platform",
]
if base_flag == "--base":
print(infos)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(infos)

assert all(f"{i} :" not in infos for i in items)
assert os.path.exists(infos.strip())
else:
assert all(i in infos 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.

Suggested change
assert all(i in infos for i in items)
assert all(f"{i} :" in infos for i in items)

Comment on lines +114 to +115
assert all(f"{i} :" not in infos for i in items)
assert os.path.exists(infos.strip())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert all(f"{i} :" not in infos for i in items)
assert os.path.exists(infos.strip())
assert all(f"{i} :" not in infos for i in items)
base_environment_path = infos.strip()
assert os.path.exists(base_environment_path)

Comment on lines +85 to +86
def test_base_subcommand(tmp_home, tmp_root_prefix, prefix_selection, base_flag):
os.environ["CONDA_PREFIX"] = str(tmp_root_prefix)
Copy link
Member

Choose a reason for hiding this comment

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

pytest exposes a monkeypatch fixture which can be used to monkeypatch environment variable in the scope of a test. This is a bit safer and the intend is clearer.

Suggested change
def test_base_subcommand(tmp_home, tmp_root_prefix, prefix_selection, base_flag):
os.environ["CONDA_PREFIX"] = str(tmp_root_prefix)
def test_base_subcommand(tmp_home, tmp_root_prefix, prefix_selection, base_flag, monkey_patch):
monkeypatch.setenv("CONDA_PREFIX", str(tmp_root_prefix))

Not that this suggestion might not respect linters' formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release::enhancements For enhancements PRs or implementing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants