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

simplify python_version markers #826

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

radoering
Copy link
Member

@radoering radoering commented Jan 25, 2025

Examples of new simplifications:

  • python_version >= "3.8" and python_version < "3.9" -> python_version == "3.8"
  • python_version == "3.8" or python_version >= "3.9" -> python_version >= "3.8"

The downstream failures are caused by cosmetic changes. The tests are fixed in python-poetry/poetry#10110. We should probably merge this PR with failing downstream tests and switch from the released poetry-core version to the main branch afterwards.

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

Testing with the pyproject.toml from python-poetry/poetry#9956 (comment):

poetry version lock (--regenerate) lock (--no-update)
main 131 s 20 s
PR 101 s 19 s

Summary by Sourcery

Tests:

  • Added tests for the simplified version markers.

Examples of new simplifications:
`python_version >= "3.8" and python_version < "3.9"` -> `python_version == "3.8"`
`python_version == "3.8" or python_version >= "3.9"` -> `python_version >= "3.8"`
Copy link

sourcery-ai bot commented Jan 25, 2025

Reviewer's Guide by Sourcery

This pull request simplifies the logic for handling python_version markers, which can lead to more concise and efficient dependency specifications. The changes include improvements to marker intersection and union operations, as well as adjustments to how markers are represented in dependency specifications.

State diagram for Python version marker transformation

stateDiagram-v2
    [*] --> Original
    Original --> CheckPrecision: Check version precision
    CheckPrecision --> AdjustPrecision: Precision < target
    CheckPrecision --> CheckOperator: Precision == target
    AdjustPrecision --> ConvertMarker: For < or >= operators
    CheckOperator --> ConvertMarker: For < or >= operators
    ConvertMarker --> SimplifyMarker: Convert python_full_version to python_version
    SimplifyMarker --> [*]
Loading

Flow diagram for Python version marker simplification

graph TD
    A[Input Marker] --> B{Check Marker Type}
    B -->|python_version| C{Check Pattern}
    B -->|Other| D[Keep Original]
    C -->|Range Pattern| E["'>=3.8 and <3.9'"]
    C -->|Union Pattern| F["'==3.8 or >=3.9'"]
    E --> G["Simplify to '==3.8'"]
    F --> H["Simplify to '>=3.8'"]
    G --> I[Output Marker]
    H --> I
    D --> I
Loading

File-Level Changes

Change Details Files
Simplified marker intersection logic.
  • Added parameterized tests for marker intersection.
  • Modified the test_single_marker_intersect_compacts_constraints test to use the new parameterized tests.
  • The intersection of two version ranges now returns a single marker when possible.
tests/version/test_markers.py
Improved marker union logic.
  • Added a test case to verify that the union of two version markers returns a single marker when possible.
  • Added a test case to verify that the union of two version ranges returns a single marker when possible.
tests/version/test_markers.py
Adjusted marker representation in dependency specifications.
  • Updated tests to reflect the new marker representation.
  • The python_version marker is now simplified to the most concise representation possible.
tests/packages/test_main.py
tests/packages/test_dependency.py
tests/masonry/builders/test_sdist.py
tests/version/test_requirements.py
Fixed precision of python_full_version marker.
  • Ensured that the python_full_version marker has a precision of at least 3.
  • Adjusted the logic to convert python_full_version to python_version when possible.
src/poetry/core/version/markers.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 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 merged commit eccf08b into python-poetry:main Jan 25, 2025
17 of 18 checks passed
@radoering radoering mentioned this pull request Feb 9, 2025
3 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