Skip to content

Commit

Permalink
Create empty base prefix with env update (#3519)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hind-M authored Oct 16, 2024
1 parent c329ca0 commit 3d71f57
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ namespace mamba
{
auto& ctx = config.context();

// `env update` case
if (update_params.env_update == EnvUpdate::Yes)
{
config.at("create_base").set_value(true);
}
config.at("use_target_prefix_fallback").set_value(true);
config.at("use_default_prefix_fallback").set_value(true);
config.at("use_root_prefix_fallback").set_value(true);
Expand Down
28 changes: 28 additions & 0 deletions micromamba/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,31 @@ def test_env_create_whitespace(tmp_home, tmp_root_prefix, tmp_path):
package["name"] == "scikit-learn" and Version(package["version"]) > Version("1.0.0")
for package in packages
)


env_yaml_content_to_update_empty_base = """
channels:
- conda-forge
dependencies:
- python
- xtensor
"""


@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
def test_env_update_empty_base(tmp_home, tmp_root_prefix, tmp_path):
env_prefix = tmp_path / "env-update-empty-base"

os.environ["MAMBA_ROOT_PREFIX"] = str(env_prefix)

env_file_yml = tmp_path / "test_env_empty_base.yaml"
env_file_yml.write_text(env_yaml_content_to_update_empty_base)

cmd = ["update", "-p", env_prefix, f"--file={env_file_yml}", "-y", "--json"]

res = helpers.run_env(*cmd)
assert res["success"]

packages = helpers.umamba_list("-p", env_prefix, "--json")
assert any(package["name"] == "xtensor" for package in packages)
assert any(package["name"] == "python" for package in packages)
27 changes: 27 additions & 0 deletions micromamba/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,3 +741,30 @@ def test_reinstall_with_new_version(tmp_home, tmp_root_prefix):

res = helpers.umamba_run("-n", env_name, "python", "-c", "import pip; print(pip.__version__)")
assert len(res)


env_yaml_content_to_install_empty_base = """
channels:
- conda-forge
dependencies:
- python
- xtensor
"""


def test_install_empty_base(tmp_home, tmp_root_prefix, tmp_path):
env_prefix = tmp_path / "env-install-empty-base"

os.environ["MAMBA_ROOT_PREFIX"] = str(env_prefix)

env_file_yml = tmp_path / "test_install_env_empty_base.yaml"
env_file_yml.write_text(env_yaml_content_to_install_empty_base)

cmd = ["-p", env_prefix, f"--file={env_file_yml}", "-y", "--json"]

res = helpers.install(*cmd)
assert res["success"]

packages = helpers.umamba_list("-p", env_prefix, "--json")
assert any(package["name"] == "xtensor" for package in packages)
assert any(package["name"] == "python" for package in packages)

0 comments on commit 3d71f57

Please sign in to comment.