Skip to content

Commit

Permalink
add optional python_site_packages_path in repodata
Browse files Browse the repository at this point in the history
Add support for the optional python_site_packages_path field that can
appear in repodata for python packages to specify the location of the
site-packages directory.

This optional field is defined in CEP-17.
  • Loading branch information
jjhelmus committed Nov 6, 2024
1 parent c511d5c commit 17e18a8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libmamba/ext/solv-cpp/include/solv-cpp/solvable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace solv
auto build_string() const -> std::string_view;
auto file_name() const -> std::string_view;
auto license() const -> std::string_view;
auto python_site_packages_path() const -> std::string_view;
auto md5() const -> std::string_view;
auto noarch() const -> std::string_view;
auto sha256() const -> std::string_view;
Expand Down Expand Up @@ -168,6 +169,17 @@ namespace solv
void set_license(raw_str_view str) const;
void set_license(const std::string& str) const;

/**
* Set the python_site_packages_path of the solvable.
*
* This is not used by libsolv and is purely for data storing.
*
* @note A call to @ref ObjRepoView::internalize is required for this attribute to
* be available for lookup.
*/
void set_python_site_packages_path(raw_str_view str) const;
void set_python_site_packages_path(const std::string& str) const;

/**
* Set the md5 hash of the solvable file.
*
Expand Down
15 changes: 15 additions & 0 deletions libmamba/ext/solv-cpp/src/solvable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ namespace solv
return set_license(str.c_str());
}

auto ObjSolvableViewConst::python_site_packages_path() const -> std::string_view
{
return ptr_to_strview(::solvable_lookup_str(const_cast<::Solvable*>(raw()), SOLVABLE_MEDIABASE));
}

void ObjSolvableView::set_python_site_packages_path(raw_str_view str) const
{
::solvable_set_str(raw(), SOLVABLE_MEDIABASE, str);
}

void ObjSolvableView::set_python_site_packages_path(const std::string& str) const
{
return set_python_site_packages_path(str.c_str());
}

auto ObjSolvableViewConst::md5() const -> std::string_view
{
::Id type = 0;
Expand Down
1 change: 1 addition & 0 deletions libmamba/include/mamba/specs/package_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace mamba::specs
std::string license = {};
std::string md5 = {};
std::string sha256 = {};
std::string python_site_packages_path = {};
std::string signatures = {};
std::vector<std::string> track_features = {};
std::vector<std::string> dependencies = {};
Expand Down
3 changes: 3 additions & 0 deletions libmamba/include/mamba/specs/repo_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ namespace mamba::specs
/** Optionally a SHA256 hash of the package archive. */
std::optional<std::string> sha256 = {};

/** Optionally a path to the site-packages directory. */
std::optional<std::string> python_site_packages_path = {};

/** A deprecated md5 hash. */
std::optional<std::string> legacy_bz2_md5 = {};

Expand Down
7 changes: 7 additions & 0 deletions libmamba/src/solver/libsolv/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace mamba::solver::libsolv
);
solv.set_md5(pkg.md5);
solv.set_sha256(pkg.sha256);
solv.set_python_site_packages_path(pkg.python_site_packages_path);

for (const auto& dep : pkg.dependencies)
{
Expand Down Expand Up @@ -110,6 +111,7 @@ namespace mamba::solver::libsolv
out.timestamp = s.timestamp();
out.md5 = s.md5();
out.sha256 = s.sha256();
out.python_site_packages_path = s.python_site_packages_path();
out.signatures = s.signatures();

const auto dep_to_str = [&pool](solv::DependencyId id)
Expand Down Expand Up @@ -265,6 +267,11 @@ namespace mamba::solver::libsolv
solv.set_sha256(sha256.value_unsafe());
}

if (auto python_site_packages_path = pkg["python_site_packages_path"].get_c_str(); !python_site_packages_path.error())
{
solv.set_python_site_packages_path(python_site_packages_path.value_unsafe());
}

if (auto elem = pkg["noarch"]; !elem.error())
{
if (auto val = elem.get_bool(); !val.error() && val.value_unsafe())
Expand Down
6 changes: 6 additions & 0 deletions libmamba/src/specs/package_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ namespace mamba::specs
p.dependencies,
p.constrains,
p.signatures,
p.python_site_packages_path,
p.defaulted_keys
);
}
Expand Down Expand Up @@ -383,6 +384,10 @@ namespace mamba::specs
{
j["signatures"] = pkg.signatures;
}
if (!pkg.python_site_packages_path.empty())
{
j["python_site_packages_path"] = pkg.python_site_packages_path;
}
if (pkg.dependencies.empty())
{
j["depends"] = nlohmann::json::array();
Expand Down Expand Up @@ -425,6 +430,7 @@ namespace mamba::specs
pkg.md5 = j.value("md5", "");
pkg.sha256 = j.value("sha256", "");
pkg.signatures = j.value("signatures", "");
pkg.python_site_packages_path = j.value("python_site_packages_path", "");
if (auto it = j.find("track_features"); it != j.end())
{
if (it->is_string() && !it->get<std::string_view>().empty())
Expand Down
2 changes: 2 additions & 0 deletions libmamba/src/specs/repo_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace mamba::specs
j["subdir"] = p.subdir;
j["md5"] = p.md5;
j["sha256"] = p.sha256;
j["python_site_packages_path"] = p.python_site_packages_path;
j["legacy_bz2_md5"] = p.legacy_bz2_md5;
j["legacy_bz2_size"] = p.legacy_bz2_size;
j["size"] = p.size;
Expand Down Expand Up @@ -50,6 +51,7 @@ namespace mamba::specs
deserialize_maybe_missing(j, "subdir", p.subdir);
deserialize_maybe_missing(j, "md5", p.md5);
deserialize_maybe_missing(j, "sha256", p.sha256);
deserialize_maybe_missing(j, "python_site_packages_path", p.python_site_packages_path);
deserialize_maybe_missing(j, "legacy_bz2_md5", p.legacy_bz2_md5);
deserialize_maybe_missing(j, "legacy_bz2_size", p.legacy_bz2_size);
deserialize_maybe_missing(j, "size", p.size);
Expand Down

0 comments on commit 17e18a8

Please sign in to comment.