diff --git a/conda_libmamba_solver/state.py b/conda_libmamba_solver/state.py index dd44ed22..9bb1cb3a 100644 --- a/conda_libmamba_solver/state.py +++ b/conda_libmamba_solver/state.py @@ -544,21 +544,28 @@ def early_exit(self) -> Dict[str, PackageRecord]: """ sis = self.solver_input_state if sis.is_removing: - not_installed = [ - spec for name, spec in sis.requested.items() if name not in sis.installed - ] + # Make sure that requested packages to be removed match + # an installed record. Otherwise, raise an error. + # When 'remove --force' is set, remove the package without solving. + if sis.force_remove: + force_remove_solution = self.current_solution + not_installed = [] + for name, spec in sis.requested.items(): + for record in sis.installed.values(): + if spec.match(record): + if sis.force_remove: + force_remove_solution.remove(record) + break + else: + not_installed.append(spec) + if not_installed: exc = PackagesNotFoundError(not_installed) exc.allow_retry = False raise exc if sis.force_remove: - for name, spec in sis.requested.items(): - for record in sis.installed.values(): - if spec.match(record): - self.records.pop(name) - break - return self.current_solution + return force_remove_solution if sis.update_modifier.SPECS_SATISFIED_SKIP_SOLVE and not sis.is_removing: for name, spec in sis.requested.items(): diff --git a/news/435-remove-wildcard b/news/435-remove-wildcard new file mode 100644 index 00000000..289a11f8 --- /dev/null +++ b/news/435-remove-wildcard @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Allow wildcards in package names for `conda remove` (e.g. `conda remove "python-*"`). (#434 via #435) + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test_solvers.py b/tests/test_solvers.py index 5539524d..9d7a0a95 100644 --- a/tests/test_solvers.py +++ b/tests/test_solvers.py @@ -15,7 +15,6 @@ from conda.common.compat import on_linux, on_win from conda.common.io import env_var from conda.core.prefix_data import PrefixData, get_python_version_for_prefix -from conda.exceptions import DryRunExit from conda.testing.integration import ( Commands, make_temp_env, @@ -26,7 +25,6 @@ from conda_libmamba_solver import LibMambaSolver from conda_libmamba_solver.exceptions import LibMambaUnsatisfiableError -from conda_libmamba_solver.mamba_utils import mamba_version from .utils import conda_subprocess