Skip to content

Commit

Permalink
Filter pins out of solver output
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Aug 23, 2023
1 parent 3a1fb80 commit 5bee57a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libmamba/src/core/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,18 @@ namespace mamba
// Solvable need to provide itself
cons_solv.add_self_provide();

// Even if we lock it, libsolv may still try to remove it with
// `SOLVER_FLAG_ALLOW_UNINSTALL`, so we flag it as not a real package to filter it out in
// the transaction
cons_solv.set_artificial(true);

// Necessary for attributes to be properly stored
installed->internalize();

// Lock the dummy solvable so that it stays install.
// Force verify the dummy solvable dependencies, as this is not the default for
// installed packages.
return add_jobs({ cons_solv_name }, SOLVER_LOCK & SOLVER_VERIFY);
return add_jobs({ cons_solv_name }, SOLVER_LOCK | SOLVER_VERIFY);
}

void MSolver::add_pins(const std::vector<std::string>& pins)
Expand Down
12 changes: 12 additions & 0 deletions libmamba/src/core/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ namespace mamba
[&](const solv::SolvableId id)
{
auto pkginfo = get_pkginfo(id);

// Artificial packages are packages that were added to implement a feature
// (e.g. a pin) but do not represent a Conda package.
// They can appear in the transaction depending on libsolv flags.
// We use this attribute to filter them out.
if (const auto solv = pool.pool().get_solvable(id);
solv.has_value() && solv->artificial())
{
LOG_DEBUG << "Solution: Remove artificial " << pkginfo.str();
return;
}

// keep_only ? specs.contains(...) : !specs.contains(...);
// TODO ideally we should use Matchspecs::contains(pkginfo)
if (keep_only == specs.contains(pkginfo.name))
Expand Down

0 comments on commit 5bee57a

Please sign in to comment.