-
Notifications
You must be signed in to change notification settings - Fork 8
Add configurable permanent packages setting #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,8 @@ def permanent_dependencies(add_plugins: bool = False) -> set[str]: | |
| installed = list(PrefixData(sys.prefix, interoperability=True).iter_records()) | ||
| prefix_graph = PrefixGraph(installed) | ||
|
|
||
| protect = [*PERMANENT_PACKAGES] | ||
| protect = [*PERMANENT_PACKAGES, *context.plugins.self_permanent_packages] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is also affecting the They will get an error: Should
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Filed: #127 For now the workaround is to remove the package from |
||
|
|
||
| if add_plugins: | ||
| for record in installed: | ||
| with suppress(NoDistInfoDirFound): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,72 @@ | ||
| from conda_self.constants import PERMANENT_PACKAGES | ||
| import pytest | ||
| from conda.base.context import context, reset_context | ||
| from conda.common.configuration import YamlRawParameter | ||
| from conda.common.serialize import yaml | ||
| from conda.plugins.manager import CondaPluginManager | ||
|
|
||
| from conda_self import plugin as conda_self_plugin | ||
| from conda_self.constants import PERMANENT_PACKAGES, SELF_PERMANENT_PACKAGES_SETTING | ||
| from conda_self.query import permanent_dependencies | ||
|
|
||
| CONDARC_PERMANENT_PACKAGES = f"""\ | ||
| plugins: | ||
| {SELF_PERMANENT_PACKAGES_SETTING}: | ||
| - python | ||
| """ | ||
|
|
||
|
|
||
| def test_permanent_dependencies(): | ||
| must_keep = permanent_dependencies() | ||
| assert set(PERMANENT_PACKAGES).issubset(must_keep) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def clear_plugins_context_cache(): | ||
| try: | ||
| del context.plugins | ||
| except AttributeError: | ||
| pass | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def self_plugin_manager( | ||
| plugin_manager: CondaPluginManager, clear_plugins_context_cache | ||
| ): | ||
| """Load the conda-self plugin module (including conda_settings).""" | ||
| plugin_manager.load_plugins(conda_self_plugin) | ||
| yield plugin_manager | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def permanent_packages_condarc(self_plugin_manager): | ||
| """Load a .condarc that sets self_permanent_packages to ['python'].""" | ||
| reset_context() | ||
| context._set_raw_data( | ||
| { | ||
| "testdata": YamlRawParameter.make_raw_parameters( | ||
| "testdata", yaml.loads(CONDARC_PERMANENT_PACKAGES) | ||
| ) | ||
| } | ||
| ) | ||
| yield self_plugin_manager | ||
| reset_context() | ||
|
|
||
|
|
||
| def test_permanent_dependencies_with_setting(permanent_packages_condarc): | ||
| """Packages listed in the self_permanent_packages setting are kept.""" | ||
| must_keep = permanent_dependencies() | ||
|
|
||
| assert set(PERMANENT_PACKAGES).issubset(must_keep) | ||
| assert "python" in must_keep | ||
|
|
||
|
|
||
| def test_permanent_dependencies_setting_empty_by_default(self_plugin_manager): | ||
| """Without condarc config, the setting defaults to an empty list.""" | ||
| assert getattr(context.plugins, SELF_PERMANENT_PACKAGES_SETTING) == () | ||
|
|
||
|
|
||
| def test_permanent_dependencies_without_setting(): | ||
| """Works normally when no plugin settings are loaded.""" | ||
| must_keep = permanent_dependencies() | ||
|
|
||
| assert set(PERMANENT_PACKAGES).issubset(must_keep) |
There was a problem hiding this comment.
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-usageI can see that the config has been added to my condarc. However, it does not appear when I runconda config --show-sources. Is this a bug in core conda?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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-sourcescallscontext.collect_all(), which only iterates overContext.raw_dataand never consultscontext.plugins.collect_all(). So plugin settings under theplugins:key are invisible in the output even though they work correctly at runtime.Filed upstream: conda/conda#15912