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

Extend PEP440 to include (_/-) as dev/post/pre-release separator #334

Merged
merged 5 commits into from
Jun 24, 2024

Conversation

ludeeus
Copy link
Owner

@ludeeus ludeeus commented Jun 24, 2024

Proposed change

Extends the PEP440 regex to allow for - and _ as pre-release separators.
Doc: https://peps.python.org/pep-0440/#pre-release-separators

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionalit)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass.
  • There is no commented out code in this PR.
  • The code has been formatted using Black (make lint)
  • Tests have been added to verify that the new code works.

Copy link

coderabbitai bot commented Jun 24, 2024

Warning

Rate limit exceeded

@ludeeus has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 38 minutes and 29 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between f6ff9cc and f24e025.

Walkthrough

The recent changes enhance the flexibility of the PEP440 version string matching in awesomeversion by updating the regular expressions and adding tests. This includes support for different suffixes (post, dev, rc) and improves version comparison functionality, addressing a key issue where certain versions couldn't be compared.

Changes

File Change Summary
awesomeversion/utils/regex.py Enhanced the regular expression pattern for PEP440-compatible version strings to better handle various version suffixes (post, dev, rc).
tests/issues/test_issue333.py Introduced a new test case to validate version comparison, especially with suffixes like rc, to address issue #333.
tests/snapshots/PEP 440/1-dev1.json Added versioning information following PEP 440, including attributes like modifier type, strategy, and validity for 1-dev1.
tests/snapshots/PEP 440/1.1-dev1.json Added versioning representation for 1.1-dev1 including detailed attributes such as major, minor, and dev version.
tests/test_strategy.py Added and updated version string variations in the list for testing ("1.1-dev1", "1.1dev1", "1.1_dev1").
tests/test_versions.py Modified version strings by using hyphens, underscores, and dots interchangeably to test parsing and comparison.

Sequence Diagram(s)

Not applicable.

Assessment against linked issues

Objective Addressed Explanation
Ensure awesomeversion can compare versions with suffixes ('rc') (#333)
Validate version comparison functionality for PEP 440 strings (#333)

These changes enhance the overall functionality and flexibility of the awesomeversion library, ensuring better compliance with the PEP 440 standards and resolving critical issues reported by users.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

@@ -17,7 +17,7 @@
)
RE_PEP440 = (
r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)"
r"(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?(\.rc(0|[1-9][0-9]*))?"
r"(0|[1-9][0-9]*))?([-_\.]?(post|dev|rc)(0|[1-9][0-9]*))*"
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Regex allows multiple consecutive separators.

The test with the input 1.1--dev1 matched, indicating that the regex currently permits multiple consecutive separators. This can lead to incorrect parsing of version strings.

  • Location: awesomeversion/utils/regex.py, line 20.

Recommendation: Modify the regex to disallow multiple consecutive separators.

Analysis chain

Ensure regex handles edge cases correctly.

The updated regex now allows for -, _, and . as optional separators between version components. Ensure this does not introduce any unintended matches, such as allowing multiple separators consecutively which could lead to incorrect version parsing.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify regex doesn't allow multiple separators consecutively.
# Test: Check regex pattern against invalid inputs. Expect: No matches for invalid inputs.
echo "1.1--dev1" | grep -P '([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?([-_\.]?(post|dev|rc)(0|[1-9][0-9]*))*'

Length of output: 153

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines 19 to 20
r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*"
r"?([-_\.]?(alpha|beta|c|d|dev|pre|preview|a|b|rc|post|r|rev)(0|[1-9][0-9]*))*"
Copy link

Choose a reason for hiding this comment

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

Ensure regex pattern does not allow multiple consecutive separators.

The updated regex pattern now supports additional separators (-, _, .). However, ensure it does not permit multiple consecutive separators as this can lead to incorrect parsing.

- r"?([-_\.]?(alpha|beta|c|d|dev|pre|preview|a|b|rc|post|r|rev)(0|[1-9][0-9]*))*"
+ r"?([-_\.]?)(alpha|beta|c|d|dev|pre|preview|a|b|rc|post|r|rev)(0|[1-9][0-9]*))"

Committable suggestion was skipped due to low confidence.

@ludeeus ludeeus changed the title Extend PEP440 to include (_/-) as pre-release seperator Extend PEP440 to include (_/-) as dev/post/pre-release separator Jun 24, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines 19 to 22
r"([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*" # Main segment
r"([-_\.]?(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))?" # Pre-release segment
r"([-_\.]?(post|r|rev)(0|[1-9][0-9]*))?" # Post-release segment
r"([-_\.]?(d|dev)(0|[1-9][0-9]*))?" # Development release segment
Copy link

Choose a reason for hiding this comment

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

Ensure regex pattern does not allow multiple consecutive separators.

The updated regex pattern supports additional separators (-, _, .) between different segments of version numbers. However, the pattern seems to allow multiple consecutive separators, which can lead to incorrect parsing of version strings. For instance, 1.1--dev1 would incorrectly be considered valid.

To address this, consider modifying the regex to disallow consecutive separators by ensuring that separators can only appear once between digits and letters.

- r"([-_\.]?(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))?"
- r"([-_\.]?(post|r|rev)(0|[1-9][0-9]*))?"
- r"([-_\.]?(d|dev)(0|[1-9][0-9]*))?"
+ r"([-_\.]?)(alpha|beta|c|pre|preview|a|b|rc)(0|[1-9][0-9]*))"
+ r"([-_\.]?)(post|r|rev)(0|[1-9][0-9]*))"
+ r"([-_\.]?)(d|dev)(0|[1-9][0-9]*))"

Committable suggestion was skipped due to low confidence.

@ludeeus ludeeus merged commit e01c153 into main Jun 24, 2024
9 checks passed
@ludeeus ludeeus deleted the extend-pep440 branch June 24, 2024 07:38
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.

Version comparison throws
1 participant