mirror of https://github.com/mamba-org/mamba.git
add multichannels from specs (#1505)
This commit is contained in:
parent
2e50484c5e
commit
fefc8bbf53
|
@ -5,3 +5,4 @@ multi_line_output=3
|
||||||
include_trailing_comma=True
|
include_trailing_comma=True
|
||||||
force_grid_wrap=0
|
force_grid_wrap=0
|
||||||
use_parentheses=True
|
use_parentheses=True
|
||||||
|
profile=black
|
||||||
|
|
|
@ -491,11 +491,11 @@ namespace mamba
|
||||||
{
|
{
|
||||||
const Channel& channel = ca.second;
|
const Channel& channel = ca.second;
|
||||||
std::string test_url = join_url(channel.location(), channel.name());
|
std::string test_url = join_url(channel.location(), channel.name());
|
||||||
|
|
||||||
// original code splits with '/' and compares tokens
|
// original code splits with '/' and compares tokens
|
||||||
if (starts_with(url, test_url))
|
if (starts_with(url, test_url))
|
||||||
{
|
{
|
||||||
auto subname = std::string(strip(url.replace(0u, test_url.size(), ""), "/"));
|
auto subname = std::string(strip(url.replace(0u, test_url.size(), ""), "/"));
|
||||||
|
|
||||||
return channel_configuration(channel.location(),
|
return channel_configuration(channel.location(),
|
||||||
join_url(channel.name(), subname),
|
join_url(channel.name(), subname),
|
||||||
scheme,
|
scheme,
|
||||||
|
|
|
@ -63,11 +63,30 @@ namespace mamba
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool channel_match(Solvable* s, const std::string& channel)
|
inline bool channel_match(Solvable* s, const Channel& needle)
|
||||||
{
|
{
|
||||||
MRepo* mrepo = reinterpret_cast<MRepo*>(s->repo->appdata);
|
MRepo* mrepo = reinterpret_cast<MRepo*>(s->repo->appdata);
|
||||||
const Channel* chan = mrepo->channel();
|
const Channel* chan = mrepo->channel();
|
||||||
return chan && chan->name() == channel;
|
|
||||||
|
if (!chan)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ((*chan) == needle)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
auto& custom_multichannels = Context::instance().custom_multichannels;
|
||||||
|
auto x = custom_multichannels.find(needle.name());
|
||||||
|
if (x != custom_multichannels.end())
|
||||||
|
{
|
||||||
|
for (auto el : (x->second))
|
||||||
|
{
|
||||||
|
const Channel& inner = make_channel(el);
|
||||||
|
if ((*chan) == inner)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSolver::add_global_job(int job_flag)
|
void MSolver::add_global_job(int job_flag)
|
||||||
|
@ -84,9 +103,10 @@ namespace mamba
|
||||||
// conda_build_form does **NOT** contain the channel info
|
// conda_build_form does **NOT** contain the channel info
|
||||||
Id match = pool_conda_matchspec(pool, ms.conda_build_form().c_str());
|
Id match = pool_conda_matchspec(pool, ms.conda_build_form().c_str());
|
||||||
|
|
||||||
|
const Channel& c = make_channel(ms.channel);
|
||||||
for (Id* wp = pool_whatprovides_ptr(pool, match); *wp; wp++)
|
for (Id* wp = pool_whatprovides_ptr(pool, match); *wp; wp++)
|
||||||
{
|
{
|
||||||
if (channel_match(pool_id2solvable(pool, *wp), ms.channel))
|
if (channel_match(pool_id2solvable(pool, *wp), c))
|
||||||
{
|
{
|
||||||
queue_push(&selected_pkgs, *wp);
|
queue_push(&selected_pkgs, *wp);
|
||||||
}
|
}
|
||||||
|
@ -264,11 +284,13 @@ namespace mamba
|
||||||
Id match = pool_conda_matchspec(pool, ms.conda_build_form().c_str());
|
Id match = pool_conda_matchspec(pool, ms.conda_build_form().c_str());
|
||||||
|
|
||||||
std::set<Id> matching_solvables;
|
std::set<Id> matching_solvables;
|
||||||
|
const Channel& c = make_channel(ms.channel);
|
||||||
|
|
||||||
for (Id* wp = pool_whatprovides_ptr(pool, match); *wp; wp++)
|
for (Id* wp = pool_whatprovides_ptr(pool, match); *wp; wp++)
|
||||||
{
|
{
|
||||||
if (!ms.channel.empty())
|
if (!ms.channel.empty())
|
||||||
{
|
{
|
||||||
if (!channel_match(pool_id2solvable(pool, *wp), ms.channel))
|
if (!channel_match(pool_id2solvable(pool, *wp), c))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,6 +339,15 @@ namespace mamba
|
||||||
ChannelContext::instance().reset();
|
ChannelContext::instance().reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Channel, channel_name)
|
||||||
|
{
|
||||||
|
std::string value = "https://repo.mamba.pm/conda-forge";
|
||||||
|
const Channel& c = make_channel(value);
|
||||||
|
EXPECT_EQ(c.scheme(), "https");
|
||||||
|
EXPECT_EQ(c.location(), "repo.mamba.pm");
|
||||||
|
EXPECT_EQ(c.name(), "conda-forge");
|
||||||
|
EXPECT_EQ(c.platforms(), std::vector<std::string>({ platform, "noarch" }));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Channel, make_channel)
|
TEST(Channel, make_channel)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,6 +43,7 @@ from conda.gateways.disk.create import mkdir_p
|
||||||
from conda.gateways.disk.delete import delete_trash, path_is_clean, rm_rf
|
from conda.gateways.disk.delete import delete_trash, path_is_clean, rm_rf
|
||||||
from conda.gateways.disk.test import is_conda_environment
|
from conda.gateways.disk.test import is_conda_environment
|
||||||
from conda.misc import explicit, touch_nonadmin
|
from conda.misc import explicit, touch_nonadmin
|
||||||
|
from conda.models.channel import MultiChannel
|
||||||
from conda.models.match_spec import MatchSpec
|
from conda.models.match_spec import MatchSpec
|
||||||
|
|
||||||
import libmambapy as api
|
import libmambapy as api
|
||||||
|
@ -377,8 +378,11 @@ def install(args, parser, command="install"):
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
# CONDA TODO: correct handling for subdir isn't yet done
|
# CONDA TODO: correct handling for subdir isn't yet done
|
||||||
spec_channel = spec.get_exact_value("channel")
|
spec_channel = spec.get_exact_value("channel")
|
||||||
if spec_channel and spec_channel.base_url not in channels:
|
if spec_channel:
|
||||||
channels.append(spec_channel.base_url)
|
if isinstance(spec_channel, MultiChannel):
|
||||||
|
channels.append(spec_channel.name)
|
||||||
|
elif spec_channel.base_url not in channels:
|
||||||
|
channels.append(spec_channel.base_url)
|
||||||
|
|
||||||
index_args["channel_urls"] = channels
|
index_args["channel_urls"] = channels
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pytest
|
||||||
from utils import (
|
from utils import (
|
||||||
Environment,
|
Environment,
|
||||||
add_glibc_virtual_package,
|
add_glibc_virtual_package,
|
||||||
|
config_file,
|
||||||
copy_channels_osx,
|
copy_channels_osx,
|
||||||
platform_shells,
|
platform_shells,
|
||||||
run_mamba_conda,
|
run_mamba_conda,
|
||||||
|
@ -178,6 +179,33 @@ def test_empty_create():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
multichannel_config = {
|
||||||
|
"channels": ["conda-forge"],
|
||||||
|
"custom_multichannels": {"conda-forge2": ["conda-forge"]},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("config_file", [multichannel_config], indirect=["config_file"])
|
||||||
|
def test_multi_channels(config_file):
|
||||||
|
# we need to create a config file first
|
||||||
|
output = subprocess.check_output(
|
||||||
|
[
|
||||||
|
"mamba",
|
||||||
|
"create",
|
||||||
|
"-n",
|
||||||
|
"multichannels",
|
||||||
|
"conda-forge2::xtensor",
|
||||||
|
"--dry-run",
|
||||||
|
"--json",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
res = json.loads(output.decode())
|
||||||
|
for pkg in res["actions"]["FETCH"]:
|
||||||
|
assert pkg["channel"].startswith("https://conda.anaconda.org/conda-forge")
|
||||||
|
for pkg in res["actions"]["LINK"]:
|
||||||
|
assert pkg["base_url"] == "https://conda.anaconda.org/conda-forge"
|
||||||
|
|
||||||
|
|
||||||
def test_update_py():
|
def test_update_py():
|
||||||
# check updating a package when a newer version
|
# check updating a package when a newer version
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
|
|
@ -4,6 +4,10 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def get_lines(std_pipe):
|
def get_lines(std_pipe):
|
||||||
|
@ -133,6 +137,23 @@ def run_mamba_conda(channels, package):
|
||||||
run("mamba", channels, package)
|
run("mamba", channels, package)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def config_file(request):
|
||||||
|
file_loc = Path.home() / ".condarc"
|
||||||
|
old_config_file = None
|
||||||
|
if file_loc.exists():
|
||||||
|
old_config_file = file_loc.rename(Path.home() / ".condarc.bkup")
|
||||||
|
|
||||||
|
with open(file_loc, "w") as fo:
|
||||||
|
yaml.dump(request.param, fo)
|
||||||
|
|
||||||
|
yield file_loc
|
||||||
|
|
||||||
|
if old_config_file:
|
||||||
|
file_loc.unlink()
|
||||||
|
old_config_file.rename(file_loc)
|
||||||
|
|
||||||
|
|
||||||
def add_glibc_virtual_package():
|
def add_glibc_virtual_package():
|
||||||
version = get_glibc_version()
|
version = get_glibc_version()
|
||||||
here = os.path.dirname(os.path.abspath(__file__))
|
here = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
Loading…
Reference in New Issue