-
Notifications
You must be signed in to change notification settings - Fork 2k
Explicitly selected env spec plugin #14877
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
Explicitly selected env spec plugin #14877
Conversation
CodSpeed Performance ReportMerging #14877 will not alter performanceComparing Summary
|
4b83356 to
a979783
Compare
|
pre-commit.ci autofix |
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.
This needs some regiggering of words I think, we should absolutely not call out the existence of "plugins" in the cli or config as that is not consistent how we've mapped plugin provided functionality to the user interface.
5213276 to
1f933f0
Compare
| "25.9", | ||
| "26.3", | ||
| addendum="Use conda.base.context.plugin_manager.get_environment_specifiers.", | ||
| addendum="Use conda.base.context.plugin_manager.detect_environment_specifier.", |
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.
It's maybe spicy to be changing this deprecation warning here? Not sure how conda's process for this is.
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.
Oh, hmm, I'm not sure. @kenodegard did we have a case like this before? Could we keep a get_environment_specifiers stub around as an alias until this deprecation cycle is done?
|
pre-commit.ci autofix |
ae2f190 to
e4f3543
Compare
7280477 to
bffd540
Compare
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
conda/base/context.py
Outdated
| # prevent modifications to envs marked with conda-meta/frozen | ||
| ), | ||
| "Plugin Configuration": ("no_plugins",), | ||
| "Environment Managment Configuration": ("environment_specifier",), |
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.
| "Environment Managment Configuration": ("environment_specifier",), | |
| "Environment Management Configuration": ("environment_specifier",), |
Hm, do we need a new section for this? If it's experimental, we should maybe put it under "undocumented" for now?
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.
I don't think this config field really fits in any of the other categories. Open to suggestions.
I don't think this should go in the undocumented section. But maybe could add an "experimental" section?
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.
Oh, I'm in favor of an experimental section!
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.
Me too, let's move it to experimental.
| p.add_argument( | ||
| "--environment-specifier", | ||
| "--env-spec", # for brevity | ||
| choices=context.plugin_manager.get_environment_specifiers(), |
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.
Can we depend on context bis at CLI initialization? My understanding is that the context needs the parsed CLI args to finish initialization, so I'm not sure we have discovered anything about plugins yet here 🤔 Would we need to validate later?
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.
Erm, ya this is not great, I'd say. This happens other places in the code, for example with the --solver cli argument https://github.com/conda/conda/blob/main/conda/cli/helpers.py#L423.
My understanding is that the context needs the parsed CLI args to finish initialization,
yes, that'll be for slurping up all the config from all the different places it comes from. I don't think this is changing anything for plugin loading though. Like, all the plugins get discovered when the plugin manager gets initialized with plugin.manager::get_plugin_manager.
So, I think setting choices is an ok thing to do here. It is weird that configuration and other things that are expected to be globally accessible (like the plugin manager) and shoved into the context object.
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.
That's a fair point, I've used something like this before, should maybe used for the solver option as well
import argparse
class LazyChoicesAction(argparse.Action):
def __init__(self, option_strings, dest, choices_func, **kwargs):
self.choices_func = choices_func
super().__init__(option_strings, dest, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
valid_choices = self.choices_func()
if values not in valid_choices:
raise argparse.ArgumentTypeError(
f"invalid choice: {values!r} (choose from {valid_choices})"
)
setattr(namespace, self.dest, values)| choices=context.plugin_manager.get_environment_specifiers(), | |
| action=LazyChoicesAction, | |
| choices_func=context.plugin_manager.get_environment_specifiers, |
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.
Oh, I had missed we do that with the solver already. I think we can apply Jannis' suggestion and fix the solver bits in a separate PR to aid with traceability.
Co-authored-by: jaimergp <[email protected]>
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.
The lazy population of the choices is good to fix before merge, other than that this looks great
conda/base/context.py
Outdated
| # prevent modifications to envs marked with conda-meta/frozen | ||
| ), | ||
| "Plugin Configuration": ("no_plugins",), | ||
| "Environment Managment Configuration": ("environment_specifier",), |
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.
Oh, I'm in favor of an experimental section!
| p.add_argument( | ||
| "--environment-specifier", | ||
| "--env-spec", # for brevity | ||
| choices=context.plugin_manager.get_environment_specifiers(), |
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.
That's a fair point, I've used something like this before, should maybe used for the solver option as well
import argparse
class LazyChoicesAction(argparse.Action):
def __init__(self, option_strings, dest, choices_func, **kwargs):
self.choices_func = choices_func
super().__init__(option_strings, dest, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
valid_choices = self.choices_func()
if values not in valid_choices:
raise argparse.ArgumentTypeError(
f"invalid choice: {values!r} (choose from {valid_choices})"
)
setattr(namespace, self.dest, values)| choices=context.plugin_manager.get_environment_specifiers(), | |
| action=LazyChoicesAction, | |
| choices_func=context.plugin_manager.get_environment_specifiers, |
| name=filename, plugin_names=[hook.name for hook in hooks] | ||
| ) | ||
|
|
||
| def get_environment_specifier( |
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.
I like this
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.
I'm fine with leaving choices= as is for now provided we check the Lazy* approach @jezdez suggested in a new PR. Let's move the documentation bits to a new Experimental section and merge here!
|
Pushed up the category map change. Follow up PR with the |
Description
This PR:
--env-spec/--environment-specifiertoconda envcommands to users can explicitly select the environment spec plugin they want to use when creating/updating an environment using an environment fileenv.specs.detectThis PR suggests that environment spec plugin selection works as follows:
--env-speccli arg orenv_specconfig parameter, conda will try to use the plugin with that nameHere are some examples of this change:
The environment spec plugin is automatically detected if no argument is provided
Return an error to the user if an unregistered plugin is requested
Return an error to the user if a plugin that won't work is requested
Set the environment spec using env vars
Checklist - did you ...
newsdirectory (using the template) for the next release's release notes?