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: Handle environment with empty or absent dependencies #3657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 10 additions & 4 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ namespace mamba
}
else
{
LOG_ERROR << "No 'dependencies' specified in YAML spec file '" << file.string()
<< "'";
throw std::runtime_error("Invalid spec file. Aborting.");
// Empty of absent `dependencies` key
deps = YAML::Node(YAML::NodeType::Null);
}
YAML::Node final_deps;

Expand Down Expand Up @@ -165,7 +164,14 @@ namespace mamba
std::vector<std::string> dependencies;
try
{
dependencies = final_deps.as<std::vector<std::string>>();
if (final_deps.IsNull())
{
dependencies = {};
}
else
{
dependencies = final_deps.as<std::vector<std::string>>();
}
}
catch (const YAML::Exception& e)
{
Expand Down
39 changes: 39 additions & 0 deletions micromamba/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,3 +1357,42 @@ def test_create_dry_run_json(tmp_path):
}

assert res == expected_output


env_spec_empty_dependencies = """
name: empty_dependencies
channels:
- conda-forge
dependencies: []
"""

env_spec_absent_dependencies = """
name: absent_dependencies
channels:
- conda-forge
"""


def test_create_empty_or_absent_dependencies(tmp_path):
env_prefix = tmp_path / "env-empty_dependencies"
# Write the env specification to a file and pass it to the create command

with open(tmp_path / "env_spec_empty_dependencies.yaml", "w") as f:
f.write(env_spec_empty_dependencies)

with open(tmp_path / "env_spec_absent_dependencies.yaml", "w") as f:
f.write(env_spec_absent_dependencies)

# Create the environment with empty dependencies, check that it is created successfully
# and that no packages are installed in the environment
res = helpers.create(
"-p", env_prefix, "-f", tmp_path / "env_spec_empty_dependencies.yaml", "--json"
)
assert res["success"]

# Create the environment with absent dependencies, check that it is created successfully
# and that no packages are installed in the environment
res = helpers.create(
"-p", env_prefix, "-f", tmp_path / "env_spec_absent_dependencies.yaml", "--json"
)
assert res["success"]
Loading