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

Explcit transaction duplicate code #3138

Merged
merged 2 commits into from
Jan 18, 2024
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
3 changes: 0 additions & 3 deletions libmamba/include/mamba/api/install.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ namespace mamba

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

std::tuple<std::vector<specs::PackageInfo>, std::vector<specs::MatchSpec>>
parse_urls_to_package_info(const std::vector<std::string>& urls);

inline void to_json(nlohmann::json&, const other_pkg_mgr_spec&)
{
}
Expand Down
40 changes: 0 additions & 40 deletions libmamba/src/api/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,46 +342,6 @@ namespace mamba
return result;
}

std::tuple<std::vector<specs::PackageInfo>, std::vector<specs::MatchSpec>>
parse_urls_to_package_info(const std::vector<std::string>& urls)
{
std::vector<specs::PackageInfo> pi_result;
std::vector<specs::MatchSpec> ms_result;
for (auto& u : urls)
{
if (util::strip(u).size() == 0)
{
continue;
}
std::size_t hash = u.find_first_of('#');
auto ms = specs::MatchSpec::parse(u.substr(0, hash));
specs::PackageInfo p(ms.name().str());
p.package_url = ms.url();
p.build_string = ms.build_string().str();
p.version = ms.version().str();
if (ms.channel().has_value())
{
p.channel = ms.channel()->location();
if (!ms.channel()->platform_filters().empty())
{
// There must be only one since we are expecting URLs
assert(ms.channel()->platform_filters().size() == 1);
p.subdir = ms.channel()->platform_filters().front();
}
}
p.filename = ms.filename();

if (hash != std::string::npos)
{
p.md5 = u.substr(hash + 1);
ms.set_md5(std::string(u.substr(hash + 1)));
}
pi_result.push_back(p);
ms_result.push_back(ms);
}
return std::make_tuple(pi_result, ms_result);
}

bool operator==(const other_pkg_mgr_spec& s1, const other_pkg_mgr_spec& s2)
{
return (s1.pkg_mgr == s2.pkg_mgr) && (s1.deps == s2.deps) && (s1.cwd == s2.cwd);
Expand Down
17 changes: 14 additions & 3 deletions libmamba/src/specs/package_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <nlohmann/json.hpp>

#include "mamba/specs/archive.hpp"
#include "mamba/specs/conda_url.hpp"
#include "mamba/specs/package_info.hpp"
#include "mamba/util/string.hpp"
#include "mamba/util/url_manip.hpp"
Expand All @@ -30,13 +31,23 @@ namespace mamba::specs
);
};

if (!has_archive_extension(spec))
{
fail_parse();
}

auto out = PackageInfo();
auto [_, pkg] = util::rsplit_once(spec, '/');
out.filename = pkg;
// TODO decide on the bet way to group filename/channel/subdir/package_url all at once
out.package_url = util::path_or_url_to_url(spec);
auto url = CondaURL::parse(out.package_url);
out.filename = url.package();
url.clear_package();
out.subdir = url.platform_name();
url.clear_platform();
out.channel = util::rstrip(url.str(), '/');

// Build string
auto [head, tail] = util::rsplit_once(strip_archive_extension(pkg), '-');
auto [head, tail] = util::rsplit_once(strip_archive_extension(out.filename), '-');
out.build_string = tail;
if (!head.has_value())
{
Expand Down
4 changes: 4 additions & 0 deletions libmamba/tests/src/specs/test_package_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ TEST_SUITE("specs::package_info")
CHECK_EQ(pkg.filename, "pkg-6.4-bld.conda");
CHECK_EQ(pkg.package_url, url);
CHECK_EQ(pkg.md5, "");
CHECK_EQ(pkg.subdir, "linux-64");
CHECK_EQ(pkg.channel, "https://conda.anaconda.org/conda-forge");
}

SUBCASE("https://conda.anaconda.org/conda-forge/linux-64/pkg-6.4-bld.conda#7dbaa197d7ba6032caf7ae7f32c1efa0"
Expand All @@ -48,6 +50,8 @@ TEST_SUITE("specs::package_info")
CHECK_EQ(pkg.filename, "pkg-6.4-bld.conda");
CHECK_EQ(pkg.package_url, url.substr(0, url.rfind('#')));
CHECK_EQ(pkg.md5, url.substr(url.rfind('#') + 1));
CHECK_EQ(pkg.subdir, "linux-64");
CHECK_EQ(pkg.channel, "https://conda.anaconda.org/conda-forge");
}
}

Expand Down
6 changes: 3 additions & 3 deletions micromamba/src/constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ construct(Configuration& config, const fs::u8path& prefix, bool extract_conda_pk
fs::u8path pkgs_dir = prefix / "pkgs";
fs::u8path urls_file = pkgs_dir / "urls";

auto [package_details, _] = detail::parse_urls_to_package_info(read_lines(urls_file));

for (const auto& pkg_info : package_details)
for (const auto& raw_url : read_lines(urls_file))
{
auto pkg_info = specs::PackageInfo::from_url(raw_url);

fs::u8path entry = pkgs_dir / pkg_info.filename;
LOG_TRACE << "Extracting " << pkg_info.filename << std::endl;
std::cout << "Extracting " << pkg_info.filename << std::endl;
Expand Down
Loading