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 considered python constraint for overrides #10157

Merged

Conversation

radoering
Copy link
Member

@radoering radoering commented Feb 7, 2025

Previously, the Python constraint of the root package has always been used to check for incompatibilities, even if the Python constraint had effectively been restricted by overrides before. This could result in false conflicts à la "The current project's supported Python range is not compatible with some of the required packages Python requirement."

Pull Request Check List

Resolves an issue introduced (or maybe just revealed) by #10141

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

Summary by Sourcery

Fix an issue where the root package's Python constraint was always used for incompatibility checks, even when overrides had restricted it, leading to false conflict errors.

Bug Fixes:

  • Fixed false "The current project's supported Python range is not compatible" errors.

Tests:

  • Added tests to cover the fix for the Python constraint issue.

Copy link

sourcery-ai bot commented Feb 7, 2025

Reviewer's Guide by Sourcery

This pull request addresses a bug in the solver where the package's effective Python constraint was incorrectly using the root package's constraint even when overrides were applied. The implementation refactors the constraint handling by renaming and recalculating the Python constraint, ensuring that the overrides are properly taken into account. Additionally, tests have been added and updated to validate that the solver now correctly handles transitive Python constraints under override scenarios.

Updated Provider Class Diagram for Python Constraint Overrides

classDiagram
    class Provider {
      - _package_python_constraint : VersionConstraint
      - _direct_origin
      - _io
      - _env : Env | null
      - _is_debugging : bool
      - _overrides : dict<Package, dict<string, Dependency>>
      - _deferred_cache : dict<Dependency, Package>
      - _load_deferred
      <<cached>>
      + _overrides_marker_intersection : BaseMarker
      <<cached>>
      + _python_constraint : VersionConstraint
      + __init__(...)
      + pool() : RepositoryPool
      + use_latest() : Collection<NormalizedName>
      + is_debugging() : bool
      + set_overrides(overrides : dict<Package, dict<string, Dependency>>) : void
      + load_deferred(load_deferred : bool) : void
      + use_environment(env : Env) : Iterator<Provider>
      + use_latest_for(names : Collection<NormalizedName>) : Iterator<Provider>
      + complete_package(...) : void
    }

    %% Note: The class now properly computes the effective Python constraint using overrides markers.
    %% The field _python_constraint is now a cached property that intersects _package_python_constraint
    %% with the Python constraint derived from the overrides marker intersection.
Loading

File-Level Changes

Change Details Files
Refactoring of Python constraint handling in provider.
  • Renamed the attribute from _python_constraint to _package_python_constraint in the provider to better represent its purpose.
  • Introduced a computed property for _python_constraint that intersects the package constraint with Python constraints derived from overrides.
  • Added cached properties for calculating the overrides marker intersection and updated cache invalidation in set_overrides.
  • Modified context manager methods to use the new _package_python_constraint during environment switches.
src/poetry/puzzle/provider.py
Enhancement of tests to cover override scenarios.
  • Updated test helper function to use the new _package_python_constraint field.
  • Added a parameterized test (test_solver_should_not_raise_errors_for_irrelevant_transitive_python_constraints2) to validate correct solver behavior when multiple Python constraints are in play due to overrides.
  • Simulated different dependency orders and conflict situations to ensure that false conflicts no longer occur.
tests/puzzle/test_solver.py

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

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:

  • Consolidate the repeated logic for renaming and updating python constraints to a single helper to reduce potential inconsistencies.
  • Instead of manually deleting cached properties in set_overrides, consider using a more robust cache invalidation strategy with the cached properties.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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.

src/poetry/puzzle/provider.py Outdated Show resolved Hide resolved
tests/puzzle/test_solver.py Outdated Show resolved Hide resolved
@radoering radoering force-pushed the fix-python-constraint-overrides branch from 8720feb to a5a528a Compare February 7, 2025 16:43
@radoering
Copy link
Member Author

@sourcery-ai review

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:

  • Consider renaming _package_python_constraint or the computed _python_constraint property to clarify their roles and avoid confusion.
  • Review the cache invalidation in set_overrides to ensure it safely resets the related state without side effects.
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 February 7, 2025 18:27
Previously, the Python constraint of the root package has always been used to check for incompatibilities, even if the Python constraint had effectively been restricted by overrides before. This could result in false conflicts à la "The current project's supported Python range is not compatible with some of the required packages Python requirement."
@abn abn force-pushed the fix-python-constraint-overrides branch from a5a528a to 0152071 Compare February 7, 2025 23:20
@radoering radoering merged commit 9d66222 into python-poetry:main Feb 8, 2025
53 checks passed
@radoering radoering mentioned this pull request Feb 9, 2025
4 tasks
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