-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow env spec plugins to enable/disable autodetection #14914
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
Conversation
e72a0b7
to
3ec8b82
Compare
CodSpeed Performance ReportMerging #14914 will not alter performanceComparing Summary
|
1eddfda
to
c1166b1
Compare
pre-commit.ci autofix |
conda/plugins/manager.py
Outdated
if hook.enable_autodetection: | ||
log.debug("EnvironmentSpec hook: checking %s", hook.name) | ||
if hook.environment_spec(source).can_handle(): | ||
log.debug( | ||
"EnvironmentSpec hook: %s can be %s", | ||
source, | ||
hook.name, | ||
) | ||
found.append(hook) | ||
else: | ||
log.debug( | ||
"EnvironmentSpec hook: %s can NOT be handled by %s", | ||
source, | ||
hook.name, | ||
) |
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.
@jaimergp @soapy1 I wonder if this enable_autodetection
option is yet another predicate about whether a plugin "can handle", since the same information could simply be implemented on the env spec level instead of the pluggy interface level. I'd prefer the env spec level to all the env spec business logic covered there
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 would say that autodetection and the ability for a plugin to parse an environment spec are seperate ideas. Both of these ideas need to come together eventually for conda to decide if an environment spec plugin is going to be used. However, can_handle
is about deteriming if a plugin is able to read/parse a given environment spec. And enable_autodetection
is about a plugin author being able to opt out of the plugin autodetection process.
imo the whole auto detection process is the responsibility of the plugin manager. So, I think the most appropriate place for a plugin author to be able to set this information is in the bit where the plugin get's registered.
I'm definitely open to suggestions here. But, I would strongly recommend that the mechanism for opting in-to or out-of autodetection is very explicit. Like, it would be confusing if opting out of autodetection was done by having can_handle
return a None
value opposed to a True
/False
value.
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 agree with your hypothesis that plugin authors should be allowed to create plugins that have two states, auto-detectable or not, I'd say those are fundamentally different behaviors, and it's visible by the error message below, which doesn't give users any recourse to resolve the problem.
In other words, I don't agree that this boolean should be stored in the plugin type, since it is business logic if a plugin should be used to automatically detect the environment spec from a provided file. The deciding code would use the same functionality as we'd implement in the EnvironmentSpecBase, rather than what is in the plugin manager, which doesn't care about the implementation details of environment specs at all.
I'd suggest we either move this into the main EnvironmentSpecBase
and do something like a detection_supported()
, an instance method that can reuse information from the instance:
if hook.enable_autodetection: | |
log.debug("EnvironmentSpec hook: checking %s", hook.name) | |
if hook.environment_spec(source).can_handle(): | |
log.debug( | |
"EnvironmentSpec hook: %s can be %s", | |
source, | |
hook.name, | |
) | |
found.append(hook) | |
else: | |
log.debug( | |
"EnvironmentSpec hook: %s can NOT be handled by %s", | |
source, | |
hook.name, | |
) | |
env_spec = hook.environment_spec(source) | |
if env_spec.detection_supported(): | |
log.debug("EnvironmentSpec hook: checking %s", hook.name) | |
if env_spec.can_handle(): | |
log.debug( | |
"EnvironmentSpec hook: %s can be %s", | |
source, | |
hook.name, | |
) | |
found.append(hook) | |
else: | |
log.debug( | |
"EnvironmentSpec hook: %s can NOT be handled by %s", | |
source, | |
hook.name, | |
) |
or we add another plugin type like class OptionalEnvironmentSpec(EnvironmentSpecBase): ...
, just for the purpose of providing an optional environment spec, plugin authors would be able to able to switch the behavior by using this different type.
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.
Lets go for adding a detection_supported
function opposed to a new type. Pushed up the change.
4740867
to
22b4bd5
Compare
7f8ea6a
to
e8e7b45
Compare
Annotating the whole class makes passing refrences to the class awkward, since it causes 'BinstarSpec' to be a function opposed to a class. This causes things like CondaEnvironmentSpecifier to have the wrong type for it's environment_spec field.
These test cases are already covered in the test_env_specs module.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
f50b2d6
to
41ae0c1
Compare
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
This is just a setting that a plugin author can set as they see fit. It should not have any extra logic associated with it.
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.
Looking good, but I think we are missing --environment-spec
somewhere? Or is this supposed to come in a follow up PR?
@@ -36,6 +35,7 @@ class BinstarSpec(EnvironmentSpecBase): | |||
|
|||
msg = None | |||
|
|||
@deprecated("24.7", "25.9") |
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.
Why this change? 🤔
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 to call this one out! I left a note in the commit message:
Annotating the whole class makes passing refrences to the
class awkward, since it causes 'BinstarSpec' to be a function
opposed to a class. This causes things like CondaEnvironmentSpecifier
to have the wrong type for it's environment_spec field.
So, before this change something like:
for hook in hooks:
if not hook.environment_spec.detection_supported:
. . .
would error on the binstar plugin because the environment_spec
type is a function instead of a class because it has been decorated.
Moving the deprecation decorator to the __init__
method still produces the result of logging the deprecation whenever the binstar class is instantiated, but avoids the above mentioned awkwardness.
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.
Hm, I'm not sure that's the intended design. cc @kenodegard. We might need an issue to track this if it's not there yet.
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.
Yeah, that's an odd one, I wouldn't block on it TBH, given that the deprecation is ending soon
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.
@kenodegard Do you have a suggestion how to handle this?
70e895c
to
d4e2ef1
Compare
Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
d4e2ef1
to
18a4bff
Compare
@jezdez, given your previous comments in this PR, can you take another look? |
Description
This PR introduces a way for environment spec plugins to declare that they should not be automatically detected. So, these plugins would only be accessible to users if they explicitly request the plugin by cli arg or configuration.
For example, consider the environment.yml spec plugin. One could implement a new plugin based on it, with autodetection for their new plugin disabled:
This plugin will never be selected if not explicitly requested. In order to use the
YamlNoAutoDetect
plugin, users must run a command like:When no plugin is detected, conda will produce an error calling out plugins with autodetection disabled:
depends on the changes to the plugin manager introduced in #14877
Checklist - did you ...
news
directory (using the template) for the next release's release notes?