Skip to content

Handle conda cyclical deps and pip components, improve test coverage#1850

Open
ryanbrandenburg wants to merge 3 commits into
mainfrom
rybrande/conda_quality
Open

Handle conda cyclical deps and pip components, improve test coverage#1850
ryanbrandenburg wants to merge 3 commits into
mainfrom
rybrande/conda_quality

Conversation

@ryanbrandenburg

Copy link
Copy Markdown
Contributor
  1. Handle cyclical dependencies in Conda to prevent infinite recursion.
  2. Check the manager of a package to determin pip or conda rather than using heuristics.
  3. Improve test coverage for the CondaComponentDetector.

Copilot AI review requested due to automatic review settings July 15, 2026 20:11
@ryanbrandenburg
ryanbrandenburg requested a review from a team as a code owner July 15, 2026 20:11
@ryanbrandenburg
ryanbrandenburg requested a review from grvillic July 15, 2026 20:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Conda lockfile detector and resolver to better handle real-world Conda environments by preventing infinite recursion on cyclical dependency graphs, classifying components as Pip vs Conda based on the lockfile’s manager field, and adding broader unit test coverage for these scenarios.

Changes:

  • Add cycle protection and null-safe dependency enumeration in CondaDependencyResolver.
  • Switch Pip-vs-Conda classification to depend solely on package.manager (rather than python-dependency heuristics).
  • Expand CondaLockComponentDetector tests to cover cycles, missing dependencies, mixed managers, dependency graph edges, malformed YAML, etc.
Show a summary per file
File Description
test/Microsoft.ComponentDetection.Detectors.Tests/CondaLockComponentDetectorTests.cs Adds focused tests for cycles, manager-based typing, null dependencies, graph edges, malformed YAML, and file pattern matching.
src/Microsoft.ComponentDetection.Detectors/conda/CondaLockComponentDetector.cs Bumps detector version to reflect updated behavior.
src/Microsoft.ComponentDetection.Detectors/conda/CondaDependencyResolver.cs Adds visited-set cycle protection, handles missing dependencies, and changes Pip/Conda component determination logic.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Low

Comment thread src/Microsoft.ComponentDetection.Detectors/conda/CondaDependencyResolver.cs Outdated
Comment thread src/Microsoft.ComponentDetection.Detectors/conda/CondaDependencyResolver.cs Outdated
Copilot AI review requested due to automatic review settings July 15, 2026 20:38
@github-actions

Copy link
Copy Markdown

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment on lines 139 to +143
private static TypedComponent CreateComponent(CondaPackage package)
=> IsPythonPackage(package)
? new PipComponent(package.Name, package.Version)
: new CondaComponent(package.Name, package.Version, null, package.Category, null, null, null, null);

/// <summary>
/// Checks if a package is a python package.
///
/// If the package is either managed by pip, or if it depends on python
/// it is considered a python package.
/// </summary>
/// <param name="package">The CondaPackage.</param>
/// <returns>True if the package is a python package.</returns>
private static bool IsPythonPackage(CondaPackage package)
=> package.Manager.Equals("pip", StringComparison.OrdinalIgnoreCase) ||
package.Dependencies.Keys.Any(dependency => dependency.Equals("python", StringComparison.OrdinalIgnoreCase));
{
return package.Manager.Equals("pip", StringComparison.OrdinalIgnoreCase)
? new PipComponent(package.Name, package.Version)
: new CondaComponent(package.Name, package.Version, null, package.Category, null, null, null, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants