Add configurable permanent packages setting#116
Conversation
e281165 to
0a7d409
Compare
Add a `self_permanent_packages` plugin setting that lets users specify
additional packages to keep during `conda self reset` via .condarc:
plugins:
self_permanent_packages:
- anaconda-anon-usage
Closes #22
Add plugin_manager fixture to conftest.py (mirrors conda's internal fixture) and reset context after permanent_packages_condarc to prevent test pollution.
db25f81 to
90ae5ad
Compare
soapy1
left a comment
There was a problem hiding this comment.
This looks good to me. I was having some issues testing this with the conda self reset command. But it looks like the issue I was running into in testing is solved by #122. I was able to verify that this works as intended by testing with the conda self remove command instead.
| @hookimpl | ||
| def conda_settings() -> Iterable[CondaSetting]: | ||
| """Register conda-self plugin settings.""" | ||
| yield CondaSetting( |
There was a problem hiding this comment.
when I run a conda config --add plugins.self_permanent_packages anaconda-anon-usage I can see that the config has been added to my condarc. However, it does not appear when I run conda config --show-sources. Is this a bug in core conda?
There was a problem hiding this comment.
Good catch, this is a bug in conda core. conda config --show-sources calls context.collect_all(), which only iterates over Context.raw_data and never consults context.plugins.collect_all(). So plugin settings under the plugins: key are invisible in the output even though they work correctly at runtime.
Filed upstream: conda/conda#15912
| prefix_graph = PrefixGraph(installed) | ||
|
|
||
| protect = [*PERMANENT_PACKAGES] | ||
| protect = [*PERMANENT_PACKAGES, *context.plugins.self_permanent_packages] |
There was a problem hiding this comment.
It looks like this is also affecting the conda self remove command. So, if a user runs
$ pixi run conda config --add plugins.self_permanent_packages anaconda-anon-usage
$ pixi run conda self remove anaconda-anon-usage
They will get an error:
SpecsCanNotBeRemoved: Packages '['anaconda-anon-usage']' can not be removed.
Should conda self remove get a flag like --force that allows a user to override the protection for this setting?
There was a problem hiding this comment.
Good point, this is working as designed (the user explicitly configured the package as permanent, so blocking removal is expected), but the UX could definitely be smoother. Rather than adding scope to this PR, let's track a --force flag separately.
Filed: #127
For now the workaround is to remove the package from plugins.self_permanent_packages in .condarc first, then run conda self remove.
The permanent packages setting merged in #116 references `context.plugins.self_permanent_packages` without importing `context`, causing ruff F821 and mypy name-defined errors.
Summary
Adds a
self_permanent_packagesconda plugin setting so users can configure extra packages (and their deps) to surviveconda self reset. Uses theconda_settingshook with aSequenceParameter, wired intopermanent_dependencies().Configurable via
.condarc:Or via CLI:
conda config --add plugins.self_permanent_packages anaconda-anon-usageOr env var:
CONDA_PLUGINS_SELF_PERMANENT_PACKAGES=anaconda-anon-usageCloses #22
Changes
constants.py: newSELF_PERMANENT_PACKAGES_SETTINGconstantplugin.py:conda_settingshook yielding the newSequenceParameterquery.py:permanent_dependencies()reads the setting and includes those packages in the protect listtests/test_query.py: tests for the setting with/without condarc configREADME.md: documents the new setting under a Configuration sectionTest plan
test_permanent_dependencies_with_setting— packages from the setting are kepttest_permanent_dependencies_setting_empty_by_default— defaults to emptytest_permanent_dependencies_without_setting— existing behavior unchangedself_permanent_packagesin condarc, runconda self reset --snapshot current, verify listed packages survive