Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update, add and remove shall not uninstall extra dependencies #10016

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

radoering
Copy link
Member

@radoering radoering commented Jan 11, 2025

With this change unrequested extras dependencies will also be kept when running install and are only removed when running sync!

Pull Request Check List

Resolves: #9975
Requires: #10014

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

Bug Fixes:

  • Dependencies with extras are no longer uninstalled when those extras are not explicitly requested during installation or update.

Copy link

sourcery-ai bot commented Jan 11, 2025

Reviewer's Guide by Sourcery

This pull request changes the behavior of Poetry with regards to handling extra dependencies during package installation. Previously, installing a package with extras would remove any other installed extras not explicitly specified. With this change, poetry install keeps the unspecified extras if already installed and only removes them if poetry sync is used or if poetry install is called with the --sync flag. This addresses issue #9975 and depends on #10014.

Sequence diagram for updated package installation behavior with extras

sequenceDiagram
    participant User
    participant Poetry
    participant PackageManager

    User->>Poetry: poetry install -E A -E B
    Note over Poetry: Package has extras A, B, C
    Note over Poetry: C is already installed
    Poetry->>PackageManager: Calculate operations
    PackageManager-->>Poetry: Operations list
    Note over Poetry: New behavior: Keep C
    Poetry->>PackageManager: Install/Update packages
    PackageManager-->>Poetry: Installation complete
    Poetry-->>User: Success (A, B installed, C kept)

    User->>Poetry: poetry sync
    Note over Poetry: Sync removes unspecified extras
    Poetry->>PackageManager: Calculate operations
    PackageManager-->>Poetry: Operations list (includes C removal)
    Poetry->>PackageManager: Remove unspecified extras
    PackageManager-->>Poetry: Sync complete
    Poetry-->>User: Success (only A, B remain)
Loading

State diagram for extras handling behavior

stateDiagram-v2
    [*] --> HasExtras: Initial state with
extras A, B, C installed
    HasExtras --> PartialExtras: poetry install -E A -E B
    HasExtras --> SyncedExtras: poetry sync --extras "A B"
    PartialExtras --> SyncedExtras: poetry sync --extras "A B"

    state PartialExtras {
        [*] --> Installed: A, B installed
        Installed --> Kept: C kept but not requested
    }

    state SyncedExtras {
        [*] --> Required: A, B installed
        Required --> Removed: C removed
    }
Loading

File-Level Changes

Change Details Files
Modified the dependency installation logic to preserve existing extras during regular installations.
  • Removed the logic that uninstalled extras not explicitly requested during installation.
  • Added a check to skip processing of unsolicited extras during installation.
  • Modified the uninstall logic to only remove extras when synchronization is requested or the --sync flag is used with poetry install.
src/poetry/puzzle/transaction.py
Updated tests to reflect the new behavior of extra handling.
  • Added tests to verify that extras are not uninstalled during regular installation unless synchronization is requested.
  • Modified existing tests to align with the new extra installation behavior.
tests/puzzle/test_transaction.py
Updated documentation to explain the new behavior of extra handling.
  • Clarified that unspecified extras are kept during regular installation.
  • Added information about using the sync command to remove unspecified extras.
docs/cli.md
Updated the installer to handle the new extra installation logic.
  • Added parameters for update and sync operations to test various scenarios.
  • Modified the installer logic to align with the new extra handling behavior.
  • Added assertions to verify the correct number of installations and removals based on the update and sync flags and whether extras are requested or not.
tests/installation/test_installer.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@radoering radoering force-pushed the fix-update-uninstall-regression2 branch from a128a78 to 507ca98 Compare January 11, 2025 05:38
@radoering radoering changed the title fix: update, add and remove with shall not uninstall extra dependencies fix: update, add and remove shall not uninstall extra dependencies Jan 11, 2025
@radoering radoering force-pushed the fix-update-uninstall-regression2 branch from 507ca98 to 861dd4a Compare January 11, 2025 14:49
@radoering radoering marked this pull request as ready for review January 11, 2025 14:52
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @radoering - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please update the documentation to reflect this behavior change regarding how extra dependencies are handled during install/update/sync operations.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@radoering radoering marked this pull request as draft January 11, 2025 14:55
@radoering
Copy link
Member Author

  • Please update the documentation to reflect this behavior change regarding how extra dependencies are handled during install/update/sync operations.

Good point.

@radoering radoering force-pushed the fix-update-uninstall-regression2 branch from 861dd4a to 0b3eea0 Compare January 11, 2025 15:02
@radoering radoering added the impact/docs Contains or requires documentation changes label Jan 11, 2025
Copy link

github-actions bot commented Jan 11, 2025

Deploy preview for website ready!

✅ Preview
https://website-nwnunsq66-python-poetry.vercel.app

Built with commit 7bc1baf.
This pull request is being automatically deployed with vercel-action

@radoering radoering marked this pull request as ready for review January 11, 2025 15:30
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @radoering - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

docs/cli.md Outdated Show resolved Hide resolved
@radoering radoering force-pushed the fix-update-uninstall-regression2 branch from 0b3eea0 to 4fd6971 Compare January 11, 2025 15:32
@radoering radoering marked this pull request as draft January 11, 2025 16:00
@radoering radoering marked this pull request as ready for review January 11, 2025 16:13
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @radoering - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@radoering radoering requested a review from a team January 11, 2025 16:17
@abn abn enabled auto-merge (rebase) January 11, 2025 17:23
With this change unrequested extras dependencies will also be kept when running `install` and are only removed when running `sync`!
@abn abn force-pushed the fix-update-uninstall-regression2 branch from 4fd6971 to 7bc1baf Compare January 11, 2025 17:23
@abn abn merged commit 0ac2c1a into python-poetry:main Jan 11, 2025
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/docs Contains or requires documentation changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Poetry removes installed extras when adding a new dependency
2 participants