Storing repos in pool (#1546)

This commit is contained in:
Johan Mabille 2022-03-01 15:21:15 +01:00 committed by GitHub
parent 304bdb51b6
commit 5ce0c38b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 34 additions and 27 deletions

View File

@ -8,8 +8,8 @@ namespace mamba
{
namespace detail
{
MRepo create_repo_from_pkgs_dir(MPool& pool, const fs::path& pkgs_dir);
MRepo& create_repo_from_pkgs_dir(MPool& pool, const fs::path& pkgs_dir);
}
std::vector<MRepo> load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry);
void load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry);
}

View File

@ -8,6 +8,7 @@
#define MAMBA_CORE_POOL_HPP
#include "context.hpp"
#include "repo.hpp"
extern "C"
{
@ -32,9 +33,12 @@ namespace mamba
operator Pool*();
MRepo& add_repo(MRepo&& repo);
private:
std::pair<spdlog::logger*, std::string> m_debug_logger;
Pool* m_pool;
std::vector<MRepo> m_repo_list;
};
} // namespace mamba

View File

@ -21,10 +21,10 @@ extern "C"
#include "solv/repo_solv.h"
}
#include "pool.hpp"
namespace mamba
{
class MPool;
/**
* Represents a channel subdirectory
* index.

View File

@ -19,6 +19,7 @@
#include "mamba/core/mamba_fs.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/package_cache.hpp"
#include "mamba/core/pool.hpp"
#include "mamba/core/repo.hpp"
#include "mamba/core/util.hpp"
@ -65,7 +66,7 @@ namespace mamba
DownloadTarget* target();
bool finalize_transfer();
MRepo create_repo(MPool& pool);
MRepo& create_repo(MPool& pool);
private:
bool decompress();

View File

@ -10,7 +10,7 @@ namespace mamba
{
namespace detail
{
MRepo create_repo_from_pkgs_dir(MPool& pool, const fs::path& pkgs_dir)
MRepo& create_repo_from_pkgs_dir(MPool& pool, const fs::path& pkgs_dir)
{
if (!fs::exists(pkgs_dir))
{
@ -27,11 +27,11 @@ namespace mamba
}
prefix_data.load_single_record(repodata_record_json);
}
return MRepo(pool, prefix_data);
return pool.add_repo(MRepo(pool, prefix_data));
}
}
std::vector<MRepo> load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry)
void load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry)
{
int RETRY_SUBDIR_FETCH = 1 << 0;
@ -81,14 +81,12 @@ namespace mamba
multi_dl.download(MAMBA_DOWNLOAD_FAILFAST);
}
std::vector<MRepo> repos;
if (ctx.offline)
{
LOG_INFO << "Creating repo from pkgs_dir for offline";
for (const auto& c : ctx.pkgs_dirs)
repos.push_back(detail::create_repo_from_pkgs_dir(pool, c));
detail::create_repo_from_pkgs_dir(pool, c);
}
std::string prev_channel;
bool loading_failed = false;
for (std::size_t i = 0; i < subdirs.size(); ++i)
@ -109,9 +107,8 @@ namespace mamba
auto& prio = priorities[i];
try
{
MRepo repo = subdir->create_repo(pool);
MRepo& repo = subdir->create_repo(pool);
repo.set_priority(prio.first, prio.second);
repos.push_back(std::move(repo));
}
catch (std::runtime_error& e)
{
@ -139,7 +136,6 @@ namespace mamba
}
throw std::runtime_error("Could not load repodata. Cache corrupted?");
}
return repos;
}
}

View File

@ -357,7 +357,7 @@ namespace mamba
}
MPool pool;
std::vector<MRepo> repos = load_channels(pool, package_caches, is_retry);
load_channels(pool, package_caches, is_retry);
PrefixData prefix_data(ctx.target_prefix);
prefix_data.load();
@ -368,7 +368,7 @@ namespace mamba
prefix_data.add_virtual_packages(get_virtual_packages());
repos.push_back(MRepo(pool, prefix_data));
pool.add_repo(MRepo(pool, prefix_data));
MSolver solver(pool,
{ { SOLVER_FLAG_ALLOW_UNINSTALL, ctx.allow_uninstall },

View File

@ -68,11 +68,10 @@ namespace mamba
throw std::runtime_error("Aborted.");
}
std::vector<MRepo> repos;
MPool pool;
PrefixData prefix_data(ctx.target_prefix);
prefix_data.load();
repos.push_back(MRepo(pool, prefix_data));
MPool pool;
pool.add_repo(MRepo(pool, prefix_data));
const fs::path pkgs_dirs(ctx.root_prefix / "pkgs");
MultiPackageCache package_caches({ pkgs_dirs });

View File

@ -27,17 +27,16 @@ namespace mamba
// bool installed = (type == QueryType::kDepends) || (type == QueryType::kWhoneeds);
MultiPackageCache package_caches(ctx.pkgs_dirs);
std::vector<MRepo> repos;
if (use_local)
{
auto prefix_data = PrefixData(ctx.target_prefix);
prefix_data.load();
repos.push_back(MRepo(pool, prefix_data));
pool.add_repo(MRepo(pool, prefix_data));
Console::stream() << "Loaded current active prefix: " << ctx.target_prefix << std::endl;
}
else
{
repos = load_channels(pool, package_caches, 0);
load_channels(pool, package_caches, 0);
}
Query q(pool);

View File

@ -35,7 +35,7 @@ namespace mamba
MPool pool;
MultiPackageCache package_caches(ctx.pkgs_dirs);
auto repos = load_channels(pool, package_caches, 0);
load_channels(pool, package_caches, 0);
PrefixData prefix_data(ctx.target_prefix);
prefix_data.load();
@ -46,7 +46,7 @@ namespace mamba
prefix_data.add_virtual_packages(get_virtual_packages());
repos.push_back(MRepo(pool, prefix_data));
pool.add_repo(MRepo(pool, prefix_data));
MSolver solver(pool,
{ { SOLVER_FLAG_ALLOW_DOWNGRADE, ctx.allow_downgrade },

View File

@ -70,4 +70,11 @@ namespace mamba
{
return m_pool;
}
MRepo& MPool::add_repo(MRepo&& repo)
{
m_repo_list.push_back(std::move(repo));
return m_repo_list.back();
}
} // namespace mamba

View File

@ -4,6 +4,7 @@
//
// The full license is in the file LICENSE, distributed with this software.
#include "mamba/core/pool.hpp"
#include "mamba/core/repo.hpp"
#include "mamba/core/output.hpp"
#include "mamba/core/package_info.hpp"

View File

@ -586,14 +586,14 @@ namespace mamba
return cache_dir;
}
MRepo MSubdirData::create_repo(MPool& pool)
MRepo& MSubdirData::create_repo(MPool& pool)
{
RepoMetadata meta{ m_repodata_url,
Context::instance().add_pip_as_python_dependency,
m_mod_etag.value("_etag", ""),
m_mod_etag.value("_mod", "") };
return MRepo(pool, m_name, cache_path(), meta, *p_channel);
return pool.add_repo(MRepo(pool, m_name, cache_path(), meta, *p_channel));
}
void MSubdirData::clear_cache()

View File

@ -223,7 +223,7 @@ PYBIND11_MODULE(bindings, m)
const std::string&,
MultiPackageCache&,
const std::string&>())
.def("create_repo", &MSubdirData::create_repo)
.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);