Skip to content

Commit

Permalink
Fix canonical name for local channels in 1.x (#3056)
Browse files Browse the repository at this point in the history
* Fix canonical name for local channels in 1.x

* Add test

* Update local test

* Add conda_build_local_paths to Context to set conda-bld paths

* no need for configuration

* use a setter as well

* Update stub
  • Loading branch information
isuruf authored Dec 20, 2023
1 parent 4c012a6 commit e2de9db
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ jobs:
wget -P $CONDA_PREFIX/conda-bld/osx-64 https://anaconda.org/conda-forge/xtl/0.6.21/download/osx-64/xtl-0.6.21-h6516342_0.tar.bz2
fi
conda index $CONDA_PREFIX/conda-bld
mamba create -n l_o_cal_test local::xtensor -c conda-forge -y
mamba create -n l_o_cal_test xtensor -c local -c conda-forge -y
conda list -n l_o_cal_test
Expand Down
5 changes: 5 additions & 0 deletions libmamba/include/mamba/core/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ namespace mamba
void set_verbosity(int lvl);
void set_log_level(log_level level);

std::vector<std::string> get_conda_build_local_paths() const;
void set_conda_build_local_paths(const std::vector<std::string>&);

protected:

Context();
Expand All @@ -259,6 +262,8 @@ namespace mamba
// Used internally
bool on_ci = false;

std::vector<std::string> conda_build_local_paths;

void load_authentication_info();
std::map<std::string, AuthenticationInfo> m_authentication_info;
bool m_authentication_infos_loaded = false;
Expand Down
9 changes: 2 additions & 7 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,20 +736,15 @@ namespace mamba
m_custom_multichannels.emplace(DEFAULT_CHANNELS_NAME, std::move(default_names));

// Local channels
std::vector<std::string> local_channels = {
Context::instance().prefix_params.target_prefix.string() + "/conda-bld",
Context::instance().prefix_params.root_prefix.string() + "/conda-bld",
"~/conda-bld"
};

std::vector<std::string> local_channels = Context::instance().get_conda_build_local_paths();
std::vector<std::string> local_names;
local_names.reserve(local_channels.size());
for (const auto& p : local_channels)
{
if (fs::is_directory(p))
{
std::string url = util::path_to_url(p);
auto channel = make_simple_channel(m_channel_alias, url, "", LOCAL_CHANNELS_NAME);
auto channel = make_simple_channel(m_channel_alias, url, url, LOCAL_CHANNELS_NAME);
std::string name = channel.name();
auto res = m_custom_channels.emplace(std::move(name), std::move(channel));
local_names.push_back(res.first->first);
Expand Down
19 changes: 19 additions & 0 deletions libmamba/src/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,23 @@ namespace mamba
logger->dump_backtrace_no_guards();
}

void Context::set_conda_build_local_paths(const std::vector<std::string>& vec)
{
conda_build_local_paths = vec;
}

std::vector<std::string> Context::get_conda_build_local_paths() const
{
if (conda_build_local_paths.empty())
{
return { prefix_params.target_prefix.string() + "/conda-bld",
prefix_params.root_prefix.string() + "/conda-bld",
"~/conda-bld" };
}
else
{
return conda_build_local_paths;
}
}

} // namespace mamba
8 changes: 8 additions & 0 deletions libmambapy/libmambapy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,14 @@ class Context:
def channels(self, arg0: typing.List[str]) -> None:
pass
@property
def conda_build_local_paths(self) -> typing.List[str]:
"""
:type: typing.List[str]
"""
@conda_build_local_paths.setter
def conda_build_local_paths(self, arg1: typing.List[str]) -> None:
pass
@property
def conda_prefix(self) -> Path:
"""
:type: Path
Expand Down
5 changes: 5 additions & 0 deletions libmambapy/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ PYBIND11_MODULE(bindings, m)
.def_readwrite("custom_channels", &Context::custom_channels)
.def_readwrite("custom_multichannels", &Context::custom_multichannels)
.def_readwrite("default_channels", &Context::default_channels)
.def_property(
"conda_build_local_paths",
&Context::get_conda_build_local_paths,
&Context::set_conda_build_local_paths
)
.def_readwrite("channel_alias", &Context::channel_alias)
.def_readwrite("use_only_tar_bz2", &Context::use_only_tar_bz2)
.def_readwrite("channel_priority", &Context::channel_priority)
Expand Down

0 comments on commit e2de9db

Please sign in to comment.