Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaim committed Apr 20, 2023
1 parent 8f0d13f commit 25befe9
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 57 deletions.
3 changes: 1 addition & 2 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ namespace mamba
platform_urls(bool with_credential = true) const;
std::vector<std::string> urls(bool with_credential = true) const;

const ChannelContext& channel_context() const { return m_channel_context; }
ChannelContext& channel_context() { return m_channel_context; }
ChannelContext& channel_context() const { return m_channel_context; }

private:

Expand Down
1 change: 1 addition & 0 deletions libmamba/include/mamba/core/env_lockfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace mamba
{
class ChannelContext;

enum class file_parsing_error_code
{
Expand Down
3 changes: 2 additions & 1 deletion libmamba/include/mamba/core/history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace mamba
{
public:

History(const fs::u8path& prefix);
History(const fs::u8path& prefix, ChannelContext& channel_context);

struct ParseResult
{
Expand Down Expand Up @@ -54,6 +54,7 @@ namespace mamba

fs::u8path m_prefix;
fs::u8path m_history_file_path;
ChannelContext& m_channel_context;
};

} // namespace mamba
Expand Down
3 changes: 1 addition & 2 deletions libmamba/include/mamba/core/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ namespace mamba
MRepo& add_repo(MRepo&& repo);
void remove_repo(Id repo_id);

ChannelContext& channel_context();
const ChannelContext& channel_context() const;
ChannelContext& channel_context() const;

private:

Expand Down
10 changes: 8 additions & 2 deletions libmamba/include/mamba/core/prefix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

namespace mamba
{
class ChannelContext;

class PrefixData
{
public:

using package_map = std::map<std::string, PackageInfo>;

static expected_t<PrefixData> create(const fs::u8path& prefix_path);
static expected_t<PrefixData> create(const fs::u8path& prefix_path, ChannelContext& channel_context);

void add_packages(const std::vector<PackageInfo>& packages);
const package_map& records() const;
Expand All @@ -32,14 +34,18 @@ namespace mamba
const fs::u8path& path() const;
std::vector<PackageInfo> sorted_records() const;

ChannelContext& channel_context() const { return m_channel_context; }

private:

PrefixData(const fs::u8path& prefix_path);
PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context);
void load();

History m_history;
package_map m_package_records;
fs::u8path m_prefix_path;

ChannelContext& m_channel_context;
};
} // namespace mamba

Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace mamba
std::ostream& table(std::ostream&) const;
std::ostream& table(std::ostream&, const std::vector<std::string>& fmt) const;
std::ostream& tree(std::ostream&) const;
nlohmann::json json() const;
nlohmann::json json(ChannelContext& channel_context) const;

std::ostream& pretty(std::ostream&) const;

Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/api/channel_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace mamba
// TODO : us tl::expected mechanis
throw std::runtime_error("Specified pkgs_dir does not exist\n");
}
auto sprefix_data = PrefixData::create(pkgs_dir);
auto sprefix_data = PrefixData::create(pkgs_dir, pool.channel_context());
if (!sprefix_data)
{
throw std::runtime_error("Specified pkgs_dir does not exist\n");
Expand Down Expand Up @@ -63,7 +63,7 @@ namespace mamba

std::vector<mamba_error> error_list;

for (auto channel : get_channels(channel_urls))
for (auto channel : pool.channel_context().get_channels(channel_urls))
{
for (auto& [platform, url] : channel->platform_urls(true))
{
Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ namespace mamba
LOG_WARNING << "No 'channels' specified";
}

MPool pool;
MPool pool{channel_context};
// functions implied in 'and_then' coding-styles must return the same type
// which limits this syntax
/*auto exp_prefix_data = load_channels(pool, package_caches, is_retry)
Expand All @@ -474,7 +474,7 @@ namespace mamba
throw std::runtime_error(exp_load.error().what());
}

auto exp_prefix_data = PrefixData::create(ctx.target_prefix);
auto exp_prefix_data = PrefixData::create(ctx.target_prefix, pool.channel_context());
if (!exp_prefix_data)
{
throw std::runtime_error(exp_prefix_data.error().what());
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace mamba
{
auto& ctx = Context::instance();

auto sprefix_data = PrefixData::create(ctx.target_prefix);
auto sprefix_data = PrefixData::create(ctx.target_prefix, channel_context);
if (!sprefix_data)
{
// TODO: propagate tl::expected mechanism
Expand Down
10 changes: 5 additions & 5 deletions libmamba/src/api/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace mamba
{
void remove(int flags)
void remove(int flags, ChannelContext& channel_context)
{
bool prune = flags & MAMBA_REMOVE_PRUNE;
bool force = flags & MAMBA_REMOVE_FORCE;
Expand All @@ -37,7 +37,7 @@ namespace mamba

if (remove_all)
{
auto sprefix_data = PrefixData::create(ctx.target_prefix);
auto sprefix_data = PrefixData::create(ctx.target_prefix, channel_context);
if (!sprefix_data)
{
// TODO: propagate tl::expected mechanism
Expand All @@ -64,7 +64,7 @@ namespace mamba

namespace detail
{
void remove_specs(const std::vector<std::string>& specs, bool prune, bool force)
void remove_specs(ChannelContext& channel_context, const std::vector<std::string>& specs, bool prune, bool force)
{
auto& ctx = Context::instance();

Expand All @@ -74,15 +74,15 @@ namespace mamba
throw std::runtime_error("Aborted.");
}

auto exp_prefix_data = PrefixData::create(ctx.target_prefix);
auto exp_prefix_data = PrefixData::create(ctx.target_prefix, channel_context);
if (!exp_prefix_data)
{
// TODO: propagate tl::expected mechanism
throw std::runtime_error(exp_prefix_data.error().what());
}
PrefixData& prefix_data = exp_prefix_data.value();

MPool pool;
MPool pool{channel_context};
MRepo::create(pool, prefix_data);

const fs::u8path pkgs_dirs(ctx.root_prefix / "pkgs");
Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/api/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace mamba
{
void repoquery(QueryType type, QueryResultFormat format, bool use_local, const std::string& query)
void repoquery(ChannelContext& channel_context, QueryType type, QueryResultFormat format, bool use_local, const std::string& query)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
Expand All @@ -26,7 +26,7 @@ namespace mamba
.set_value(MAMBA_ALLOW_EXISTING_PREFIX | MAMBA_ALLOW_MISSING_PREFIX);
config.load();

MPool pool;
MPool pool{ channel_context };

// bool installed = (type == QueryType::kDepends) || (type == QueryType::kWhoneeds);
MultiPackageCache package_caches(ctx.pkgs_dirs);
Expand Down
15 changes: 9 additions & 6 deletions libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ namespace mamba
}
name = name != "" ? strip(name, "/") : strip(channel_url, "/");
return Channel(
*this,
scheme,
location,
name,
Expand All @@ -317,8 +318,8 @@ namespace mamba

const Channel& ChannelContext::make_cached_channel(const std::string& value)
{
auto res = get_cache().find(value);
if (res == get_cache().end())
auto res = m_channel_cache.find(value);
if (res == m_channel_cache.end())
{
auto& ctx = Context::instance();

Expand Down Expand Up @@ -346,7 +347,7 @@ namespace mamba
}
}
}
res = get_cache().insert(std::make_pair(value, std::move(chan))).first;
res = m_channel_cache.insert(std::make_pair(value, std::move(chan))).first;
}
return res->second;
}
Expand Down Expand Up @@ -499,6 +500,7 @@ namespace mamba
auto config = read_channel_configuration(*this, scheme, host, port, path);

return Channel(
*this,
config.m_scheme.size() ? config.m_scheme : "https",
config.m_location,
config.m_name,
Expand Down Expand Up @@ -543,6 +545,7 @@ namespace mamba
}

return Channel(
*this,
it->second.scheme(),
it->second.location(),
combined_name,
Expand All @@ -555,7 +558,7 @@ namespace mamba
else
{
const Channel& alias = get_channel_alias();
return Channel(alias.scheme(), alias.location(), name, alias.auth(), alias.token());
return Channel(*this, alias.scheme(), alias.location(), name, alias.auth(), alias.token());
}
}

Expand Down Expand Up @@ -685,7 +688,7 @@ namespace mamba
{
if (INVALID_CHANNELS.count(in_value) > 0)
{
return Channel("", "", UNKNOWN_CHANNEL, "");
return Channel(*this, "", "", UNKNOWN_CHANNEL, "");
}

std::string value = in_value;
Expand Down Expand Up @@ -765,7 +768,7 @@ namespace mamba
whitelist.begin(),
whitelist.end(),
accepted_urls.begin(),
[](const std::string& url) { return make_channel(url).base_url(); }
[&](const std::string& url) { return make_channel(url).base_url(); }
);
std::for_each(
urls.begin(),
Expand Down
7 changes: 4 additions & 3 deletions libmamba/src/core/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

namespace mamba
{
History::History(const fs::u8path& prefix)
History::History(const fs::u8path& prefix, ChannelContext& channel_context)
: m_prefix(prefix)
, m_history_file_path(fs::absolute(m_prefix / "conda-meta" / "history"))
, m_channel_context(channel_context)
{
}

Expand Down Expand Up @@ -193,13 +194,13 @@ namespace mamba
{
std::unordered_map<std::string, MatchSpec> map;

auto to_specs = [](const std::vector<std::string>& sv)
auto to_specs = [&](const std::vector<std::string>& sv)
{
std::vector<MatchSpec> v;
v.reserve(sv.size());
for (const auto& el : sv)
{
v.emplace_back(el);
v.emplace_back(el, m_channel_context);
}
return v;
};
Expand Down
7 changes: 1 addition & 6 deletions libmamba/src/core/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ namespace mamba

MPool::~MPool() = default;

ChannelContext& MPool::channel_context()
{
return m_data->channel_context;
}

const ChannelContext& MPool::channel_context() const
ChannelContext& MPool::channel_context() const
{
return m_data->channel_context;
}
Expand Down
11 changes: 6 additions & 5 deletions libmamba/src/core/prefix_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

namespace mamba
{
auto PrefixData::create(const fs::u8path& prefix_path) -> expected_t<PrefixData>
auto PrefixData::create(const fs::u8path& prefix_path, ChannelContext& channel_context) -> expected_t<PrefixData>
{
try
{
return PrefixData(prefix_path);
return PrefixData(prefix_path, channel_context);
}
catch (std::exception& e)
{
Expand All @@ -35,9 +35,10 @@ namespace mamba
}
}

PrefixData::PrefixData(const fs::u8path& prefix_path)
: m_history(prefix_path)
PrefixData::PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context)
: m_history(prefix_path, channel_context)
, m_prefix_path(prefix_path)
, m_channel_context(channel_context)
{
load();
}
Expand Down Expand Up @@ -95,7 +96,7 @@ namespace mamba
for (const auto& dep : record->depends)
{
// Creating a matchspec to parse the name (there may be a channel)
auto ms = MatchSpec(dep);
auto ms = MatchSpec{ dep, m_channel_context };
// Ignoring unmatched dependencies, the environment could be broken
// or it could be a matchspec
const auto from_iter = name_to_node_id.find(ms.name);
Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/core/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,13 @@ namespace mamba
return out;
}

nlohmann::json query_result::json() const
nlohmann::json query_result::json(ChannelContext& channel_context) const
{
nlohmann::json j;
std::string query_type = m_type == QueryType::kSEARCH
? "search"
: (m_type == QueryType::kDEPENDS ? "depends" : "whoneeds");
j["query"] = { { "query", MatchSpec(m_query).conda_build_form() }, { "type", query_type } };
j["query"] = { { "query", MatchSpec{ m_query, channel_context }.conda_build_form() }, { "type", query_type } };

std::string msg = m_pkg_id_list.empty() ? "No entries matching \"" + m_query + "\" found"
: "";
Expand Down
Loading

0 comments on commit 25befe9

Please sign in to comment.