Make `self-update` a command for micromamba only (#3906)

Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Klaim <Klaim@users.noreply.github.com>
This commit is contained in:
Julien Jerphanion 2025-04-28 16:05:20 +02:00 committed by GitHub
parent 3364c8e2d7
commit f182c7bd3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 26 deletions

View File

@ -102,6 +102,7 @@ endif()
if(BUILD_STATIC)
message(STATUS "Adding executable micromamba")
mambaexe_create_target(micromamba STATIC micromamba)
target_compile_definitions(micromamba PRIVATE BUILDING_MICROMAMBA)
endif()
# Installation

View File

@ -51,8 +51,10 @@ set_umamba_command(CLI::App* com, mamba::Configuration& config)
CLI::App* update_subcom = com->add_subcommand("update", "Update packages in active environment");
set_update_command(update_subcom, config);
#ifdef BUILDING_MICROMAMBA
CLI::App* self_update_subcom = com->add_subcommand("self-update", "Update micromamba");
set_self_update_command(self_update_subcom, config);
#endif
CLI::App* repoquery_subcom = com->add_subcommand(
"repoquery",

View File

@ -52,8 +52,10 @@ set_umamba_command(CLI::App* com, mamba::Configuration& config);
void
set_update_command(CLI::App* subcom, mamba::Configuration& config);
#ifdef BUILDING_MICROMAMBA
void
set_self_update_command(CLI::App* subcom, mamba::Configuration& config);
#endif
void
set_repoquery_search_command(CLI::App* subcmd, mamba::Configuration& config);

View File

@ -27,6 +27,33 @@
using namespace mamba; // NOLINT(build/namespaces)
void
set_update_command(CLI::App* subcom, Configuration& config)
{
init_install_options(subcom, config);
static bool prune_deps = true;
static bool update_all = false;
subcom->add_flag("--prune-deps,!--no-prune-deps", prune_deps, "Prune dependencies (default)");
subcom->get_option("specs")->description("Specs to update in the environment");
subcom->add_flag("-a,--all", update_all, "Update all packages in the environment");
subcom->callback(
[&]
{
auto update_params = UpdateParams{
update_all ? UpdateAll::Yes : UpdateAll::No,
prune_deps ? PruneDeps::Yes : PruneDeps::No,
EnvUpdate::No,
RemoveNotSpecified::No,
};
return update(config, update_params);
}
);
}
#ifdef BUILDING_MICROMAMBA
namespace
{
auto database_has_package(solver::libsolv::Database& database, specs::MatchSpec spec) -> bool
@ -197,32 +224,6 @@ update_self(Configuration& config, const std::optional<std::string>& version)
return ec ? ec.value() : status;
}
void
set_update_command(CLI::App* subcom, Configuration& config)
{
init_install_options(subcom, config);
static bool prune_deps = true;
static bool update_all = false;
subcom->add_flag("--prune-deps,!--no-prune-deps", prune_deps, "Prune dependencies (default)");
subcom->get_option("specs")->description("Specs to update in the environment");
subcom->add_flag("-a,--all", update_all, "Update all packages in the environment");
subcom->callback(
[&]
{
auto update_params = UpdateParams{
update_all ? UpdateAll::Yes : UpdateAll::No,
prune_deps ? PruneDeps::Yes : PruneDeps::No,
EnvUpdate::No,
RemoveNotSpecified::No,
};
return update(config, update_params);
}
);
}
void
set_self_update_command(CLI::App* subcom, Configuration& config)
{
@ -234,3 +235,4 @@ set_self_update_command(CLI::App* subcom, Configuration& config)
subcom->callback([&] { return update_self(config, version); });
}
#endif

View File

@ -901,6 +901,10 @@ def tmp_umamba():
os.chmod(mamba_exe, 0o755)
@pytest.mark.skipif(
"micromamba" not in Path(helpers.get_umamba()).stem,
reason="micromamba-only test",
)
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
@pytest.mark.parametrize("interpreter", get_self_update_interpreters())
def test_self_update(