Skip to content

Conversation

soapy1
Copy link
Contributor

@soapy1 soapy1 commented Jun 13, 2025

Description

This PR updates the EnvironmentSpecBase interface to return a model.Environment (environment model) instead of an env.env.Environment (environment.yml model). The env.env.Environment does not fully describe a conda environment. On the other hand, model.Environment can fully describe an environment. So, this type makes more sense to be the return type for env spec plugins. For more information on the Environment model see https://docs.google.com/document/d/1Q_M66kFGCYLuaqAqez_jlsqxnQEQh5tSUBtvEz3ixdA/edit?tab=t.gmwr9pinfepw.

This PR also updates conda env commands and env installers to use the new Environment model.

This is a refactor PR, there should be no changes in conda's behaviour.

fixes conda/conda-planning#62

depends on #14820

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?

@github-project-automation github-project-automation bot moved this to 🆕 New in 🔎 Review Jun 13, 2025
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Jun 13, 2025
Copy link

codspeed-hq bot commented Jun 13, 2025

CodSpeed Instrumentation Performance Report

Merging #14937 will not alter performance

Comparing soapy1:env-spec-env-model (ce38b4d) with main (01f2286)

Summary

✅ 21 untouched benchmarks

@jezdez
Copy link
Member

jezdez commented Jun 25, 2025

Could we start this up again, now that #14820 is merged? #14886 could really need a way to convert the legacy environment classes to the new models, see _create_environment_from_prefix here

@soapy1
Copy link
Contributor Author

soapy1 commented Jun 25, 2025

Absolutely! Will whip it up in just a bit

@soapy1 soapy1 force-pushed the env-spec-env-model branch from 29074b5 to 7808343 Compare June 25, 2025 22:30
@@ -56,18 +57,18 @@ def _solve(

def dry_run(
specs: list[str], args: Namespace, env: Environment, *_, **kwargs
) -> Environment:
) -> EnvironmentYaml:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to continue to return the conda.env.env.Environment here so that we aren't changing the installer api. Eventually this should move over to use the new Environment model. But I think it's better to chunk that in another piece of work to keep this change focused on the env spec api.

Copy link
Member

Choose a reason for hiding this comment

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

I can't parse this statement

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be ok to make these changes here to make sure we have covered all the API changes and nothing lingers.

Copy link

codspeed-hq bot commented Jun 25, 2025

CodSpeed WallTime Performance Report

Merging #14937 will not alter performance

Comparing soapy1:env-spec-env-model (6f3365c) with main (21abdfe)

Summary

✅ 21 untouched benchmarks

@soapy1 soapy1 force-pushed the env-spec-env-model branch 2 times, most recently from 167fc08 to 9776b39 Compare June 26, 2025 01:21
@@ -1,108 +0,0 @@
# Copyright (C) 2012 Anaconda, Inc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want to support an explicit environment.yaml anymore. The conda.env.env.Environment class should just represent the conda environment.yaml format.

Copy link
Member

Choose a reason for hiding this comment

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

Wait, what's "an explicit environment.yaml"? @EXPLICIT input files are defined in CEP 23, we can't not support them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TL;DR

  • To clarify, this PR is still supporting explicit input files.
  • conda.env.env.Environment should only be representing environment.yaml files.

Previously, this was implemented by making conda.env.env.Environment support reading these files (that was in #14820). That was an ok approach at that time since env spec plugins were meant to be returning conda.env.env.Environment.

However, now we want env spec plugins to return conda.models.environment.Environment. So, I think we should back out the changes to conda.env.env.Environment that allow it to represent an explicit environment and restore it to it's original purpose which is to represent an environment.yaml file. And ExplicitSpecPlugin should create a conda.models.environment.Environment.

@@ -1,102 +0,0 @@
# Copyright (C) 2012 Anaconda, Inc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests are duplicates of the ones in tests/env/specs/test_explicit.py

@@ -4,9 +4,12 @@

import pytest

from conda.env.env import Environment
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this whole file can be deleted?

@soapy1
Copy link
Contributor Author

soapy1 commented Jun 26, 2025

pre-commit.ci autofix

@soapy1 soapy1 force-pushed the env-spec-env-model branch 2 times, most recently from 11c65cd to 1916f6e Compare June 26, 2025 19:17
@soapy1 soapy1 force-pushed the env-spec-env-model branch from 1916f6e to 971a044 Compare June 26, 2025 21:23
@soapy1 soapy1 marked this pull request as ready for review June 26, 2025 21:23
@soapy1 soapy1 requested a review from a team as a code owner June 26, 2025 21:23
@soapy1 soapy1 force-pushed the env-spec-env-model branch from 971a044 to 6faf13e Compare June 26, 2025 21:44
Comment on lines 157 to 160
if len(env.requested_packages) > 0:
installers["conda"] = get_installer("conda")

for installer_type in env.external_packages:
Copy link
Member

Choose a reason for hiding this comment

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

Why do we only get and set the conda installer if there are requested packages? This makes me wonder why we have a separation between requested and external packages

Copy link
Contributor

Choose a reason for hiding this comment

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

requested packages are only for conda packages. external are everything else (PyPI and whatever ecosystem we end up adding).

@soapy1 soapy1 force-pushed the env-spec-env-model branch from ef7ed2a to 95f62f8 Compare July 2, 2025 15:15
@github-project-automation github-project-automation bot moved this from ✅ Approved to 🏗️ In Progress in 🔎 Review Jul 2, 2025
soapy1 and others added 2 commits July 2, 2025 09:08
Co-authored-by: Ken Odegard <kodegard@anaconda.com>
Co-authored-by: Ken Odegard <kodegard@anaconda.com>
@soapy1 soapy1 requested a review from kenodegard July 2, 2025 17:12
@github-project-automation github-project-automation bot moved this from 🏗️ In Progress to ✅ Approved in 🔎 Review Jul 2, 2025
@soapy1 soapy1 merged commit 9c502c7 into conda:main Jul 2, 2025
75 checks passed
@github-project-automation github-project-automation bot moved this from ✅ Approved to 🏁 Done in 🔎 Review Jul 2, 2025
@soapy1 soapy1 deleted the env-spec-env-model branch July 2, 2025 20:23
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.

Make environment specifier hook API return the new Environment dataclass object
5 participants