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(env): isolated env must validate requirements #10048

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

abn
Copy link
Member

@abn abn commented Jan 15, 2025

This change ensures that when an isolated environment is created, the temporary lockfile created does not consider dependencies that are not valid for the environment. This reduces the possibility of constraint errors when building dependencies from source that use complex build-system requirements.

Resolves: #8409

Summary by Sourcery

Validate dependencies before installing them in an isolated environment. This prevents constraint errors during dependency resolution, especially for complex build systems.

Bug Fixes:

  • Fixed an issue where invalid dependencies could cause constraint errors when building in an isolated environment.

Tests:

  • Added tests to verify that only valid dependencies are installed in an isolated environment.

@abn abn requested a review from a team January 15, 2025 03:59
This change ensures that when an isolated environment is created, the
temporary lockfile created does not consider dependencies that are not
valid for the environment. This reduces the possibility of constraint
errors when building dependencies from source that use complex
build-system requirements.

Resolves: python-poetry#8409
@abn
Copy link
Member Author

abn commented Jan 15, 2025

@sourcery-ai review

Copy link

sourcery-ai bot commented Jan 15, 2025

Reviewer's Guide by Sourcery

This pull request fixes a bug in the isolated environment creation process where invalid dependencies were considered during temporary lockfile creation. This change ensures that only valid dependencies for the target environment are considered, reducing the risk of constraint errors during dependency resolution.

Sequence diagram for isolated environment dependency validation

sequenceDiagram
    participant IsolatedEnv as IsolatedEnvironment
    participant Package as ProjectPackage
    participant Dep as Dependency
    participant Marker as Marker

    IsolatedEnv->>Package: Create root package
    IsolatedEnv->>IsolatedEnv: Get environment markers
    loop For each requirement
        IsolatedEnv->>Dep: Create from PEP 508
        IsolatedEnv->>Marker: Validate dependency marker
        alt Marker is empty or valid
            IsolatedEnv->>Package: Add dependency
        else Invalid for environment
            Note over IsolatedEnv: Skip dependency
        end
    end
Loading

Flow diagram for dependency validation process

flowchart TD
    A[Start] --> B[Create root package]
    B --> C[Get environment markers]
    C --> D[Get next requirement]
    D --> E{Create dependency}
    E --> F{Check marker}
    F -->|Empty marker| H[Add dependency]
    F -->|Valid for env| H
    F -->|Invalid for env| I[Skip dependency]
    H --> J{More requirements?}
    I --> J
    J -->|Yes| D
    J -->|No| K[End]
Loading

File-Level Changes

Change Details Files
Discard requirements not valid for the current environment during isolated environment creation
  • Added logic to filter out invalid dependencies based on environment markers when installing packages in an isolated environment.
  • Added a test case to verify that requirements incompatible with the isolated environment are discarded during installation and do not cause constraint errors during dependency resolution.
src/poetry/utils/isolated_build.py
tests/utils/test_isolated_build.py
Updated virtual environment calls
  • Modified the expected virtual environment call count in a test case to reflect changes in the virtual environment interaction during package information retrieval. This update ensures consistent test results after the changes in dependency handling within the isolated environment.
tests/inspection/test_info.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

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 @abn - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Could you explain why the expected VirtualEnv.run call count in test_info_setup_simple increased from 4 to 6? This change seems unrelated to the main PR changes.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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.

tests/utils/test_isolated_build.py Show resolved Hide resolved
Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

This only sorts out direct dependencies. Transitive dependencies that are not valid for the environment will still be considered. However, since it is a simple change and a clear improvement - and a complete fix would take more effort - I think we can merge it anyway.

@abn abn merged commit d63da5f into python-poetry:main Jan 16, 2025
73 checks passed
@abn abn deleted the issues/8409 branch January 16, 2025 09:16
@finswimmer finswimmer mentioned this pull request Feb 6, 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.

Pedantic IncompatibleConstraintsError with scipy 1.11.2 on Debian
3 participants