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(add): do not pass @latest to parser #10069

Merged
merged 1 commit into from
Jan 18, 2025

Conversation

abn
Copy link
Member

@abn abn commented Jan 17, 2025

We should not pass in front-end specific @latest descriptor to the core requirement parser.

Relates-to: #10068

Summary by Sourcery

Strip out the '@latest' descriptor from requirements before parsing to prevent passing front-end specific descriptors to the core parser, and add a test to verify this behavior.

Bug Fixes:

  • Fix the issue where the '@latest' descriptor was incorrectly passed to the core requirement parser by stripping it out before parsing.

Tests:

  • Add a test to ensure that the '@latest' descriptor is stripped out before parsing and does not affect the package version selection.

@abn abn requested a review from a team January 17, 2025 18:56
Copy link

sourcery-ai bot commented Jan 17, 2025

Reviewer's Guide by Sourcery

This pull request addresses the issue of passing the '@latest' descriptor to the core requirement parser by stripping it from the requirement strings before parsing. A new test was added to ensure this behavior is correctly implemented.

Sequence diagram for requirement parsing without @latest

sequenceDiagram
    participant User
    participant AddCommand
    participant Parser

    User->>AddCommand: Add dependency
    AddCommand->>AddCommand: _parse_requirements()
    Note over AddCommand: Strip @latest descriptor
    AddCommand->>Parser: parse(cleaned_requirement)
    Parser-->>AddCommand: Parsed requirement
    AddCommand-->>User: Dependency added
Loading

Flow diagram for requirement string processing

flowchart LR
    A[Raw Requirement] -->|Input| B[Strip @latest]
    B -->|Regular Expression| C[Clean Requirement]
    C -->|Parse| D[Parsed Requirement]

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style D fill:#9f9,stroke:#333,stroke-width:2px
Loading

File-Level Changes

Change Details Files
Added a test to ensure '@latest' is stripped from requirements in the add command.
  • Added a new test function to check that '@latest' is removed from the requirement string before parsing.
  • Used a mocker spy to verify that the RequirementsParser's parse method is called with the correct arguments.
tests/console/commands/test_add.py
Modified the requirements parsing logic to strip '@latest' from requirement strings.
  • Updated the _parse_requirements method to use a regular expression to remove '@latest' from each requirement string before parsing.
src/poetry/console/commands/init.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.
  • 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

@abn abn force-pushed the fix/invalid-pep50-latest branch from 8a6b461 to 6fda3ae Compare January 17, 2025 18:57
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 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.

We should not pass in front-end specific `@latest` descriptor to the
core requirement parser.

Relates-to: python-poetry#10068
@abn abn force-pushed the fix/invalid-pep50-latest branch from 42dcea9 to 04b2afb Compare January 18, 2025 00:57
@abn abn merged commit 4d0301e into python-poetry:main Jan 18, 2025
73 checks passed
@abn abn deleted the fix/invalid-pep50-latest branch January 18, 2025 01:14
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