-
Notifications
You must be signed in to change notification settings - Fork 379
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
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?
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()); |
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.
Can mamba info --base
be tested?
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 have no idea how to test it. Open to suggestions!
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 do you think of testing that the usual information is not present and that an existing path is output?
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 <Klaim@users.noreply.github.com>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz> Co-authored-by: Johan Mabille <johan.mabille@gmail.com> Co-authored-by: Hind Montassif <hind.montassif@gmail.com>
…mamba-org#3792) Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
…rg#3788) Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
namespace detail | ||
{ | ||
struct list_options | ||
{ | ||
bool 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.
bool base; | |
bool base = false; |
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?
"platform", | ||
] | ||
if base_flag == "--base": | ||
print(infos) |
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.
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) |
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.
assert all(i in infos for i in items) | |
assert all(f"{i} :" in infos for i in items) |
assert all(f"{i} :" not in infos for i in items) | ||
assert os.path.exists(infos.strip()) |
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.
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) |
def test_base_subcommand(tmp_home, tmp_root_prefix, prefix_selection, base_flag): | ||
os.environ["CONDA_PREFIX"] = str(tmp_root_prefix) |
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.
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.
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.
Adds one of the missing sub-command #3535