Skip to content

Add configurable permanent packages setting#116

Merged
jezdez merged 3 commits into
mainfrom
issue-22-permanent-packages
Apr 14, 2026
Merged

Add configurable permanent packages setting#116
jezdez merged 3 commits into
mainfrom
issue-22-permanent-packages

Conversation

@jezdez
Copy link
Copy Markdown
Member

@jezdez jezdez commented Apr 9, 2026

Summary

Adds a self_permanent_packages conda plugin setting so users can configure extra packages (and their deps) to survive conda self reset. Uses the conda_settings hook with a SequenceParameter, wired into permanent_dependencies().

Configurable via .condarc:

plugins:
  self_permanent_packages:
    - anaconda-anon-usage

Or via CLI: conda config --add plugins.self_permanent_packages anaconda-anon-usage

Or env var: CONDA_PLUGINS_SELF_PERMANENT_PACKAGES=anaconda-anon-usage

Closes #22

Changes

  • constants.py: new SELF_PERMANENT_PACKAGES_SETTING constant
  • plugin.py: conda_settings hook yielding the new SequenceParameter
  • query.py: permanent_dependencies() reads the setting and includes those packages in the protect list
  • tests/test_query.py: tests for the setting with/without condarc config
  • README.md: documents the new setting under a Configuration section

Test plan

  • test_permanent_dependencies_with_setting — packages from the setting are kept
  • test_permanent_dependencies_setting_empty_by_default — defaults to empty
  • test_permanent_dependencies_without_setting — existing behavior unchanged
  • Manual: set self_permanent_packages in condarc, run conda self reset --snapshot current, verify listed packages survive

@jezdez jezdez force-pushed the issue-22-permanent-packages branch from e281165 to 0a7d409 Compare April 9, 2026 09:32
jezdez added 3 commits April 10, 2026 19:02
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.
@jezdez jezdez force-pushed the issue-22-permanent-packages branch from db25f81 to 90ae5ad Compare April 10, 2026 17:02
@jezdez jezdez requested review from marcoesters and soapy1 April 10, 2026 17:40
Copy link
Copy Markdown
Contributor

@soapy1 soapy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread conda_self/plugin.py
@hookimpl
def conda_settings() -> Iterable[CondaSetting]:
"""Register conda-self plugin settings."""
yield CondaSetting(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

@jezdez jezdez Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread conda_self/query.py
prefix_graph = PrefixGraph(installed)

protect = [*PERMANENT_PACKAGES]
protect = [*PERMANENT_PACKAGES, *context.plugins.self_permanent_packages]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

@jezdez jezdez Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jezdez jezdez merged commit 188b07f into main Apr 14, 2026
23 checks passed
@jezdez jezdez deleted the issue-22-permanent-packages branch April 14, 2026 10:04
jezdez added a commit that referenced this pull request Apr 14, 2026
The permanent packages setting merged in #116 references
`context.plugins.self_permanent_packages` without importing
`context`, causing ruff F821 and mypy name-defined errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: configurable permanent packages

2 participants