Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conda should provide a helpful error message for invalid create_default_packages setting#15115

Merged
jezdez merged 8 commits intoconda:mainfrom
soapy1:dont-allow-explicit-packages-in-create-default-packages
Aug 26, 2025
Merged

Conda should provide a helpful error message for invalid create_default_packages setting#15115
jezdez merged 8 commits intoconda:mainfrom
soapy1:dont-allow-explicit-packages-in-create-default-packages

Conversation

@soapy1
Copy link
Contributor

@soapy1 soapy1 commented Aug 20, 2025

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 message CondaValueError: cannot mix specifications with conda package filenames.

A user may also set a create_default_packages setting. This will inject the specified default packages into an environment created with the conda create and conda env create commands. 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_packages setting contains a reference to an explicit package.

Consider the condarc:

create_default_packages:
  - https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2025.2.25-h06a4308_0.conda

When trying to create an environment.

Previously, this would produce an error when creating an environment with a package specified:

$ conda create -n test-default python                               

CondaValueError: cannot mix specifications with conda package filenames

And, it would create an environment with the explicit package if no package is specified:

$ conda create -n test-default      

Downloading and Extracting Packages:


## Package Plan ##

  environment location: /home/sophia/projects/conda/devenv/Linux/x86_64/envs/devenv-3.10-c/envs/test-default

  added / updated specs:
    - pkgs/main/linux-64::ca-certificates==2025.2.25=h06a4308_0


. . . 

Now, conda will produce an error:

$ conda create -n test-default

CondaValueError: Conda setting `create_default_packages` must not include references to explicit packages. Found explicit package reference 'https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2025.2.25-h06a4308_0.conda'

ref: conda/conda-planning#71

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Aug 20, 2025
@github-project-automation github-project-automation bot moved this to 🆕 New in 🔎 Review Aug 20, 2025
@soapy1 soapy1 force-pushed the dont-allow-explicit-packages-in-create-default-packages branch 2 times, most recently from f1dbc25 to 03df363 Compare August 20, 2025 17:59
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 20, 2025

CodSpeed Instrumentation Performance Report

Merging #15115 will not alter performance

Comparing soapy1:dont-allow-explicit-packages-in-create-default-packages (bced45d) with main (c91315d)

Summary

✅ 21 untouched benchmarks

names = {MatchSpec(spec).name for spec in specs}
for default_package in context.create_default_packages:
if is_package_file(default_package):
raise CondaValueError(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option is to have conda doctor check for if this setting is valid. Would that be a better alternative solution?

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise I think this is a fine exception. Maybe check if there is a more specific exception class in our small exception class collection?

Copy link
Member

Choose a reason for hiding this comment

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

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."

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@soapy1 soapy1 marked this pull request as ready for review August 20, 2025 18:27
@soapy1 soapy1 requested a review from a team as a code owner August 20, 2025 18:27
Copy link
Contributor

@ryanskeith ryanskeith 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 humbly suggest we could add more information to the message to help users understand what to do or where to go next.

@soapy1 soapy1 force-pushed the dont-allow-explicit-packages-in-create-default-packages branch 6 times, most recently from 2e3cb87 to 2058c9c Compare August 22, 2025 21:57
@github-project-automation github-project-automation bot moved this from 🆕 New to 🏗️ In Progress in 🔎 Review Aug 25, 2025
@soapy1 soapy1 force-pushed the dont-allow-explicit-packages-in-create-default-packages branch from f15d892 to 71688bf Compare August 25, 2025 18:15
@soapy1
Copy link
Contributor Author

soapy1 commented Aug 25, 2025

pre-commit.ci autofix

@soapy1 soapy1 force-pushed the dont-allow-explicit-packages-in-create-default-packages branch from f45554e to cfd2915 Compare August 25, 2025 19:15
@github-project-automation github-project-automation bot moved this from 🏗️ In Progress to ✅ Approved in 🔎 Review Aug 26, 2025
@jezdez jezdez enabled auto-merge (squash) August 26, 2025 16:13
@jezdez jezdez merged commit f60b5e1 into conda:main Aug 26, 2025
75 checks passed
@github-project-automation github-project-automation bot moved this from ✅ Approved to 🏁 Done in 🔎 Review Aug 26, 2025
@kenodegard kenodegard mentioned this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed [bot] added once the contributor has signed the CLA

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants

Comments