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(puzzle): handle self-referential extras #10124

Closed
wants to merge 1 commit into from

Conversation

abn
Copy link
Member

@abn abn commented Jan 29, 2025

This is an alternative proposed by @dimbleby for #10106.

Raising this as a draft to preserve the proposed chang as I had to revert to my original approach to ensure tests passed once #10119 was merged to main.

Summary by Sourcery

Tests:

  • Add tests for resolving self-referential extras with and without markers, and at different dependency levels.

Copy link

sourcery-ai bot commented Jan 29, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ability to handle self-referential extras in package dependencies. It modifies the solver to correctly resolve dependencies when extras refer to each other, either directly or through nested extras. Additionally, it includes new test cases to verify the correct behavior of the solver and installer with self-referential extras.

Class diagram for dependency resolution changes

classDiagram
    class Package {
        +extras: Dict
        +requires: List
        +is_root(): bool
    }

    class Dependency {
        +name: str
        +extras: Set
        +is_optional(): bool
        +in_extras: List
    }

    class Provider {
        +complete_package()
    }

    Package -- Dependency : contains
    Provider -- Package : processes
Loading

File-Level Changes

Change Details Files
Added test cases for self-referential extras in the solver.
  • Added parameterized tests to check different combinations of enabled extras and top-level dependencies.
  • Added a test case to verify the correct resolution of self-referential extras with markers.
tests/puzzle/test_solver.py
Added test cases for self-referential extras in the installer.
  • Added parameterized tests to check different combinations of enabled extras and top-level dependencies.
  • Added a test case to verify the correct resolution of self-referential extras with markers.
tests/installation/test_installer.py
Added a factory fixture for creating packages with extras and self-referenced extras.
  • Introduced a new fixture create_package to simplify the creation of packages with extras and self-referenced extras in tests.
tests/conftest.py
Modified the solver to handle self-referential extras.
  • Modified the complete_package method to correctly resolve self-referential extras by using a stack to traverse the extras.
  • Ensured that optional dependencies are correctly included based on the requested extras, including self-referential ones.
src/poetry/puzzle/provider.py
Added type definition for PackageFactory.
  • Added a type definition for the PackageFactory fixture.
tests/types.py
Added new test fixtures for self-referential extras.
  • Added new test fixtures to verify the correct behavior of the installer with self-referential extras.
tests/installation/fixtures/with-self-referencing-extras-all-deep.test
tests/installation/fixtures/with-self-referencing-extras-all-top.test
tests/installation/fixtures/with-self-referencing-extras-b-markers.test
tests/installation/fixtures/with-self-referencing-extras-deep.test
tests/installation/fixtures/with-self-referencing-extras-download-deep.test
tests/installation/fixtures/with-self-referencing-extras-download-top.test
tests/installation/fixtures/with-self-referencing-extras-install-deep.test
tests/installation/fixtures/with-self-referencing-extras-install-download-deep.test
tests/installation/fixtures/with-self-referencing-extras-install-download-top.test
tests/installation/fixtures/with-self-referencing-extras-install-top.test
tests/installation/fixtures/with-self-referencing-extras-nested-deep.test
tests/installation/fixtures/with-self-referencing-extras-nested-top.test
tests/installation/fixtures/with-self-referencing-extras-top.test

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

@dimbleby
Copy link
Contributor

I'm not sure what you're trying to do in the failing test, so far as I can tell the code is right and the test is wrong.

I think the sort of test you want is something like:

  • one of the dependencies eg download-package has an additional marker eg python_version < "3.10"
  • provide an environment to the solver during the test ie with solver.use_environment(...)
  • confirm that when the marker is false in the environment, the extra is not installed

@abn
Copy link
Member Author

abn commented Jan 29, 2025

I'm not sure what you're trying to do in the failing test, so far as I can tell the code is right and the test is wrong.

You are quite possibly correct. I only looked at it briefly, and the test setup is incorrect. That said, there is also the issue of the marker not being propagated or being accounted for if it is on an extra dependency; which I had hoped #10119 would fix - but I reckon that was incomplete as well.

@abn abn force-pushed the fix/install-with-extra-hotham branch from 973c8f4 to e251296 Compare January 29, 2025 19:03
@abn
Copy link
Member Author

abn commented Jan 29, 2025

Sorry about the multiple threads, decided to go back to #10106 to keep things together. #10106 (comment)

@abn abn closed this Jan 29, 2025
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