Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ChanelContext context capture #3015

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion libmamba/include/mamba/api/channel_loader.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// Copyright (c) 2019, QuantStack and Mamba Contributors
//
// Distributed under the terms of the BSD 3-Clause License.
//
// The full license is in the file LICENSE, distributed with this software.

#ifndef MAMBA_API_CHANNEL_LOADER_HPP
#define MAMBA_API_CHANNEL_LOADER_HPP

#include "mamba/core/error_handling.hpp"

namespace mamba
{
class Context;
class MPool;
class MultiPackageCache;

expected_t<void, mamba_aggregated_error>
load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry);
load_channels(Context& ctx, MPool& pool, MultiPackageCache& package_caches, int is_retry);
}
#endif
4 changes: 2 additions & 2 deletions libmamba/include/mamba/api/info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
#define MAMBA_API_INFO_HPP

#include <string>
#include <vector>

namespace mamba
{
class ChannelContext;
class Configuration;
class Context;

void info(Configuration& config);

std::string version();

namespace detail
{
void print_info(ChannelContext& channel_context, const Configuration& config);
void print_info(Context& ctx, ChannelContext& channel_context, const Configuration& config);
}
}

Expand Down
9 changes: 7 additions & 2 deletions libmamba/include/mamba/api/install.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ namespace mamba
);

void install_explicit_specs(
Context& ctx,
ChannelContext& channel_context,
const std::vector<std::string>& specs,
bool create_env = false,
bool remove_prefix_on_failure = false
);
void install_lockfile_specs(
Context& ctx,
ChannelContext& channel_context,
const std::string& lockfile_specs,
const std::vector<std::string>& categories,
Expand Down Expand Up @@ -85,8 +87,11 @@ namespace mamba

yaml_file_contents read_yaml_file(fs::u8path yaml_file, const std::string platform);

std::tuple<std::vector<PackageInfo>, std::vector<MatchSpec>>
parse_urls_to_package_info(const std::vector<std::string>& urls, ChannelContext& channel_context);
std::tuple<std::vector<PackageInfo>, std::vector<MatchSpec>> parse_urls_to_package_info(
const std::vector<std::string>& urls,
Context& ctx,
ChannelContext& channel_context
);

inline void to_json(nlohmann::json&, const other_pkg_mgr_spec&)
{
Expand Down
3 changes: 2 additions & 1 deletion libmamba/include/mamba/api/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ namespace mamba
{
class ChannelContext;
class Configuration;
class Context;

void list(Configuration& config, const std::string& regex);

namespace detail
{
void list_packages(std::string regex, ChannelContext& channel_context);
void list_packages(const Context& ctx, std::string regex, ChannelContext& channel_context);

struct formatted_pkg;

Expand Down
3 changes: 3 additions & 0 deletions libmamba/include/mamba/api/remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

namespace mamba
{
class Context;
class ChannelContext;
class Configuration;

void remove(Configuration& config, int flags = MAMBA_REMOVE_PRUNE);

namespace detail
{
void remove_specs(
Context& ctx,
ChannelContext& channel_context,
const std::vector<std::string>& specs,
bool prune,
Expand Down
8 changes: 2 additions & 6 deletions libmamba/include/mamba/api/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
#ifndef MAMBA_API_UPDATE_HPP
#define MAMBA_API_UPDATE_HPP

#include <string>
#include <vector>

#include "mamba/core/query.hpp"
#include "mamba/fs/filesystem.hpp"


namespace mamba
{
class Configuration;

void update(
Configuration& config,
bool update_all = false,
Expand Down
15 changes: 3 additions & 12 deletions libmamba/include/mamba/core/channel_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef MAMBA_CORE_CHANNEL_HPP
#define MAMBA_CORE_CHANNEL_HPP

#include <functional>
#include <string>
#include <string_view>

Expand All @@ -32,7 +31,7 @@ namespace mamba
* Custom channels are treated as aliases rather than the Conda way (the name is not
* added at the end of the URL if absent).
*/
[[nodiscard]] static auto make_simple(Context& ctx) -> ChannelContext;
[[nodiscard]] static auto make_simple(const Context& ctx) -> ChannelContext;

/**
* Create a ChannelContext while applying all of Conda context options.
Expand All @@ -43,36 +42,28 @@ namespace mamba
* be added.
* The function will ensure custom channels names are added at the end of the URLs.
*/
[[nodiscard]] static auto make_conda_compatible(Context& ctx) -> ChannelContext;
[[nodiscard]] static auto make_conda_compatible(const Context& ctx) -> ChannelContext;

/**
* Initialize channel with the parameters as they are.
*
* The Context is not parsed.
*/
ChannelContext(Context& ctx, ChannelResolveParams params, std::vector<Channel> has_zst);
ChannelContext(ChannelResolveParams params, std::vector<Channel> has_zst);

auto make_channel(std::string_view name) -> const channel_list&;

[[nodiscard]] auto params() const -> const specs::ChannelResolveParams&;

[[nodiscard]] auto has_zst(const Channel& chan) const -> bool;

/**
* Return the context.
*
* @deprecated We aim to remove the capture of the Context.
*/
[[nodiscard, deprecated]] auto context() const -> const Context&;

private:

using ChannelCache = std::unordered_map<std::string, channel_list>;

ChannelResolveParams m_channel_params;
ChannelCache m_channel_cache;
std::vector<Channel> m_has_zst;
std::reference_wrapper<const Context> m_context;
};
}
#endif
8 changes: 6 additions & 2 deletions libmamba/include/mamba/core/env_lockfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace mamba
{
class Context;
class ChannelContext;

enum class file_parsing_error_code
Expand Down Expand Up @@ -112,8 +113,11 @@ namespace mamba

/// Read an environment lock YAML file and returns it's structured content or an error if
/// failed.
tl::expected<EnvironmentLockFile, mamba_error>
read_environment_lockfile(ChannelContext& channel_context, const mamba::fs::u8path& lockfile_location);
tl::expected<EnvironmentLockFile, mamba_error> read_environment_lockfile(
const Context& ctx,
ChannelContext& channel_context,
const mamba::fs::u8path& lockfile_location
);


/// Returns `true` if the filename matches names of files which should be interpreted as conda
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace mamba
std::vector<ParseResult> parse();
bool parse_comment_line(const std::string& line, UserRequest& req);
std::vector<UserRequest> get_user_requests();
std::unordered_map<std::string, MatchSpec> get_requested_specs_map();
std::unordered_map<std::string, MatchSpec> get_requested_specs_map(const Context& ctx);
void add_entry(const History::UserRequest& entry);

fs::u8path m_prefix;
Expand Down
5 changes: 3 additions & 2 deletions libmamba/include/mamba/core/match_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace mamba
{
class Context;
class ChannelContext;

class MatchSpec
Expand All @@ -22,9 +23,9 @@ namespace mamba

MatchSpec() = default;

MatchSpec(std::string_view i_spec, ChannelContext& channel_context);
MatchSpec(std::string_view i_spec, const Context& ctx, ChannelContext& channel_context);

void parse(ChannelContext& channel_context);
void parse(const Context& ctx, ChannelContext& channel_context);
std::string conda_build_form() const;
std::string str() const;

Expand Down
8 changes: 1 addition & 7 deletions libmamba/include/mamba/core/package_fetcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <functional>

#include "mamba/core/channel_context.hpp"
#include "mamba/core/download.hpp"
#include "mamba/core/package_cache.hpp"
#include "mamba/core/package_handling.hpp"
Expand Down Expand Up @@ -79,11 +78,7 @@ namespace mamba
using post_download_success_t = std::function<void(std::size_t)>;
using progress_callback_t = std::function<void(PackageExtractEvent)>;

PackageFetcher(
const PackageInfo& pkg_info,
ChannelContext& channel_context,
MultiPackageCache& caches
);
PackageFetcher(const PackageInfo& pkg_info, MultiPackageCache& caches);

const std::string& name() const;

Expand Down Expand Up @@ -127,7 +122,6 @@ namespace mamba
void update_monitor(progress_callback_t* cb, PackageExtractEvent event) const;

PackageInfo m_package_info;
std::string m_url = "";

fs::u8path m_tarball_path;
fs::u8path m_cache_path;
Expand Down
18 changes: 14 additions & 4 deletions libmamba/include/mamba/core/pinning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
#include <string>
#include <vector>

#include "prefix_data.hpp"


namespace mamba
{
std::string python_pin(PrefixData& prefix_data, const std::vector<std::string>& specs);
class Context;
class ChannelContext;
class PrefixData;
namespace fs
{
class u8path;
}

std::string python_pin(
const Context& ctx,
ChannelContext& chc,
PrefixData& prefix_data,
const std::vector<std::string>& specs
);

std::vector<std::string> file_pins(const fs::u8path& file);
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace mamba
{
public:

MPool(ChannelContext& channel_context);
MPool(Context& ctx, ChannelContext& channel_context);
~MPool();

void set_debuglevel();
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/prefix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace mamba

History& history();
const fs::u8path& path() const;
std::vector<PackageInfo> sorted_records() const;
std::vector<PackageInfo> sorted_records(const Context& ctx) const;

ChannelContext& channel_context() const
{
Expand Down
2 changes: 2 additions & 0 deletions libmamba/include/mamba/core/subdirdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace mamba
public:

static expected_t<MSubdirData> create(
Context& ctx,
ChannelContext& channel_context,
const specs::Channel& channel,
const std::string& platform,
Expand Down Expand Up @@ -137,6 +138,7 @@ namespace mamba
private:

MSubdirData(
Context& ctx,
ChannelContext& channel_context,
const specs::Channel& channel,
const std::string& platform,
Expand Down
7 changes: 3 additions & 4 deletions libmamba/src/api/channel_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ namespace mamba
}

expected_t<void, mamba_aggregated_error>
load_channels(MPool& pool, MultiPackageCache& package_caches, int is_retry)
load_channels(Context& ctx, MPool& pool, MultiPackageCache& package_caches, int is_retry)
{
int RETRY_SUBDIR_FETCH = 1 << 0;

auto& ctx = pool.context();

std::vector<MSubdirData> subdirs;

std::vector<std::pair<int, int>> priorities;
Expand All @@ -68,6 +66,7 @@ namespace mamba
for (const auto& platform : channel.platforms())
{
auto sdires = MSubdirData::create(
ctx,
pool.channel_context(),
channel,
platform,
Expand Down Expand Up @@ -178,7 +177,7 @@ namespace mamba
if (!ctx.offline && !(is_retry & RETRY_SUBDIR_FETCH))
{
LOG_WARNING << "Encountered malformed repodata.json cache. Redownloading.";
return load_channels(pool, package_caches, is_retry | RETRY_SUBDIR_FETCH);
return load_channels(ctx, pool, package_caches, is_retry | RETRY_SUBDIR_FETCH);
}
error_list.push_back(mamba_error(
"Could not load repodata. Cache corrupted?",
Expand Down
3 changes: 2 additions & 1 deletion libmamba/src/api/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace mamba
{
const auto lockfile_path = ctx.env_lockfile.value();
install_lockfile_specs(
ctx,
channel_context,
lockfile_path,
config.at("categories").value<std::vector<std::string>>(),
Expand All @@ -93,7 +94,7 @@ namespace mamba
{
if (use_explicit)
{
install_explicit_specs(channel_context, create_specs, true, remove_prefix_on_failure);
install_explicit_specs(ctx, channel_context, create_specs, true, remove_prefix_on_failure);
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions libmamba/src/api/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace mamba
config.load();

auto channel_context = ChannelContext::make_conda_compatible(config.context());
detail::print_info(channel_context, config);
detail::print_info(config.context(), channel_context, config);

config.operation_teardown();
}
Expand Down Expand Up @@ -88,10 +88,9 @@ namespace mamba
Console::instance().json_write(items_map);
}

void print_info(ChannelContext& channel_context, const Configuration& config)
void print_info(Context& ctx, ChannelContext& channel_context, const Configuration& config)
{
assert(&channel_context.context() == &config.context());
const auto& ctx = config.context();
assert(&ctx == &config.context());
std::vector<std::tuple<std::string, nlohmann::json>> items;

items.push_back({ "libmamba version", version() });
Expand Down
Loading
Loading