Skip to content

Commit 339715a

Browse files
jjhelmusAntoinePrvjjerphan
authored
feat: Support for optional python_site_packages_path in repodata (#3579)
Co-authored-by: AntoinePrv <[email protected]> Co-authored-by: Julien Jerphanion <[email protected]>
1 parent d5c2a83 commit 339715a

File tree

21 files changed

+287
-33
lines changed

21 files changed

+287
-33
lines changed

dev/environment-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies:
2929
# micromamba test dependencies
3030
- python
3131
- mitmproxy
32+
- bcrypt==4.0.1 # An indirect dependency pin due to failures on MacOS
3233
- pytest >=7.3.0
3334
- pytest-asyncio
3435
- pytest-timeout

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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ 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+
215+
void ObjSolvableView::set_python_site_packages_path(raw_str_view str) const
216+
{
217+
::solvable_set_str(raw(), SOLVABLE_MEDIABASE, str);
218+
}
219+
220+
void ObjSolvableView::set_python_site_packages_path(const std::string& str) const
221+
{
222+
return set_python_site_packages_path(str.c_str());
223+
}
224+
209225
auto ObjSolvableViewConst::md5() const -> std::string_view
210226
{
211227
::Id type = 0;

libmamba/ext/solv-cpp/tests/src/test_solvable.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace
4343
solv.set_build_string("build");
4444
solv.set_file_name("file.tar.gz");
4545
solv.set_license("MIT");
46+
solv.set_python_site_packages_path("dummy_pspp");
4647
solv.set_md5("6f29ba77e8b03b191c9d667f331bf2a0");
4748
solv.set_sha256("ecde63af23e0d49c0ece19ec539d873ea408a6f966d3126994c6d33ae1b9d3f7");
4849
solv.set_signatures(
@@ -62,6 +63,7 @@ namespace
6263
REQUIRE(solv.build_string() == "");
6364
REQUIRE(solv.file_name() == "");
6465
REQUIRE(solv.license() == "");
66+
REQUIRE(solv.python_site_packages_path() == "");
6567
REQUIRE(solv.md5() == "");
6668
REQUIRE(solv.sha256() == "");
6769
REQUIRE(solv.signatures() == "");
@@ -83,6 +85,7 @@ namespace
8385
REQUIRE(solv.build_string() == "build");
8486
REQUIRE(solv.file_name() == "file.tar.gz");
8587
REQUIRE(solv.license() == "MIT");
88+
REQUIRE(solv.python_site_packages_path() == "dummy_pspp");
8689
REQUIRE(solv.md5() == "6f29ba77e8b03b191c9d667f331bf2a0");
8790
REQUIRE(
8891
solv.sha256() == "ecde63af23e0d49c0ece19ec539d873ea408a6f966d3126994c6d33ae1b9d3f7"

libmamba/include/mamba/core/transaction.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,16 @@ namespace mamba
8282
History::UserRequest m_history_entry;
8383
solver::Solution m_solution;
8484

85+
/** Pair of current Python version, and potential update. */
8586
std::pair<std::string, std::string> m_py_versions;
87+
/**
88+
* The potential "python_site_package" entry.
89+
*
90+
* Found in the the new or installed python interpreter.
91+
* Key is added as part of CEP-17.
92+
* https://conda.org/learn/ceps/cep-0017
93+
*/
94+
std::string m_python_site_packages_path;
8695
std::vector<specs::MatchSpec> m_requested_specs;
8796

8897
MTransaction(const CommandParams& command_params, MultiPackageCache&);

libmamba/include/mamba/specs/package_info.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace mamba::specs
4747
std::string license = {};
4848
std::string md5 = {};
4949
std::string sha256 = {};
50+
std::string python_site_packages_path = {};
5051
std::string signatures = {};
5152
std::vector<std::string> track_features = {};
5253
std::vector<std::string> dependencies = {};

libmamba/include/mamba/specs/repo_data.hpp

Lines changed: 3 additions & 0 deletions
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/core/query.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ namespace mamba
325325
fmt::print(out, fmtstring, "Track Features", fmt::join(pkg.track_features, ","));
326326
}
327327

328+
if (!pkg.python_site_packages_path.empty())
329+
{
330+
fmt::print(out, fmtstring, "Site-packages", pkg.python_site_packages_path);
331+
}
332+
328333
// std::cout << fmt::format<char>(
329334
// " {:<15} {:%Y-%m-%d %H:%M:%S} UTC\n", "Timestamp", fmt::gmtime(pkg.timestamp));
330335

libmamba/src/core/transaction.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@
2727
#include "mamba/core/repo_checker_store.hpp"
2828
#include "mamba/core/thread_utils.hpp"
2929
#include "mamba/core/transaction.hpp"
30-
#include "mamba/core/util_os.hpp"
3130
#include "mamba/solver/libsolv/database.hpp"
3231
#include "mamba/specs/match_spec.hpp"
33-
#include "mamba/util/environment.hpp"
3432
#include "mamba/util/variant_cmp.hpp"
3533

36-
#include "./link.hpp"
37-
#include "./transaction_context.hpp"
3834
#include "solver/helpers.hpp"
3935

36+
#include "link.hpp"
4037
#include "progress_bar_impl.hpp"
38+
#include "transaction_context.hpp"
4139

4240
namespace mamba
4341
{
@@ -110,19 +108,22 @@ namespace mamba
110108
return out;
111109
}
112110

113-
auto
114-
find_python_version(const solver::Solution& solution, const solver::libsolv::Database& database)
115-
-> std::pair<std::string, std::string>
111+
auto find_python_versions_and_site_packages(
112+
const solver::Solution& solution,
113+
const solver::libsolv::Database& database
114+
) -> std::pair<std::pair<std::string, std::string>, std::string>
116115
{
117116
// We need to find the python version that will be there after this
118117
// Transaction is finished in order to compile the noarch packages correctly,
119118

120119
// We need to look into installed packages in case we are not installing a new python
121120
// version but keeping the current one.
122121
// Could also be written in term of PrefixData.
122+
std::string python_site_packages_path = {};
123123
std::string installed_py_ver = {};
124124
if (auto pkg = installed_python(database))
125125
{
126+
python_site_packages_path = pkg->python_site_packages_path;
126127
installed_py_ver = pkg->version;
127128
LOG_INFO << "Found python in installed packages " << installed_py_ver;
128129
}
@@ -131,9 +132,13 @@ namespace mamba
131132
if (auto py = solver::find_new_python_in_solution(solution))
132133
{
133134
new_py_ver = py->get().version;
135+
python_site_packages_path = py->get().python_site_packages_path;
134136
}
135137

136-
return { std::move(new_py_ver), std::move(installed_py_ver) };
138+
return {
139+
{ std::move(new_py_ver), std::move(installed_py_ver) },
140+
std::move(python_site_packages_path),
141+
};
137142
}
138143
}
139144

@@ -213,7 +218,10 @@ namespace mamba
213218
Console::instance().json_write({ { "PREFIX", ctx.prefix_params.target_prefix.string() } });
214219
}
215220

216-
m_py_versions = find_python_version(m_solution, database);
221+
std::tie(
222+
m_py_versions,
223+
m_python_site_packages_path
224+
) = find_python_versions_and_site_packages(m_solution, database);
217225
}
218226

219227
MTransaction::MTransaction(
@@ -258,7 +266,10 @@ namespace mamba
258266
[&](const auto& item) { m_requested_specs.push_back(item.spec); }
259267
);
260268

261-
m_py_versions = find_python_version(m_solution, database);
269+
std::tie(
270+
m_py_versions,
271+
m_python_site_packages_path
272+
) = find_python_versions_and_site_packages(m_solution, database);
262273

263274
// if no action required, don't even start logging them
264275
if (!empty())
@@ -303,7 +314,10 @@ namespace mamba
303314
[](specs::PackageInfo&& pkg) { return solver::Solution::Install{ std::move(pkg) }; }
304315
);
305316

306-
m_py_versions = find_python_version(m_solution, database);
317+
std::tie(
318+
m_py_versions,
319+
m_python_site_packages_path
320+
) = find_python_versions_and_site_packages(m_solution, database);
307321
}
308322

309323
class TransactionRollback
@@ -395,7 +409,12 @@ namespace mamba
395409
};
396410

397411
TransactionRollback rollback;
398-
TransactionContext transaction_context(ctx.transaction_params(), m_py_versions, m_requested_specs);
412+
TransactionContext transaction_context(
413+
ctx.transaction_params(),
414+
m_py_versions,
415+
m_python_site_packages_path,
416+
m_requested_specs
417+
);
399418

400419
for (const specs::PackageInfo& pkg : m_solution.packages_to_remove())
401420
{

libmamba/src/core/transaction_context.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010
#include <reproc++/drain.hpp>
1111

12-
#include "mamba/core/error_handling.hpp"
1312
#include "mamba/core/output.hpp"
1413
#include "mamba/util/environment.hpp"
1514
#include "mamba/util/string.hpp"
1615

17-
#include "./transaction_context.hpp"
16+
#include "transaction_context.hpp"
1817

1918
extern const char data_compile_pyc_py[];
2019

@@ -91,17 +90,28 @@ namespace mamba
9190
}
9291
}
9392

94-
TransactionContext::PythonParams
95-
build_python_params(std::pair<std::string, std::string> py_versions)
93+
TransactionContext::PythonParams build_python_params(
94+
std::pair<std::string, std::string> py_versions,
95+
std::string python_site_packages_path
96+
)
9697
{
98+
if (py_versions.first.empty())
99+
{
100+
return {};
101+
}
102+
97103
TransactionContext::PythonParams res;
98-
if (py_versions.first.size() != 0)
104+
res.has_python = true;
105+
res.python_version = std::move(py_versions.first);
106+
res.old_python_version = std::move(py_versions.second);
107+
res.short_python_version = compute_short_python_version(res.python_version);
108+
res.python_path = get_python_short_path(res.short_python_version);
109+
if (!python_site_packages_path.empty())
110+
{
111+
res.site_packages_path = python_site_packages_path;
112+
}
113+
else
99114
{
100-
res.has_python = true;
101-
res.python_version = std::move(py_versions.first);
102-
res.old_python_version = std::move(py_versions.second);
103-
res.short_python_version = compute_short_python_version(res.python_version);
104-
res.python_path = get_python_short_path(res.short_python_version);
105115
res.site_packages_path = get_python_site_packages_short_path(res.short_python_version);
106116
}
107117
return res;
@@ -110,10 +120,13 @@ namespace mamba
110120
TransactionContext::TransactionContext(
111121
TransactionParams transaction_params,
112122
std::pair<std::string, std::string> py_versions,
123+
std::string python_site_packages_path,
113124
std::vector<specs::MatchSpec> lrequested_specs
114125
)
115126
: m_transaction_params(std::move(transaction_params))
116-
, m_python_params(build_python_params(std::move(py_versions)))
127+
, m_python_params(
128+
build_python_params(std::move(py_versions), std::move(python_site_packages_path))
129+
)
117130
, m_requested_specs(std::move(lrequested_specs))
118131
{
119132
if (m_python_params.python_version.size() == 0)

0 commit comments

Comments
 (0)