Skip to content

Implement Extended Version Comparisons (Ranges, Hyphens, Tilde...) #241

Open

Description

@tomschr

Situation

Currently, semver.VersionInfo semver.Version contains a match method. However, it does support only a limited number of comparisons. For example, ~ or ^ as known in NPM is unknown.

Proposal

Add an additional class which provides all the necessary functionality. How this is implemented is a matter of design. 😉

I'd suggest to add this after major 3 is released.

This could be the use cases (I use a class Spec here, but the naming is subject to change):

>>> import semver
>>> spec = semver.Spec(">=1.0 <= 1.7")
>>> ver = semver.Version.parse("1.2.0")

>>> spec in ver
True
>>> spec.match(ver)
True

Depending on how we want to design it, it could also influence, for example, semver.Version.match. Maybe we should (re)move that and move this functionality into a future Spec class? Wouldn't it a bit more appropriate there?

@python-semver/reviewers What do you think about this idea? Any preferences?

Grammar

range-set  ::= range ( logical-or range ) *
logical-or ::= ( ' ' ) * '||' ( ' ' ) *
range      ::= hyphen | simple ( ' ' simple ) * | ''
hyphen     ::= partial ' - ' partial
simple     ::= primitive | partial | tilde | caret
primitive  ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial
partial    ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
xr         ::= 'x' | 'X' | '*' | nr
nr         ::= '0' | ['1'-'9'] ( ['0'-'9'] ) *
tilde      ::= '~' partial
caret      ::= '^' partial
qualifier  ::= ( '-' pre )? ( '+' build )?
pre        ::= parts
build      ::= parts
parts      ::= part ( '.' part ) *
part       ::= nr | [-0-9A-Za-z]+

See Also

Activity

  1. added
    Release_3.x.yOnly for the major release 3
    QuestionUnclear or open issue subject for debate
    EnhancementNot a bug, but increases or improves in value, quality, desirability, or attractiveness
    on Apr 22, 2020
  2. linked a pull request that will close this issue(not semver) Support complex filters #53on Apr 24, 2020
  3. added a commit that references this issue on Nov 1, 2023
    065f013
  4. added a commit that references this issue on Aug 13, 2024
    fb58e48
  5. linked a pull request that will close this issueFix #241: Implement tilde and caret matching #367on Aug 13, 2024
  6. pinned this issue on Nov 14, 2024
  7. levimatheri commented on Feb 25, 2025

    @levimatheri

    Any update on the progress of this?

  8. tomschr commented on Feb 25, 2025

    @tomschr
    MemberAuthor

    @levimatheri

    Any update on the progress of this?

    Thanks for asking! I've tried different approaches, you can find one in #367. None of them were very convincing, so I'm not sure yet how to proceed.

    If you have a good implementation idea, I'd like to hear it. Share it here. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNot a bug, but increases or improves in value, quality, desirability, or attractivenessQuestionUnclear or open issue subject for debateRelease_3.x.yOnly for the major release 3

    Type

    No type

    Fields

    SIze

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions