Skip to content

Commit

Permalink
fix: Activated environment name
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
  • Loading branch information
jjerphan committed Dec 9, 2024
1 parent 1785933 commit 0cd5a53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libmamba/src/core/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ namespace mamba
{
return "base";
}
// if ../miniconda3/envs/my_super_env, return `my_super_env`, else path
if (prefix.parent_path().stem() == "envs")
// if ../miniconda3/envs/my_super.env, return `my_super.env`, else path
if (prefix.parent_path().filename() == "envs")
{
return prefix.stem().string();
return prefix.filename().string();
}
else
{
Expand Down
15 changes: 15 additions & 0 deletions libmamba/tests/src/core/test_activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@ namespace mamba
// std::endl; std::cout << a.activate("/home/wolfv/miniconda3/", false) <<
// std::endl;
}

TEST_CASE("Activator::get_default_env")
{
ContextOptions opts;
Context ctx(opts);
ctx.prefix_params.root_prefix = "/home/user/miniforge";
PosixActivator a(ctx);
REQUIRE(a.get_default_env("/home/user/miniforge") == "base");
REQUIRE(a.get_default_env("/home/user/miniforge/envs/env") == "env");
REQUIRE(a.get_default_env("/home/user/miniforge/envs/an.env") == "an.env");
REQUIRE(a.get_default_env("/home/user/miniforge/envs/an-oth.er") == "an-oth.er");
REQUIRE(a.get_default_env("/opt/envs/yet.an-oth.er") == "yet.an-oth.er");
REQUIRE(a.get_default_env("/opt/envs.d/env") == "/opt/envs.d/env");
REQUIRE(a.get_default_env("/home/user/some/env") == "/home/user/some/env");
}
}
} // namespace mamba

0 comments on commit 0cd5a53

Please sign in to comment.