unify channels of installed and removed packages written in history (#3892)

This commit is contained in:
Sandrine Pataut 2025-05-28 09:47:33 +02:00 committed by GitHub
parent aeb417f617
commit fb54852b92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View File

@ -379,8 +379,27 @@ namespace mamba
return true;
}
TransactionRollback rollback;
// Channels coming from the repodata (packages to install) don't have the same channel
// format than packages coming from the prefix (packages to remove). We set all the channels
// to be URL like (i.e. explicit). Below is a loop to fix the channel of the linked
// packages (fix applied to the unlinked packages to avoid potential bugs). Ideally, this
// should be normalised when reading the data.
const auto fix_channel = [&](specs::PackageInfo& pkg)
{
auto unresolved_pkg_channel = mamba::specs::UnresolvedChannel::parse(pkg.channel).value();
auto pkg_channel = mamba::specs::Channel::resolve(
unresolved_pkg_channel,
channel_context.params()
)
.value();
auto channel_url = pkg_channel[0].platform_url(pkg.platform).str();
pkg.channel = channel_url;
};
for_each_to_install(m_solution.actions, fix_channel);
for_each_to_remove(m_solution.actions, fix_channel);
for_each_to_omit(m_solution.actions, fix_channel);
TransactionRollback rollback;
TransactionContext transaction_context(ctx.transaction_params(), m_py_versions, m_requested_specs);
const auto link = [&](const specs::PackageInfo& pkg)

View File

@ -0,0 +1,20 @@
import re
# Need to import everything to get fixtures
from .helpers import * # noqa: F403
from . import helpers
def test_history(tmp_home, tmp_root_prefix):
env_name = "myenv"
helpers.create("-n", env_name, "python=3.8")
helpers.install("-n", env_name, "xtl")
helpers.uninstall("-n", env_name, "xtl")
effective_prefix = tmp_root_prefix / "envs" / env_name
history_path = effective_prefix / "conda-meta" / "history"
assert history_path.exists()
with open(history_path) as f:
history = f.read()
assert len(re.findall(r"\+https:\/\/conda.anaconda.org\/conda-forge\/.+::xtl", history)) > 0
assert len(re.findall(r"-https:\/\/conda.anaconda.org\/conda-forge\/.+::xtl", history)) > 0