Conda should provide a helpful error message for invalid create_default_packages setting#15115
Conversation
f1dbc25 to
03df363
Compare
CodSpeed Instrumentation Performance ReportMerging #15115 will not alter performanceComparing Summary
|
conda/models/environment.py
Outdated
| names = {MatchSpec(spec).name for spec in specs} | ||
| for default_package in context.create_default_packages: | ||
| if is_package_file(default_package): | ||
| raise CondaValueError( |
There was a problem hiding this comment.
Is this too strict? Should conda allow explicit packages in the create_default_packages setting?
- In every case that a user creates an environment and wants to specify packages, it will cause an error. For example
conda create -n myenv python. - It's maybe valid if the case where the user is not specifying packages to go in the created environment. For example
conda create -n myenv- But, installing an explicit package means that none of the dependencies get installed. So if the user specifies an explicit reference to, say a flask package, the environment will be in a weird state.
There was a problem hiding this comment.
Another option is to have conda doctor check for if this setting is valid. Would that be a better alternative solution?
There was a problem hiding this comment.
I'd not raise the error immediately here, but first iterate over all of them to check if they are a package file, so that the CondaValueError can show a list if needed, preventing the users from having to run conda multiple times.
There was a problem hiding this comment.
Otherwise I think this is a fine exception. Maybe check if there is a more specific exception class in our small exception class collection?
There was a problem hiding this comment.
Hi @soapy1,
What if we did a warn and continue approach to educate them but not block them? This way they would get a warning that their config is bad, but it would ignore the explicit packages, try to install other non-explicit packages in create_default_packages and keep going.
The warning could be something like f"Skipping invalid explicit package in create_default_packages: '{default_package}'. Use package names like 'numpy' or specs like 'numpy>=1.20' instead."
There was a problem hiding this comment.
I agree with collecting all of the failures into one message instead of failing on the first invalid package
I also think we should move this logic over into the context object and make context.create_default_packages a property that performs this validation
There was a problem hiding this comment.
Thanks for the feedback all!
but first iterate over all of them to check if they are a package file
I like this idea! Added 🎆
What if we did a warn and continue approach to educate them but not block them?
I like this idea too. I think in general ignoring user config, even if invalid, can result in pretty hairy situations. For this case, it is always invalid for conda to be mixing explicit package references and specs. Having an explicit spec as a value in create_default_packages is invalid, and the solution is to always remove it. So, I think in this case removing the explicit package and just warning instead of erroring out is ok.
There was a problem hiding this comment.
I also think we should move this logic over into the context object and make context.create_default_packages a property that performs this validation
Oh! I was also thinking about how the validation can be done in the context object. Just couldn't figure it out. Making it a property makes sense. I like that approach, will give it a go.
ryanskeith
left a comment
There was a problem hiding this comment.
This looks good to me. I humbly suggest we could add more information to the message to help users understand what to do or where to go next.
2e3cb87 to
2058c9c
Compare
…ult_packages' setting
Conda will produce a warning to users if this setting contains invalid entries.
Co-authored-by: Ken Odegard <[email protected]>
f15d892 to
71688bf
Compare
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
f45554e to
cfd2915
Compare
Description
Conda is unable to install a mixture of explicit packages (eg.
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2025.2.25-h06a4308_0.conda) and package specs (eg.python > 3.10). If a user tries to do this, they get an error messageCondaValueError: cannot mix specifications with conda package filenames.A user may also set a
create_default_packagessetting. This will inject the specified default packages into an environment created with theconda createandconda env createcommands. If this setting contains an explicit package, the user will see the same error message,CondaValueError: cannot mix specifications with conda package filenames. However, it would be better if this error message was more helpful.This PR adds more context to the error message presented to the user when the
create_default_packagessetting contains a reference to an explicit package.Consider the condarc:
When trying to create an environment.
Previously, this would produce an error when creating an environment with a package specified:
And, it would create an environment with the explicit package if no package is specified:
Now, conda will produce an error:
ref: conda/conda-planning#71
Checklist - did you ...
newsdirectory (using the template) for the next release's release notes?