Skip to content

Conversation

ForgottenProgramme
Copy link
Contributor

@ForgottenProgramme ForgottenProgramme commented Apr 2, 2025

Description

This PR adds a new health check to conda doctor called "environment consistency check".

resolves #14715

Todo

  • output why the environment is inconsistent
  • Write tests
  • remove the following text from the outputed health report
Channels:
 - file:///var/folders/tg/gstz8jc94rb75hnd7pfsxjvr0000gp/T/tmpg2n97khs
Platform: osx-arm64
Collecting package metadata (repodata.json): done
Solving environment: done

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 Apr 2, 2025
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 2, 2025
Copy link

codspeed-hq bot commented Apr 2, 2025

CodSpeed Performance Report

Merging #14726 will not alter performance

Comparing ForgottenProgramme:consistent-env (fcf7b73) with main (8cca6cc)

Summary

✅ 21 untouched benchmarks

@ForgottenProgramme ForgottenProgramme marked this pull request as ready for review April 22, 2025 15:29
@ForgottenProgramme ForgottenProgramme requested a review from a team as a code owner April 22, 2025 15:29
Copy link
Contributor

@kenodegard kenodegard left a comment

Choose a reason for hiding this comment

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

Need to add tests (both consistent and inconsistent environments) to better understand if this check is doing what we expect it to be doing.

@jjhelmus
Copy link
Contributor

Is a solve really necessary here. Iterating over the PrefixRecords and testing if their dependencies are met by packages in the prefix is sufficient to validate an environment. This process can be done using MatchSpecs and not the solver.

@ForgottenProgramme
Copy link
Contributor Author

ForgottenProgramme commented Apr 30, 2025

Hey, @jjhelmus
To get started on this PR I ported logic found in the resolve.py module. See here.

@github-project-automation github-project-automation bot moved this from 🆕 New to 🏗️ In Progress in 🔎 Review May 1, 2025
@jjhelmus
Copy link
Contributor

jjhelmus commented May 1, 2025

Can a similar check be done by validating that all dependencies for each packages installed in the environment in question are met? This seems favorable given it can be accomplished without engaging the solver or creating mock channels.

The following snippet performs this check:

def consistent_env_check(prefix: str, verbose: bool) -> None:

    # get the plugin manager from context
    pm = context.plugin_manager

    # find virtual packages
    virtual_packages = {str(p.name): p for p in  pm.get_virtual_package_records()}

    # get prefix data
    prefix_data = PrefixData(prefix)

    issues = []
    # look at each package in the environment for conflicts
    prefix_record: PrefixRecord
    for prefix_record in prefix_data.iter_records():
        for depend in prefix_record.depends:
            matchspec = MatchSpec(depend)
            package_record_with_name = prefix_data.get(
                matchspec.name,
                default=virtual_packages.get(matchspec.name, None),
            )
            if package_record_with_name is None:
                issues.append(f"No package {matchspec.name} required by {prefix_record} ({matchspec})")
                continue
            if not matchspec.match(package_record_with_name):
                issues.append(f"{package_record_with_name} does not match {prefix_record} ({matchspec})")
                continue
    if issues:
        print(
            f"{X_MARK} The environment is not consistent due to the following issues:\n",
            ''.join(issues),
        )
    else:
        print(f"{OK_MARK} The environment is consistent.\n")

@ForgottenProgramme
Copy link
Contributor Author

@jjhelmus thank you for your suggested changes.
I will keep this PR as is. And create a new PR without engaging the solver. The two solutions can then be compared and one of them merged. 👍🏼

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.

Add 'check if environment is consistent with solver' health check to conda doctor
5 participants