Skip to content

Commit

Permalink
WIP - most libmamba is modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaim committed Apr 18, 2023
1 parent 1f5e51b commit 337db2c
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 62 deletions.
3 changes: 3 additions & 0 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ 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; }

private:

Channel(
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/env_lockfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ 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(const fs::u8path& lockfile_location);
read_environment_lockfile(ChannelContext& channel_context, const fs::u8path& lockfile_location);


/// Returns `true` if the filename matches names of files which should be interpreted as conda
Expand Down
8 changes: 5 additions & 3 deletions libmamba/include/mamba/core/match_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

namespace mamba
{
class ChannelContext;

class MatchSpec
{
public:

MatchSpec() = default;
// TODO make explicit
MatchSpec(std::string_view i_spec);

void parse();
MatchSpec(std::string_view i_spec, ChannelContext& channel_context);

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

Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/core/pinning.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace mamba
{
std::string python_pin(const PrefixData& prefix_data, const std::vector<std::string>& specs);
std::string python_pin(PrefixData& prefix_data, const std::vector<std::string>& specs);

std::vector<std::string> file_pins(const fs::u8path& file);
}
Expand Down
6 changes: 5 additions & 1 deletion libmamba/include/mamba/core/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace mamba
{
class MatchSpec;
class ChannelContext;

/**
* Pool of solvable involved in resolving en environment.
Expand All @@ -31,7 +32,7 @@ namespace mamba
{
public:

MPool();
MPool(ChannelContext& channel_context);
~MPool();

std::size_t n_solvables() const;
Expand All @@ -51,6 +52,9 @@ namespace mamba
MRepo& add_repo(MRepo&& repo);
void remove_repo(Id repo_id);

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

private:

struct MPoolData;
Expand Down
5 changes: 5 additions & 0 deletions libmamba/include/mamba/core/prefix_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "error_handling.hpp"
#include "history.hpp"
#include "package_info.hpp"
#include "channel.hpp"

namespace mamba
{
Expand All @@ -32,6 +33,9 @@ namespace mamba
const fs::u8path& path() const;
std::vector<PackageInfo> sorted_records() const;

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

private:

PrefixData(const fs::u8path& prefix_path);
Expand All @@ -40,6 +44,7 @@ namespace mamba
History m_history;
package_map m_package_records;
fs::u8path m_prefix_path;
ChannelContext m_channel_context; // FIXME: REVIEWERS, does this make sense or should it be a dependency?
};
} // namespace mamba

Expand Down
8 changes: 4 additions & 4 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ namespace mamba
}

std::tuple<std::vector<PackageInfo>, std::vector<MatchSpec>>
parse_urls_to_package_info(const std::vector<std::string>& urls)
parse_urls_to_package_info(const std::vector<std::string>& urls, ChannelContext& channel_context)
{
std::vector<PackageInfo> pi_result;
std::vector<MatchSpec> ms_result;
Expand All @@ -346,7 +346,7 @@ namespace mamba
continue;
}
std::size_t hash = u.find_first_of('#');
MatchSpec ms(u.substr(0, hash));
MatchSpec ms(u.substr(0, hash), channel_context);
PackageInfo p(ms.name);
p.url = ms.url;
p.build_string = ms.build_string;
Expand Down Expand Up @@ -420,7 +420,7 @@ namespace mamba
int RETRY_SOLVE_ERROR = 1 << 1;

void
install_specs(const std::vector<std::string>& specs, bool create_env, int solver_flag, int is_retry)
install_specs(ChannelContext& channel_context, const std::vector<std::string>& specs, bool create_env, int solver_flag, int is_retry)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
Expand Down Expand Up @@ -449,7 +449,7 @@ namespace mamba
// add channels from specs
for (const auto& s : specs)
{
if (auto m = MatchSpec{ s }; !m.channel.empty())
if (auto m = MatchSpec{ s, channel_context }; !m.channel.empty())
{
ctx.channels.push_back(m.channel);
}
Expand Down
6 changes: 3 additions & 3 deletions libmamba/src/api/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace mamba
return a.name < b.name;
}

void list_packages(std::string regex)
void list_packages(std::string regex, ChannelContext& channel_context)
{
auto& ctx = Context::instance();

Expand Down Expand Up @@ -77,7 +77,7 @@ namespace mamba

if (regex.empty() || std::regex_search(pkg_info.name, spec_pat))
{
auto& channel = make_channel(pkg_info.url);
auto& channel = channel_context.make_channel(pkg_info.url);
obj["base_url"] = channel.base_url();
obj["build_number"] = pkg_info.build_number;
obj["build_string"] = pkg_info.build_string;
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace mamba
}
else
{
const Channel& channel = make_channel(package.second.url);
const Channel& channel = channel_context.make_channel(package.second.url);
formatted_pkgs.channel = channel.name();
}
packages.push_back(formatted_pkgs);
Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/api/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace mamba
{
void update(bool update_all, bool prune)
void update(ChannelContext& channel_context, bool update_all, bool prune)
{
auto& ctx = Context::instance();
auto& config = Configuration::instance();
Expand All @@ -33,7 +33,7 @@ namespace mamba
// add channels from specs
for (const auto& s : update_specs)
{
if (auto m = MatchSpec{ s }; !m.channel.empty())
if (auto m = MatchSpec{ s, channel_context }; !m.channel.empty())
{
ctx.channels.push_back(m.channel);
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ namespace mamba

auto add_channel = [&](const std::string& lname)
{
auto channel = &make_channel(lname + platform_spec);
auto* channel = &make_channel(lname + platform_spec);
if (added.insert(channel).second)
{
result.push_back(channel);
Expand Down
12 changes: 6 additions & 6 deletions libmamba/src/core/env_lockfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace mamba
{
using Package = EnvironmentLockFile::Package;

tl::expected<Package, mamba_error> read_package_info(const YAML::Node& package_node)
tl::expected<Package, mamba_error> read_package_info(ChannelContext& channel_context, const YAML::Node& package_node)
{
Package package{
/* .info = */ mamba::PackageInfo{ package_node["name"].as<std::string>() },
Expand Down Expand Up @@ -57,7 +57,7 @@ namespace mamba
}

package.info.url = package_node["url"].as<std::string>();
const MatchSpec spec{ package.info.url };
const MatchSpec spec{ package.info.url, channel_context };
package.info.fn = spec.fn;
package.info.build_string = spec.build_string;
package.info.subdir = spec.subdir;
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace mamba
}

tl::expected<EnvironmentLockFile, mamba_error>
read_environment_lockfile(const YAML::Node& lockfile_yaml)
read_environment_lockfile(ChannelContext& channel_context, const YAML::Node& lockfile_yaml)
{
const auto& maybe_metadata = read_metadata(lockfile_yaml["metadata"]);
if (!maybe_metadata)
Expand All @@ -158,7 +158,7 @@ namespace mamba
std::vector<Package> packages;
for (const auto& package_node : lockfile_yaml["package"])
{
if (auto maybe_package = read_package_info(package_node))
if (auto maybe_package = read_package_info(channel_context, package_node))
{
packages.push_back(maybe_package.value());
}
Expand All @@ -173,7 +173,7 @@ namespace mamba
}

tl::expected<EnvironmentLockFile, mamba_error>
read_environment_lockfile(const fs::u8path& lockfile_location)
read_environment_lockfile(ChannelContext& channel_context, const fs::u8path& lockfile_location)
{
const auto file_path = fs::absolute(lockfile_location); // Having the complete path helps
// with logging and error reports.
Expand All @@ -185,7 +185,7 @@ namespace mamba
switch (lockfile_version)
{
case 1:
return env_lockfile_v1::read_environment_lockfile(lockfile_content);
return env_lockfile_v1::read_environment_lockfile(channel_context, lockfile_content);

default:
{
Expand Down
8 changes: 4 additions & 4 deletions libmamba/src/core/match_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace mamba
return split_str;
}

MatchSpec::MatchSpec(std::string_view i_spec)
MatchSpec::MatchSpec(std::string_view i_spec, ChannelContext& channel_context)
: spec(i_spec)
{
parse();
parse(channel_context);
}

std::tuple<std::string, std::string> MatchSpec::parse_version_and_build(const std::string& s)
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace mamba
}
}

void MatchSpec::parse()
void MatchSpec::parse(ChannelContext& channel_context)
{
LOG_INFO << "Parsing MatchSpec " << spec;
std::string spec_str = spec;
Expand All @@ -84,7 +84,7 @@ namespace mamba
LOG_INFO << "need to expand path!";
spec_str = path_to_url(fs::absolute(env::expand_user(spec_str)).string());
}
auto& parsed_channel = make_channel(spec_str);
auto& parsed_channel = channel_context.make_channel(spec_str);

if (parsed_channel.package_filename())
{
Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/core/pinning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace mamba
{
std::string python_pin(const PrefixData& prefix_data, const std::vector<std::string>& specs)
std::string python_pin(PrefixData& prefix_data, const std::vector<std::string>& specs)
{
std::string pin = "";
std::string py_version;
Expand All @@ -30,7 +30,7 @@ namespace mamba

for (const auto& spec : specs)
{
MatchSpec ms(spec);
MatchSpec ms{spec, prefix_data.channel_context()};
if (ms.name == "python")
{
return "";
Expand Down
Loading

0 comments on commit 337db2c

Please sign in to comment.