mirror of https://github.com/mamba-org/mamba.git
fix: Return JSON on environment creation dry run (#3627)
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
This commit is contained in:
parent
fcb007a981
commit
b163ce9027
|
@ -4,6 +4,8 @@
|
|||
//
|
||||
// The full license is in the file LICENSE, distributed with this software.
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "mamba/api/configuration.hpp"
|
||||
#include "mamba/api/create.hpp"
|
||||
#include "mamba/api/install.hpp"
|
||||
|
@ -29,6 +31,7 @@ namespace mamba
|
|||
|
||||
auto& create_specs = config.at("specs").value<std::vector<std::string>>();
|
||||
auto& use_explicit = config.at("explicit_install").value<bool>();
|
||||
auto& json_format = config.at("json").get_cli_config<bool>();
|
||||
|
||||
auto channel_context = ChannelContext::make_conda_compatible(ctx);
|
||||
|
||||
|
@ -78,6 +81,21 @@ namespace mamba
|
|||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (create_specs.empty() && json_format)
|
||||
{
|
||||
// Just print the JSON
|
||||
nlohmann::json output;
|
||||
output["actions"]["FETCH"] = nlohmann::json::array();
|
||||
output["actions"]["PREFIX"] = ctx.prefix_params.target_prefix;
|
||||
output["dry_run"] = true;
|
||||
output["prefix"] = ctx.prefix_params.target_prefix;
|
||||
output["success"] = true;
|
||||
std::cout << output.dump(2) << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx.env_lockfile)
|
||||
{
|
||||
|
|
|
@ -1343,3 +1343,18 @@ def test_parsable_env_history_with_metadata(tmp_home, tmp_root_prefix, tmp_path)
|
|||
|
||||
# Must not hang
|
||||
helpers.umamba_list("-p", env_prefix, "--json")
|
||||
|
||||
|
||||
def test_create_dry_run_json(tmp_path):
|
||||
# Non-regression test for https://github.com/mamba-org/mamba/issues/3583
|
||||
env_prefix = tmp_path / "env-create_dry_run_json"
|
||||
res = helpers.create("-p", env_prefix, "--dry-run", "--json")
|
||||
|
||||
expected_output = {
|
||||
"actions": {"FETCH": [], "PREFIX": str(env_prefix)},
|
||||
"dry_run": True,
|
||||
"prefix": str(env_prefix),
|
||||
"success": True,
|
||||
}
|
||||
|
||||
assert res == expected_output
|
||||
|
|
Loading…
Reference in New Issue