Skip to content

Commit 17e18a8

Browse files
committed
add optional python_site_packages_path in repodata
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.
1 parent c511d5c commit 17e18a8

File tree

7 files changed

+46
-0
lines changed

7 files changed

+46
-0
lines changed

libmamba/ext/solv-cpp/include/solv-cpp/solvable.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace solv
5353
auto build_string() const -> std::string_view;
5454
auto file_name() const -> std::string_view;
5555
auto license() const -> std::string_view;
56+
auto python_site_packages_path() const -> std::string_view;
5657
auto md5() const -> std::string_view;
5758
auto noarch() const -> std::string_view;
5859
auto sha256() const -> std::string_view;
@@ -168,6 +169,17 @@ namespace solv
168169
void set_license(raw_str_view str) const;
169170
void set_license(const std::string& str) const;
170171

172+
/**
173+
* Set the python_site_packages_path of the solvable.
174+
*
175+
* This is not used by libsolv and is purely for data storing.
176+
*
177+
* @note A call to @ref ObjRepoView::internalize is required for this attribute to
178+
* be available for lookup.
179+
*/
180+
void set_python_site_packages_path(raw_str_view str) const;
181+
void set_python_site_packages_path(const std::string& str) const;
182+
171183
/**
172184
* Set the md5 hash of the solvable file.
173185
*

libmamba/ext/solv-cpp/src/solvable.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ namespace solv
206206
return set_license(str.c_str());
207207
}
208208

209+
auto ObjSolvableViewConst::python_site_packages_path() const -> std::string_view
210+
{
211+
return ptr_to_strview(::solvable_lookup_str(const_cast<::Solvable*>(raw()), SOLVABLE_MEDIABASE));
212+
}
213+
214+
void ObjSolvableView::set_python_site_packages_path(raw_str_view str) const
215+
{
216+
::solvable_set_str(raw(), SOLVABLE_MEDIABASE, str);
217+
}
218+
219+
void ObjSolvableView::set_python_site_packages_path(const std::string& str) const
220+
{
221+
return set_python_site_packages_path(str.c_str());
222+
}
223+
209224
auto ObjSolvableViewConst::md5() const -> std::string_view
210225
{
211226
::Id type = 0;

libmamba/include/mamba/specs/package_info.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace mamba::specs
4646
std::string license = {};
4747
std::string md5 = {};
4848
std::string sha256 = {};
49+
std::string python_site_packages_path = {};
4950
std::string signatures = {};
5051
std::vector<std::string> track_features = {};
5152
std::vector<std::string> dependencies = {};

libmamba/include/mamba/specs/repo_data.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ namespace mamba::specs
6363
/** Optionally a SHA256 hash of the package archive. */
6464
std::optional<std::string> sha256 = {};
6565

66+
/** Optionally a path to the site-packages directory. */
67+
std::optional<std::string> python_site_packages_path = {};
68+
6669
/** A deprecated md5 hash. */
6770
std::optional<std::string> legacy_bz2_md5 = {};
6871

libmamba/src/solver/libsolv/helpers.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace mamba::solver::libsolv
6969
);
7070
solv.set_md5(pkg.md5);
7171
solv.set_sha256(pkg.sha256);
72+
solv.set_python_site_packages_path(pkg.python_site_packages_path);
7273

7374
for (const auto& dep : pkg.dependencies)
7475
{
@@ -110,6 +111,7 @@ namespace mamba::solver::libsolv
110111
out.timestamp = s.timestamp();
111112
out.md5 = s.md5();
112113
out.sha256 = s.sha256();
114+
out.python_site_packages_path = s.python_site_packages_path();
113115
out.signatures = s.signatures();
114116

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

270+
if (auto python_site_packages_path = pkg["python_site_packages_path"].get_c_str(); !python_site_packages_path.error())
271+
{
272+
solv.set_python_site_packages_path(python_site_packages_path.value_unsafe());
273+
}
274+
268275
if (auto elem = pkg["noarch"]; !elem.error())
269276
{
270277
if (auto val = elem.get_bool(); !val.error() && val.value_unsafe())

libmamba/src/specs/package_info.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ namespace mamba::specs
337337
p.dependencies,
338338
p.constrains,
339339
p.signatures,
340+
p.python_site_packages_path,
340341
p.defaulted_keys
341342
);
342343
}
@@ -383,6 +384,10 @@ namespace mamba::specs
383384
{
384385
j["signatures"] = pkg.signatures;
385386
}
387+
if (!pkg.python_site_packages_path.empty())
388+
{
389+
j["python_site_packages_path"] = pkg.python_site_packages_path;
390+
}
386391
if (pkg.dependencies.empty())
387392
{
388393
j["depends"] = nlohmann::json::array();
@@ -425,6 +430,7 @@ namespace mamba::specs
425430
pkg.md5 = j.value("md5", "");
426431
pkg.sha256 = j.value("sha256", "");
427432
pkg.signatures = j.value("signatures", "");
433+
pkg.python_site_packages_path = j.value("python_site_packages_path", "");
428434
if (auto it = j.find("track_features"); it != j.end())
429435
{
430436
if (it->is_string() && !it->get<std::string_view>().empty())

libmamba/src/specs/repo_data.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace mamba::specs
2222
j["subdir"] = p.subdir;
2323
j["md5"] = p.md5;
2424
j["sha256"] = p.sha256;
25+
j["python_site_packages_path"] = p.python_site_packages_path;
2526
j["legacy_bz2_md5"] = p.legacy_bz2_md5;
2627
j["legacy_bz2_size"] = p.legacy_bz2_size;
2728
j["size"] = p.size;
@@ -50,6 +51,7 @@ namespace mamba::specs
5051
deserialize_maybe_missing(j, "subdir", p.subdir);
5152
deserialize_maybe_missing(j, "md5", p.md5);
5253
deserialize_maybe_missing(j, "sha256", p.sha256);
54+
deserialize_maybe_missing(j, "python_site_packages_path", p.python_site_packages_path);
5355
deserialize_maybe_missing(j, "legacy_bz2_md5", p.legacy_bz2_md5);
5456
deserialize_maybe_missing(j, "legacy_bz2_size", p.legacy_bz2_size);
5557
deserialize_maybe_missing(j, "size", p.size);

0 commit comments

Comments
 (0)