Skip to content

Commit

Permalink
Add uninstall subcommand (#112)
Browse files Browse the repository at this point in the history
* Add uninstall subcommand.

* Add support for removing environment directories

* Create _is_subdir function

* Specify which .condarc files to remove

* Clean parent directories of config files

* Rename ambiguous --clean to --conda-clean

* Add doc strings

* Clarify use of user and home in --remove-condarcs

* Use target path to detect Windows reg keys

* Improve HKEY handling

* Do not support environment directories (menuinst may cause problems

* Run menuinst separately from conda remove

* Add support for environments directories

* Determine base prefix for menuinst

* Use CONDA_ROOT_PREFIX instead of MENUINST_BASE_PREFIX

* Change homedir to Path.home()

* Replace deprecated native_path_to_unix with win_path_to_unix

* Remove empty parent directories of pkgs_dirs and cache directories

* Consolidate parent removal functions

* Add tests

* Fix sentinel string for csh and tcsh

* Remove pkgs directory when only urls files are present

* Check that parent directories are removed for init reverse tests

* Pre-create directories for menuinst on Windows

* Force mocking user cache directory

* Skip LongPathsEnabled registry key

* Add conda to recipe test requirements

* Update documentation

* Replace deprecated List type

* Add news file

* Interpret conda.exe -m as conda.exe python -m to call run_plan_elevated

* Use sudo where needed for test_uninstallation_remove_condarcs

* Add a note that some files may be left behind with sudo

* Add missing XDG_DATA_HOME location for Linux shortcuts

* Convert path into string for init reverse plans

* Use different condarc locations for sudo and non-sudo runs

* Do not write directly into /root

* Always write parents on mkdir

* Catch PermissionError on exists for /root/.condarc

* Use sudo -E

* Instruct to use sudo -E in README

* Create wrapper function to run uninstaller in tests

* Make uninstall a subcommand of constructor

* Use removeprefix

* Check for directory before checking for file/symlink

* Ensure that ON_CI=False for CI="0"

* Patch HOMEDRIVE and HOMEPATH

* Use conda environment fixtures

* Add test_uninstallation_keep_config_dir

* Set MENUINST_BASE_PREFIX for menuinst test

* Simplify _is_subdir function

* Warn about limited softlink support

* Do not resolve paths in _remove_config_file_and_parents

* Do not use conda fixtures for menuinst tests

* Elaborate on lack of symlink support.

* Rename --remove-caches to --remove-conda-caches

* Expand variables for args.prefix

* Ensure that mutually exclusive group is required without a subcommand

* Clarify how --prefix is enforced

* Remove empty parents only when created by conda

* Return earlier when removing parents of config files

* Do not resolve uninstall_prefix

* Remove notices cache with package caches

* Use XDG-style conventions for constructor uninstall CLI arguments

* Fix typo in README

* Apply suggestions from code review

Co-authored-by: jaimergp <[email protected]>

* Update src/entry_point.py

Co-authored-by: jaimergp <[email protected]>

---------

Co-authored-by: jaimergp <[email protected]>
  • Loading branch information
marcoesters and jaimergp authored Nov 27, 2024
1 parent 666eed0 commit dce4ddb
Show file tree
Hide file tree
Showing 8 changed files with 972 additions and 65 deletions.
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,65 @@ It also adds new subcommands not available on the regular `conda`:
This subcommand is mainly used by the installers generated with `constructor`.

```bash
$ conda.exe constructor --help
usage: conda.exe constructor [-h] --prefix PREFIX [--extract-conda-pkgs] [--extract-tarball] [--make-menus [PKG_NAME ...]] [--rm-menus]
usage: conda.exe constructor [-h] [--prefix PREFIX] [--num-processors N]
[--extract-conda-pkgs | --extract-tarball | --make-menus [PKG_NAME ...] | --rm-menus]
{uninstall} ...

constructor helper subcommand

optional arguments:
positional arguments:
{uninstall}

options:
-h, --help show this help message and exit
--prefix PREFIX path to the conda environment to operate on
--num-processors N Number of processors to use with --extract-conda-pkgs. Value must be int between 0 (auto) and the
number of processors. Defaults to 3.
--extract-conda-pkgs extract conda packages found in prefix/pkgs
--extract-tarball extract tarball from stdin
--make-menus [PKG_NAME ...]
create menu items for the given packages; if none are given, create menu items for all packages in the environment specified by --prefix
create menu items for the given packages; if none are given, create menu items for all packages
in the environment specified by --prefix
--rm-menus remove menu items for all packages in the environment specified by --prefix
```
### `conda.exe constructor uninstall`
This subcommand can be used to uninstall a base environment and all sub-environments, including
entire Miniconda/Miniforge installations.
It is also possible to remove environments directories created by `conda create`. This feature is
useful if `envs_dirs` is set inside `.condarc` file.
There are several options to remove configuration and cache files:
```bash
$ conda.exe constructor uninstall [-h] --prefix PREFIX [--conda-clean] [--remove-config-files {user,system,all}]
[--remove-conda-caches]
```
- `--prefix` (required): Path to the conda directory to uninstall.
- `--remove-caches`:
Removes the notices cache and runs `conda --clean --all` to clean package caches outside the
installation directory. This is especially useful when `pkgs_dirs` is set in a `.condarc` file.
Not recommended with multiple conda installations when softlinks are enabled.
- `--remove-config-files {user,system,all}`:
Removes all `.condarc` files. `user` removes the files inside the current user's home directory
and `system` removes all files outside of that directory. Not recommended when multiple conda
installations are on the system or when running on an environments directory.
- `--remove-user-data`:
Removes the `~/.conda` directory. Not recommended when multiple conda installations are installed
on the system or when running on an environments directory.
> [!IMPORTANT]
> Use `sudo -E` if removing system-level configuration files requires superuser privileges.
> `conda` relies on environment variables like `HOME` and `XDG_CONFIG_HOME` when detecting
> configuration files, which may be overwritten with just `sudo`.
> This can cause files to be left behind.
> [!WARNING]
> Support for softlinks is still untested.
> The uninstaller will only perform unlink operations and not delete any files the links point to.
### `conda.exe python`
This subcommand provides access to the Python interpreter bundled in the conda-standalone
Expand Down
20 changes: 20 additions & 0 deletions news/112-add-uninstall-subcommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* Add `uninstall` subcommand, which uninstalls all environments inside a prefix and reverses
`conda init` commands. It also for deleting cache directories and configuration files. (#112)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
3 changes: 2 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ requirements:

test:
requires:
- pytest
- conda
- menuinst >={{ menuinst_lower_bound }}
- pytest
- ruamel.yaml
source_files:
- tests
Expand Down
Loading

0 comments on commit dce4ddb

Please sign in to comment.