mirror of https://github.com/mamba-org/mamba.git
fix: Correct `mamba env export --json --from-history` (#3590)
This commit is contained in:
parent
e1bdc942af
commit
4535562cb8
|
@ -184,24 +184,25 @@ set_env_command(CLI::App* com, Configuration& config)
|
|||
std::stringstream dependencies;
|
||||
std::set<std::string> channels;
|
||||
|
||||
for (auto it = versions_map.begin(); it != versions_map.end(); ++it)
|
||||
bool first_dependency_printed = false;
|
||||
for (const auto& [k, v] : versions_map)
|
||||
{
|
||||
auto k = it->first;
|
||||
auto v = it->second;
|
||||
if (from_history && requested_specs_map.find(k) == requested_specs_map.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dependencies << (first_dependency_printed ? ",\n" : "") << " \"";
|
||||
first_dependency_printed = true;
|
||||
|
||||
auto chans = channel_context.make_channel(v.channel);
|
||||
|
||||
if (from_history)
|
||||
{
|
||||
dependencies << " \"" << requested_specs_map[k].str() << "\",\n";
|
||||
dependencies << requested_specs_map[k].str() << "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencies << " \"";
|
||||
if (channel_subdir)
|
||||
{
|
||||
dependencies
|
||||
|
@ -218,8 +219,7 @@ set_env_command(CLI::App* com, Configuration& config)
|
|||
{
|
||||
dependencies << "[md5=" << v.md5 << "]";
|
||||
}
|
||||
auto last_dep = std::next(it) == versions_map.end();
|
||||
dependencies << "\"" << (last_dep ? "" : ",") << "\n";
|
||||
dependencies << "\"";
|
||||
}
|
||||
|
||||
for (const auto& chan : chans)
|
||||
|
@ -227,6 +227,8 @@ set_env_command(CLI::App* com, Configuration& config)
|
|||
channels.insert(chan.display_name());
|
||||
}
|
||||
}
|
||||
dependencies << (first_dependency_printed ? "\n" : "");
|
||||
|
||||
std::cout << "{\n";
|
||||
|
||||
if (!channels.empty())
|
||||
|
|
|
@ -70,6 +70,20 @@ def export_env():
|
|||
return env_name
|
||||
|
||||
|
||||
@pytest.mark.parametrize("json_flag", [None, "--json"])
|
||||
def test_env_export_from_history(json_flag, export_env):
|
||||
flags = filter(None, [json_flag])
|
||||
output = helpers.run_env("export", "-n", export_env, "--from-history", *flags)
|
||||
|
||||
# json is already parsed
|
||||
ret = output if json_flag else yaml.safe_load(output)
|
||||
assert ret["name"] == export_env
|
||||
assert export_env in ret["prefix"]
|
||||
assert set(ret["channels"]) == {"conda-forge"}
|
||||
micromamba_spec_prefix = "micromamba=0.24.0"
|
||||
assert [micromamba_spec_prefix] == ret["dependencies"]
|
||||
|
||||
|
||||
@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"])
|
||||
|
|
Loading…
Reference in New Issue