add global job function

This commit is contained in:
Wolf Vollprecht 2022-01-24 15:37:38 +01:00
parent 4edf58be6f
commit 7c71c34887
8 changed files with 48 additions and 20 deletions

View File

@ -44,6 +44,7 @@ namespace mamba
MSolver(MSolver&&) = delete;
MSolver& operator=(MSolver&&) = delete;
void add_global_job(int job_flag);
void add_jobs(const std::vector<std::string>& jobs, int job_flag);
void add_constraint(const std::string& job);
void add_pin(const std::string& pin);

View File

@ -72,7 +72,7 @@ namespace mamba
solver_flag |= SOLVER_CLEANDEPS;
}
solver.add_jobs(keep_specs, SOLVER_USERINSTALLED);
solver.add_jobs({}, solver_flag);
solver.add_global_job(solver_flag);
}
else
{

View File

@ -52,6 +52,11 @@ namespace mamba
return false;
}
void MSolver::add_global_job(int job_flag)
{
queue_push2(&m_jobs, job_flag, 0);
}
void MSolver::add_channel_specific_job(const MatchSpec& ms, int job_flag)
{
Pool* pool = m_pool;
@ -137,11 +142,6 @@ namespace mamba
void MSolver::add_jobs(const std::vector<std::string>& jobs, int job_flag)
{
if (jobs.empty())
{
queue_push2(&m_jobs, job_flag, 0);
return;
}
for (const auto& job : jobs)
{
MatchSpec ms(job);

View File

@ -97,6 +97,7 @@ PYBIND11_MODULE(bindings, m)
.def(py::init<MPool&, std::vector<std::pair<int, int>>>())
.def(py::init<MPool&, std::vector<std::pair<int, int>>, const PrefixData*>())
.def("add_jobs", &MSolver::add_jobs)
.def("add_global_job", &MSolver::add_global_job)
.def("add_constraint", &MSolver::add_constraint)
.def("add_pin", &MSolver::add_pin)
.def("set_flags", &MSolver::set_flags)

View File

@ -123,10 +123,12 @@ def mamba_install(prefix, specs, args, env, dry_run=False, *_, **kwargs):
print(f"\n Pinned packages:\n\n{pinned_specs_info}\n")
install_specs = [s for s in specs if MatchSpec(s).name not in installed_names]
solver.add_jobs(install_specs, api.SOLVER_INSTALL)
if install_specs:
solver.add_jobs(install_specs, api.SOLVER_INSTALL)
update_specs = [s for s in specs if MatchSpec(s).name in installed_names]
solver.add_jobs(update_specs, api.SOLVER_UPDATE)
if update_specs:
solver.add_jobs(update_specs, api.SOLVER_UPDATE)
success = solver.solve()
if not success:

View File

@ -61,6 +61,15 @@ main(int argc, char** argv)
return 0;
}
std::stringstream full_command;
for (int i = 0; i < argc; ++i)
{
full_command << utf8argv[i];
if (i < argc - 1)
full_command << " ";
}
ctx.current_command = full_command.str();
try
{
CLI11_PARSE(app, argc, utf8argv);

View File

@ -25,7 +25,7 @@ set_update_command(CLI::App* subcom)
subcom->add_flag("--prune,!--no-prune", prune, "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->add_flag("-a,--all", update_all, "Update all packages in the environment");
subcom->callback([&]() { update(update_all, prune); });
}

View File

@ -17,8 +17,8 @@ class TestUpdate:
env_name = random_string()
root_prefix = os.path.expanduser(os.path.join("~", "tmproot" + random_string()))
prefix = os.path.join(root_prefix, "envs", env_name)
old_version = "0.18.3"
medium_old_version = "0.20"
old_version = "0.21.10"
medium_old_version = "0.22"
@staticmethod
@pytest.fixture(scope="class")
@ -58,11 +58,6 @@ class TestUpdate:
return
def test_constrained_update(self, env_created):
print(Path(TestUpdate.root_prefix).exists())
print(Path(TestUpdate.prefix).exists())
print(os.environ["MAMBA_ROOT_PREFIX"])
print(os.environ["CONDA_PREFIX"])
update_res = update("xtensor<=" + self.medium_old_version, "--json")
xtensor_link = [
l for l in update_res["actions"]["LINK"] if l["name"] == "xtensor"
@ -80,10 +75,6 @@ class TestUpdate:
assert xtensor_link["build_number"] == 0
def test_classic_spec(self, env_created):
print(Path(TestUpdate.root_prefix).exists())
print(Path(TestUpdate.prefix).exists())
print(os.environ["MAMBA_ROOT_PREFIX"])
print(os.environ["CONDA_PREFIX"])
update_res = update("xtensor", "--json")
xtensor_link = [
@ -106,6 +97,30 @@ class TestUpdate:
assert update_res["success"] == True
assert "action" not in update_res
def test_update_all(self, env_created):
update_res = update("--all", "--json")
xtensor_link = [
l for l in update_res["actions"]["LINK"] if l["name"] == "xtensor"
][0]
assert TestUpdate.old_version != xtensor_link["version"]
if dry_run_tests == DryRun.OFF:
pkg = get_concrete_pkg(update_res, "xtensor")
pkg_info = get_concrete_pkg_info(get_env(TestUpdate.env_name), pkg)
version = pkg_info["version"]
assert TestUpdate.old_version != version
with open(Path(self.prefix) / "conda-meta" / "history") as h:
history = h.readlines()
print("".join(history))
for el in reversed(history):
x = el.strip()
if x.startswith(">=="):
break
assert not x.startswith("update specs:")
@pytest.mark.parametrize(
"alias",
[