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

fix: Export 'channels' as part of environments' export #3587

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 6 additions & 10 deletions micromamba/src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,14 @@ set_env_command(CLI::App* com, Configuration& config)
}
std::cout << "{\n";

if (!channels.empty())
std::cout << " \"channels\": [\n";
for (auto channel_it = channels.begin(); channel_it != channels.end(); ++channel_it)
{
std::cout << " \"channels\": [\n";
for (auto channel_it = channels.begin(); channel_it != channels.end();
++channel_it)
{
auto last_channel = std::next(channel_it) == channels.end();
std::cout << " \"" << *channel_it << "\"" << (last_channel ? "" : ",")
<< "\n";
}
std::cout << " ],\n";
auto last_channel = std::next(channel_it) == channels.end();
std::cout << " \"" << *channel_it << "\"" << (last_channel ? "" : ",") << "\n";
}
std::cout << " ],\n";

std::cout << " \"dependencies\": [\n" << dependencies.str() << " ],\n";

std::cout << " \"name\": \"" << get_env_name(ctx, ctx.prefix_params.target_prefix)
Expand Down
30 changes: 23 additions & 7 deletions micromamba/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,47 @@ def export_env():
return env_name


@pytest.fixture(scope="module")
def empty_env():
env_name = "env-empty"
helpers.create("-n", env_name)
return env_name


@pytest.mark.parametrize("json_flag", [None, "--json"])
def test_empty_env_export(json_flag, empty_env):
flags = filter(None, [json_flag])
output = helpers.run_env("export", "-n", empty_env, *flags)

# json is already parsed
ret = output if json_flag else yaml.safe_load(output)
assert ret["name"] == empty_env
assert "env-empty" in ret["prefix"]
assert not ret["channels"]


@pytest.mark.parametrize("channel_subdir_flag", [None, "--channel-subdir"])
@pytest.mark.parametrize("md5_flag", [None, "--md5", "--no-md5"])
@pytest.mark.parametrize("explicit_flag", [None, "--explicit"])
@pytest.mark.parametrize("no_build_flag", [None, "--no-build", "--no-builds"])
@pytest.mark.parametrize("json_flag", [None, "--json"])
def test_env_export(
export_env, json_flag, no_build_flag, explicit_flag, md5_flag, channel_subdir_flag
channel_subdir_flag, md5_flag, explicit_flag, no_build_flag, json_flag, export_env
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the order it is mentioned above, it's better to have the same order everywhere

):
if explicit_flag and json_flag:
# `--explicit` has precedence over `--json`, which is tested bellow.
# But we need to omit here to avoid `helpers.run_env` to parse the output as JSON and fail.
json_flag = None

flags = filter(None, [no_build_flag, json_flag, explicit_flag, md5_flag, channel_subdir_flag])
flags = filter(None, [channel_subdir_flag, md5_flag, explicit_flag, no_build_flag, json_flag])
output = helpers.run_env("export", "-n", export_env, *flags)
if explicit_flag:
assert "/micromamba-0.24.0-0." in output
if md5_flag != "--no-md5":
assert re.search("#[a-f0-9]{32}$", output.replace("\r", ""))
else:
if json_flag:
# Already parsed
ret = output
else:
ret = yaml.safe_load(output)
# json is already parsed
ret = output if json_flag else yaml.safe_load(output)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is quite easy to read as a one-line

assert ret["name"] == export_env
assert "env-create-export" in ret["prefix"]
assert set(ret["channels"]) == {"conda-forge"}
Expand Down