From 3e4a839fc507a6ffba6ac1925ca030ad8cac36a1 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Wed, 2 Mar 2022 15:23:18 +0100 Subject: [PATCH] Remove need to manually call SubdirData.load() (#1554) --- libmamba/include/mamba/core/subdirdata.hpp | 10 ++-------- libmamba/src/api/channel_loader.cpp | 1 - libmamba/src/core/subdirdata.cpp | 3 ++- libmamba/tests/test_cpp.cpp | 6 ++++++ libmamba/tests/test_transfer.cpp | 2 -- libmambapy/src/main.cpp | 1 - mamba/mamba/utils.py | 4 +--- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/libmamba/include/mamba/core/subdirdata.hpp b/libmamba/include/mamba/core/subdirdata.hpp index a6ddc0c4c..fdad644b2 100644 --- a/libmamba/include/mamba/core/subdirdata.hpp +++ b/libmamba/include/mamba/core/subdirdata.hpp @@ -31,12 +31,6 @@ namespace decompress namespace mamba { - namespace detail - { - // read the header that contains json like {"_mod": "...", ...} - nlohmann::json read_mod_and_etag(const fs::path& file); - } - /** * Represents a channel subdirectory (i.e. a platform) * packages index. Handles downloading of the index @@ -54,8 +48,7 @@ namespace mamba // TODO return seconds as double fs::file_time_type::duration check_cache(const fs::path& cache_file, const fs::file_time_type::clock::time_point& ref); - bool load(); - bool loaded(); + bool loaded() const; bool forbid_cache(); void clear_cache(); @@ -69,6 +62,7 @@ namespace mamba MRepo& create_repo(MPool& pool); private: + bool load(); bool decompress(); void create_target(nlohmann::json& mod_etag); std::size_t get_cache_control_max_age(const std::string& val); diff --git a/libmamba/src/api/channel_loader.cpp b/libmamba/src/api/channel_loader.cpp index 9aa5b9830..47898fb2c 100644 --- a/libmamba/src/api/channel_loader.cpp +++ b/libmamba/src/api/channel_loader.cpp @@ -56,7 +56,6 @@ namespace mamba { auto sdir = std::make_shared(*channel, platform, url, package_caches); - sdir->load(); multi_dl.add(sdir->target()); subdirs.push_back(sdir); if (ctx.channel_priority == ChannelPriority::kDisabled) diff --git a/libmamba/src/core/subdirdata.cpp b/libmamba/src/core/subdirdata.cpp index 47ad1e838..99ddff174 100644 --- a/libmamba/src/core/subdirdata.cpp +++ b/libmamba/src/core/subdirdata.cpp @@ -176,6 +176,7 @@ namespace mamba { m_json_fn = cache_fn_url(m_repodata_url); m_solv_fn = m_json_fn.substr(0, m_json_fn.size() - 4) + "solv"; + load(); } fs::file_time_type::duration MSubdirData::check_cache( @@ -194,7 +195,7 @@ namespace mamba } } - bool MSubdirData::loaded() + bool MSubdirData::loaded() const { return m_loaded; } diff --git a/libmamba/tests/test_cpp.cpp b/libmamba/tests/test_cpp.cpp index b23753074..b6d318d2e 100644 --- a/libmamba/tests/test_cpp.cpp +++ b/libmamba/tests/test_cpp.cpp @@ -503,6 +503,12 @@ namespace mamba EXPECT_FALSE(lexists("emptytestfile")); } + namespace detail + { + // read the header that contains json like {"_mod": "...", ...} + nlohmann::json read_mod_and_etag(const fs::path& file); + } + TEST(subdirdata, parse_mod_etag) { fs::path cache_folder = fs::path("repodata_json_cache"); diff --git a/libmamba/tests/test_transfer.cpp b/libmamba/tests/test_transfer.cpp index 1d2fb228b..02389b4ec 100644 --- a/libmamba/tests/test_transfer.cpp +++ b/libmamba/tests/test_transfer.cpp @@ -14,7 +14,6 @@ namespace mamba mamba::MultiDownloadTarget multi_dl; mamba::MultiPackageCache pkg_cache({ "/tmp/" }); mamba::MSubdirData cf(c, "linux-64", "file:///nonexistent/repodata.json", pkg_cache); - cf.load(); multi_dl.add(cf.target()); // file:// url should not retry @@ -30,7 +29,6 @@ namespace mamba mamba::MultiDownloadTarget multi_dl; mamba::MultiPackageCache pkg_cache({ "/tmp/" }); mamba::MSubdirData cf(c, "noarch", "file:///nonexistent/repodata.json", pkg_cache); - cf.load(); multi_dl.add(cf.target()); EXPECT_THROW(multi_dl.download(MAMBA_DOWNLOAD_FAILFAST), std::runtime_error); } diff --git a/libmambapy/src/main.cpp b/libmambapy/src/main.cpp index 7a877fdea..a4bdf8825 100644 --- a/libmambapy/src/main.cpp +++ b/libmambapy/src/main.cpp @@ -232,7 +232,6 @@ PYBIND11_MODULE(bindings, m) MultiPackageCache&, const std::string&>()) .def("create_repo", &MSubdirData::create_repo, py::return_value_policy::reference) - .def("load", &MSubdirData::load) .def("loaded", &MSubdirData::loaded) .def("cache_path", &MSubdirData::cache_path); diff --git a/mamba/mamba/utils.py b/mamba/mamba/utils.py index ce6f20658..09262288b 100644 --- a/mamba/mamba/utils.py +++ b/mamba/mamba/utils.py @@ -29,7 +29,7 @@ import libmambapy as api def load_channel(subdir_data, result_container): if not context.quiet: print("Getting ", subdir_data.channel.name, subdir_data.channel.platform) - return result_container.append(subdir_data.load()) + return result_container.append(subdir_data.loaded()) def get_index( @@ -85,8 +85,6 @@ def get_index( channel, channel_platform, full_url, pkgs_dirs, repodata_fn ) - sd.load() - index.append( (sd, {"platform": channel_platform, "url": url, "channel": channel}) )