Skip to content

Commit

Permalink
Add more solver tests and other small features (#3198)
Browse files Browse the repository at this point in the history
* Add clean_dependencies to Request::Update

* Allow pins without installed repo

* Add more solver tests

* Filename repodata fallback

* Fix repodata test

* Add channel specific solver test

* Add solver conflict test
  • Loading branch information
AntoinePrv authored Feb 22, 2024
1 parent 6d535ea commit e276fa3
Show file tree
Hide file tree
Showing 6 changed files with 682 additions and 48 deletions.
1 change: 1 addition & 0 deletions libmamba/include/mamba/solver/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace mamba::solver
struct Update
{
specs::MatchSpec spec;
bool clean_dependencies = true;
};

/** Instruct to update all installed packages. */
Expand Down
48 changes: 36 additions & 12 deletions libmamba/src/solver/libsolv/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,20 @@ namespace mamba::solver::libsolv
) -> bool
{
// Not available from RepoDataPackage
solv.set_file_name(filename);
solv.set_url((repo_url / filename).str(specs::CondaURL::Credentials::Show));
solv.set_channel(repo_url_str);

solv.set_file_name(filename);
if (auto fn = pkg["fn"].get_string(); !fn.error())
{
solv.set_name(fn.value_unsafe());
}
else
{
// Fallback from key entry
solv.set_file_name(filename);
}

if (auto name = pkg["name"].get_string(); !name.error())
{
solv.set_name(name.value_unsafe());
Expand Down Expand Up @@ -767,22 +777,29 @@ namespace mamba::solver::libsolv
mamba_error_code::incorrect_usage
);
}
auto installed = pool.installed_repo();
if (!installed.has_value())
auto installed = [&]() -> solv::ObjRepoView
{
return make_unexpected(
fmt::format(R"("Cannot add pin "{}" without a repo of installed packages")", pin.str()),
mamba_error_code::incorrect_usage
);
}
if (auto repo = pool.installed_repo())
{
return *repo;
}
// If the installed repo does not exists, we can safely create it because this is
// called right before the solve function.
// If it gets modified latter on the pin should not interfere with user packages.
// If it gets overriden this it is not a problem for the solve because pins are added
// on each solve.
auto [id, repo] = pool.add_repo("installed");
pool.set_installed_repo(id);
return repo;
}();

return pool_add_matchspec(pool, pin, params)
.transform(
[&](solv::DependencyId cons)
{
// Add dummy solvable with a constraint on the pin (not installed if not
// present)
auto [cons_solv_id, cons_solv] = installed->add_solvable();
auto [cons_solv_id, cons_solv] = installed.add_solvable();
const std::string cons_solv_name = fmt::format(
"pin-{}",
util::generate_random_alphanumeric_string(10)
Expand All @@ -802,7 +819,7 @@ namespace mamba::solver::libsolv

// Necessary for attributes to be properly stored
// TODO move this at the end of all job requests
installed->internalize();
installed.internalize();

return cons_solv;
}
Expand Down Expand Up @@ -1221,12 +1238,19 @@ namespace mamba::solver::libsolv
.transform(
[&](auto id)
{
auto const clean_deps = job.clean_dependencies ? SOLVER_CLEANDEPS : 0;
// TODO: ignoring update specs here for now
if (!job.spec.is_simple())
{
raw_jobs.push_back(SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES, id);
raw_jobs.push_back(
SOLVER_INSTALL | SOLVER_SOLVABLE_PROVIDES | clean_deps,
id
);
}
raw_jobs.push_back(SOLVER_UPDATE | SOLVER_SOLVABLE_PROVIDES, id);
raw_jobs.push_back(
SOLVER_UPDATE | SOLVER_SOLVABLE_PROVIDES | clean_deps,
id
);
}
);
}
Expand Down
66 changes: 33 additions & 33 deletions libmamba/tests/data/repodata/conda-forge-numpy-linux-64.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": {
"_libgcc_mutex-0.1-conda_forge": {
"_libgcc_mutex-0.1-conda_forge.tar.bz2": {
"build": "conda_forge",
"build_number": 0,
"build_string": "conda_forge",
Expand All @@ -18,7 +18,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2",
"version": "0.1"
},
"_openmp_mutex-4.5-2_gnu": {
"_openmp_mutex-4.5-2_gnu.tar.bz2": {
"build": "2_gnu",
"build_number": 16,
"build_string": "2_gnu",
Expand All @@ -41,7 +41,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2",
"version": "4.5"
},
"libffi-3.4.2-h7f98852_5": {
"libffi-3.4.2-h7f98852_5.tar.bz2": {
"build": "h7f98852_5",
"build_number": 5,
"build_string": "h7f98852_5",
Expand All @@ -61,7 +61,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libffi-3.4.2-h7f98852_5.tar.bz2",
"version": "3.4.2"
},
"xz-5.2.6-h166bdaf_0": {
"xz-5.2.6-h166bdaf_0.tar.bz2": {
"build": "h166bdaf_0",
"build_number": 0,
"build_string": "h166bdaf_0",
Expand All @@ -83,7 +83,7 @@
}
},
"packages.conda": {
"bzip2-1.0.8-hd590300_5": {
"bzip2-1.0.8-hd590300_5.conda": {
"build": "hd590300_5",
"build_number": 5,
"build_string": "hd590300_5",
Expand All @@ -103,7 +103,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hd590300_5.conda",
"version": "1.0.8"
},
"ca-certificates-2024.2.2-hbcca054_0": {
"ca-certificates-2024.2.2-hbcca054_0.conda": {
"build": "hbcca054_0",
"build_number": 0,
"build_string": "hbcca054_0",
Expand All @@ -121,7 +121,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2024.2.2-hbcca054_0.conda",
"version": "2024.2.2"
},
"ld_impl_linux-64-2.40-h41732ed_0": {
"ld_impl_linux-64-2.40-h41732ed_0.conda": {
"build": "h41732ed_0",
"build_number": 0,
"build_string": "h41732ed_0",
Expand All @@ -141,7 +141,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.40-h41732ed_0.conda",
"version": "2.40"
},
"libblas-3.9.0-21_linux64_openblas": {
"libblas-3.9.0-21_linux64_openblas.conda": {
"build": "21_linux64_openblas",
"build_number": 21,
"build_string": "21_linux64_openblas",
Expand All @@ -167,7 +167,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libblas-3.9.0-21_linux64_openblas.conda",
"version": "3.9.0"
},
"libcblas-3.9.0-21_linux64_openblas": {
"libcblas-3.9.0-21_linux64_openblas.conda": {
"build": "21_linux64_openblas",
"build_number": 21,
"build_string": "21_linux64_openblas",
Expand All @@ -191,7 +191,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.9.0-21_linux64_openblas.conda",
"version": "3.9.0"
},
"libexpat-2.5.0-hcb278e6_1": {
"libexpat-2.5.0-hcb278e6_1.conda": {
"build": "hcb278e6_1",
"build_number": 1,
"build_string": "hcb278e6_1",
Expand All @@ -213,7 +213,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.5.0-hcb278e6_1.conda",
"version": "2.5.0"
},
"libgcc-ng-13.2.0-h807b86a_5": {
"libgcc-ng-13.2.0-h807b86a_5.conda": {
"build": "h807b86a_5",
"build_number": 5,
"build_string": "h807b86a_5",
Expand All @@ -236,7 +236,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-13.2.0-h807b86a_5.conda",
"version": "13.2.0"
},
"libgfortran-ng-13.2.0-h69a702a_5": {
"libgfortran-ng-13.2.0-h69a702a_5.conda": {
"build": "h69a702a_5",
"build_number": 5,
"build_string": "h69a702a_5",
Expand All @@ -256,7 +256,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libgfortran-ng-13.2.0-h69a702a_5.conda",
"version": "13.2.0"
},
"libgfortran5-13.2.0-ha4646dd_5": {
"libgfortran5-13.2.0-ha4646dd_5.conda": {
"build": "ha4646dd_5",
"build_number": 5,
"build_string": "ha4646dd_5",
Expand All @@ -278,7 +278,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-13.2.0-ha4646dd_5.conda",
"version": "13.2.0"
},
"libgomp-13.2.0-h807b86a_5": {
"libgomp-13.2.0-h807b86a_5.conda": {
"build": "h807b86a_5",
"build_number": 5,
"build_string": "h807b86a_5",
Expand All @@ -298,7 +298,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libgomp-13.2.0-h807b86a_5.conda",
"version": "13.2.0"
},
"liblapack-3.9.0-21_linux64_openblas": {
"liblapack-3.9.0-21_linux64_openblas.conda": {
"build": "21_linux64_openblas",
"build_number": 21,
"build_string": "21_linux64_openblas",
Expand All @@ -322,7 +322,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.9.0-21_linux64_openblas.conda",
"version": "3.9.0"
},
"libnsl-2.0.1-hd590300_0": {
"libnsl-2.0.1-hd590300_0.conda": {
"build": "hd590300_0",
"build_number": 0,
"build_string": "hd590300_0",
Expand All @@ -342,7 +342,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libnsl-2.0.1-hd590300_0.conda",
"version": "2.0.1"
},
"libopenblas-0.3.26-pthreads_h413a1c8_0": {
"libopenblas-0.3.26-pthreads_h413a1c8_0.conda": {
"build": "pthreads_h413a1c8_0",
"build_number": 0,
"build_string": "pthreads_h413a1c8_0",
Expand All @@ -366,7 +366,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.26-pthreads_h413a1c8_0.conda",
"version": "0.3.26"
},
"libsqlite-3.44.2-h2797004_0": {
"libsqlite-3.44.2-h2797004_0.conda": {
"build": "h2797004_0",
"build_number": 0,
"build_string": "h2797004_0",
Expand All @@ -387,7 +387,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.44.2-h2797004_0.conda",
"version": "3.44.2"
},
"libstdcxx-ng-13.2.0-h7e041cc_5": {
"libstdcxx-ng-13.2.0-h7e041cc_5.conda": {
"build": "h7e041cc_5",
"build_number": 5,
"build_string": "h7e041cc_5",
Expand All @@ -405,7 +405,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-13.2.0-h7e041cc_5.conda",
"version": "13.2.0"
},
"libuuid-2.38.1-h0b41bf4_0": {
"libuuid-2.38.1-h0b41bf4_0.conda": {
"build": "h0b41bf4_0",
"build_number": 0,
"build_string": "h0b41bf4_0",
Expand All @@ -425,7 +425,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.38.1-h0b41bf4_0.conda",
"version": "2.38.1"
},
"libxcrypt-4.4.36-hd590300_1": {
"libxcrypt-4.4.36-hd590300_1.conda": {
"build": "hd590300_1",
"build_number": 1,
"build_string": "hd590300_1",
Expand All @@ -445,7 +445,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda",
"version": "4.4.36"
},
"libzlib-1.2.13-hd590300_5": {
"libzlib-1.2.13-hd590300_5.conda": {
"build": "hd590300_5",
"build_number": 5,
"build_string": "hd590300_5",
Expand All @@ -467,7 +467,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.2.13-hd590300_5.conda",
"version": "1.2.13"
},
"ncurses-6.4-h59595ed_2": {
"ncurses-6.4-h59595ed_2.conda": {
"build": "h59595ed_2",
"build_number": 2,
"build_string": "h59595ed_2",
Expand All @@ -487,7 +487,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.4-h59595ed_2.conda",
"version": "6.4"
},
"numpy-1.26.4-py312heda63a1_0": {
"numpy-1.26.4-py312heda63a1_0.conda": {
"build": "py312heda63a1_0",
"build_number": 0,
"build_string": "py312heda63a1_0",
Expand Down Expand Up @@ -515,7 +515,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/numpy-1.26.4-py312heda63a1_0.conda",
"version": "1.26.4"
},
"openssl-3.2.1-hd590300_0": {
"openssl-3.2.1-hd590300_0.conda": {
"build": "hd590300_0",
"build_number": 0,
"build_string": "hd590300_0",
Expand All @@ -538,7 +538,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/openssl-3.2.1-hd590300_0.conda",
"version": "3.2.1"
},
"pip-24.0-pyhd8ed1ab_0": {
"pip-24.0-pyhd8ed1ab_0.conda": {
"build": "pyhd8ed1ab_0",
"build_number": 0,
"build_string": "pyhd8ed1ab_0",
Expand All @@ -561,7 +561,7 @@
"url": "https://conda.anaconda.org/conda-forge/noarch/pip-24.0-pyhd8ed1ab_0.conda",
"version": "24.0"
},
"python-3.12.1-hab00c5b_1_cpython": {
"python-3.12.1-hab00c5b_1_cpython.conda": {
"build": "hab00c5b_1_cpython",
"build_number": 1,
"build_string": "hab00c5b_1_cpython",
Expand Down Expand Up @@ -598,7 +598,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/python-3.12.1-hab00c5b_1_cpython.conda",
"version": "3.12.1"
},
"python_abi-3.12-4_cp312": {
"python_abi-3.12-4_cp312.conda": {
"build": "4_cp312",
"build_number": 4,
"build_string": "4_cp312",
Expand All @@ -618,7 +618,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.12-4_cp312.conda",
"version": "3.12"
},
"readline-8.2-h8228510_1": {
"readline-8.2-h8228510_1.conda": {
"build": "h8228510_1",
"build_number": 1,
"build_string": "h8228510_1",
Expand All @@ -639,7 +639,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8228510_1.conda",
"version": "8.2"
},
"setuptools-69.0.3-pyhd8ed1ab_0": {
"setuptools-69.0.3-pyhd8ed1ab_0.conda": {
"build": "pyhd8ed1ab_0",
"build_number": 0,
"build_string": "pyhd8ed1ab_0",
Expand All @@ -660,7 +660,7 @@
"url": "https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda",
"version": "69.0.3"
},
"tk-8.6.13-noxft_h4845f30_101": {
"tk-8.6.13-noxft_h4845f30_101.conda": {
"build": "noxft_h4845f30_101",
"build_number": 101,
"build_string": "noxft_h4845f30_101",
Expand All @@ -681,7 +681,7 @@
"url": "https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda",
"version": "8.6.13"
},
"tzdata-2024a-h0c530f3_0": {
"tzdata-2024a-h0c530f3_0.conda": {
"build": "h0c530f3_0",
"build_number": 0,
"build_string": "h0c530f3_0",
Expand All @@ -700,7 +700,7 @@
"url": "https://conda.anaconda.org/conda-forge/noarch/tzdata-2024a-h0c530f3_0.conda",
"version": "2024a"
},
"wheel-0.42.0-pyhd8ed1ab_0": {
"wheel-0.42.0-pyhd8ed1ab_0.conda": {
"build": "pyhd8ed1ab_0",
"build_number": 0,
"build_string": "pyhd8ed1ab_0",
Expand Down
Loading

0 comments on commit e276fa3

Please sign in to comment.