From e2de9db4101b9be451e8b3c2ef07eba641de0cf0 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 20 Dec 2023 18:46:01 +0530 Subject: [PATCH] Fix canonical name for local channels in 1.x (#3056) * 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 --- .github/workflows/unix.yml | 1 + libmamba/include/mamba/core/context.hpp | 5 +++++ libmamba/src/core/channel.cpp | 9 ++------- libmamba/src/core/context.cpp | 19 +++++++++++++++++++ libmambapy/libmambapy/__init__.pyi | 8 ++++++++ libmambapy/src/main.cpp | 5 +++++ 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/.github/workflows/unix.yml b/.github/workflows/unix.yml index f79f1ae485..72da62595b 100644 --- a/.github/workflows/unix.yml +++ b/.github/workflows/unix.yml @@ -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 diff --git a/libmamba/include/mamba/core/context.hpp b/libmamba/include/mamba/core/context.hpp index 79b7473db7..f145eedc93 100644 --- a/libmamba/include/mamba/core/context.hpp +++ b/libmamba/include/mamba/core/context.hpp @@ -248,6 +248,9 @@ namespace mamba void set_verbosity(int lvl); void set_log_level(log_level level); + std::vector get_conda_build_local_paths() const; + void set_conda_build_local_paths(const std::vector&); + protected: Context(); @@ -259,6 +262,8 @@ namespace mamba // Used internally bool on_ci = false; + std::vector conda_build_local_paths; + void load_authentication_info(); std::map m_authentication_info; bool m_authentication_infos_loaded = false; diff --git a/libmamba/src/core/channel.cpp b/libmamba/src/core/channel.cpp index 66cef72e3e..64642daf1c 100644 --- a/libmamba/src/core/channel.cpp +++ b/libmamba/src/core/channel.cpp @@ -736,12 +736,7 @@ namespace mamba m_custom_multichannels.emplace(DEFAULT_CHANNELS_NAME, std::move(default_names)); // Local channels - std::vector local_channels = { - Context::instance().prefix_params.target_prefix.string() + "/conda-bld", - Context::instance().prefix_params.root_prefix.string() + "/conda-bld", - "~/conda-bld" - }; - + std::vector local_channels = Context::instance().get_conda_build_local_paths(); std::vector local_names; local_names.reserve(local_channels.size()); for (const auto& p : local_channels) @@ -749,7 +744,7 @@ namespace mamba 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); diff --git a/libmamba/src/core/context.cpp b/libmamba/src/core/context.cpp index bc6254976f..5d1b65bca8 100644 --- a/libmamba/src/core/context.cpp +++ b/libmamba/src/core/context.cpp @@ -366,4 +366,23 @@ namespace mamba logger->dump_backtrace_no_guards(); } + void Context::set_conda_build_local_paths(const std::vector& vec) + { + conda_build_local_paths = vec; + } + + std::vector 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 diff --git a/libmambapy/libmambapy/__init__.pyi b/libmambapy/libmambapy/__init__.pyi index d4bd5a303f..e4b2678194 100644 --- a/libmambapy/libmambapy/__init__.pyi +++ b/libmambapy/libmambapy/__init__.pyi @@ -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 diff --git a/libmambapy/src/main.cpp b/libmambapy/src/main.cpp index c4a5afab3e..94d38ce522 100644 --- a/libmambapy/src/main.cpp +++ b/libmambapy/src/main.cpp @@ -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)