Skip to content

feat: pixi add skips already-present packages without version spec#6145

Open
benmoss wants to merge 3 commits into
prefix-dev:mainfrom
benmoss:fix/add-skip-existing-deps
Open

feat: pixi add skips already-present packages without version spec#6145
benmoss wants to merge 3 commits into
prefix-dev:mainfrom
benmoss:fix/add-skip-existing-deps

Conversation

@benmoss
Copy link
Copy Markdown
Contributor

@benmoss benmoss commented May 18, 2026

Description

When a package is already a dependency and pixi add <pkg> is called without a version constraint, the command now skips the package instead of upgrading it. This prevents accidental version bumps and makes the behavior consistent with cargo's approach.

Users are informed with a clear message and directed to use pixi upgrade for intentional version updates:

$ pixi add crane
✔ crane is already a dependency
  Run pixi upgrade crane to get the newest compatible version

Explicitly versioned adds like pixi add crane==2.0 still overwrite the existing spec as before.

Fixes #3936

How Has This Been Tested?

  • New integration test add_existing_dependency_without_version_is_noop validates:
    • Adding with explicit version works (pixi add foobar==1)
    • Re-adding without version is a noop (spec stays ==1)
    • Re-adding with explicit version overwrites (pixi add foobar==2)
  • All existing add and upgrade integration tests pass

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Claude Code (Claude Opus 4.6)

Checklist:

  • I have performed a self-review of my own code
  • I have added sufficient tests to cover my changes.

When a package is already a dependency and `pixi add <pkg>` is called
without a version constraint, the command now skips the package instead
of upgrading it. This prevents accidental version bumps and makes the
behavior consistent with cargo's approach.

Users are informed with a clear message and directed to use
`pixi upgrade` for intentional version updates.

Closes prefix-dev#3936

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@benmoss benmoss force-pushed the fix/add-skip-existing-deps branch from 8558337 to fd4267f Compare May 18, 2026 18:37
Comment thread crates/pixi/tests/integration_rust/install_tests.rs
@benmoss benmoss marked this pull request as ready for review May 18, 2026 19:38
Copy link
Copy Markdown
Contributor

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

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

One small comment but otherwise looks good. Looking at @ruben-arts if this CLI change makes sense to him.

Comment thread crates/pixi_cli/src/cli_config.rs Outdated
Comment on lines +339 to +346
if skipped.iter().any(|s| {
package == s.as_str()
|| package.strip_prefix(s.as_str()).is_some_and(|rest| {
rest.starts_with(|c: char| !c.is_alphanumeric() && c != '-' && c != '_')
})
}) {
continue;
}
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.

What does this do?

Copy link
Copy Markdown
Contributor Author

@benmoss benmoss May 19, 2026

Choose a reason for hiding this comment

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

This prevents the "✔ Added crane" logs from appearing for packages that we skip. The extra prefix testing is to handle the fact that self.specs is raw strings of MatchSpecs and PyPI requirements. It's kinda hacky though. Let me see if I can make this simpler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

9ca5329 refactors this to use the CondaDependency/PypiDependency types and filter in add.rs

@baszalmstra baszalmstra requested a review from ruben-arts May 19, 2026 06:42
@ruben-arts
Copy link
Copy Markdown
Contributor

Sounds good to me. Would love to see the pixi upgrade xxx command to be colored.

benmoss and others added 2 commits May 19, 2026 09:40
…atching

Use already-parsed package names (from MatchSpec/Requirement parsing)
to filter the display list, avoiding reparsing and fragile string
pattern matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@benmoss benmoss changed the title fix: pixi add skips already-present packages without version spec feat: pixi add skips already-present packages without version spec May 19, 2026
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.

pixi add when package already is specified updates the package

3 participants