Skip to content

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

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

Open
tomschr opened this issue Apr 22, 2020 · 2 comments · May be fixed by #367
Open

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

tomschr opened this issue Apr 22, 2020 · 2 comments · May be fixed by #367
Labels
Enhancement Not a bug, but increases or improves in value, quality, desirability, or attractiveness Question Unclear or open issue subject for debate Release_3.x.y Only for the major release 3

Comments

@tomschr
Copy link
Member

tomschr commented Apr 22, 2020

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

@tomschr tomschr added Release_3.x.y Only for the major release 3 Question Unclear or open issue subject for debate Enhancement Not a bug, but increases or improves in value, quality, desirability, or attractiveness labels Apr 22, 2020
tomschr added a commit to tomschr/python-semver that referenced this issue Nov 1, 2023
* Introduce Spec class to deal with such comparisons
* Improve documentation
* Simplify code in Version.match (delegates to Spec.match)
tomschr added a commit to tomschr/python-semver that referenced this issue Aug 13, 2024
* Introduce Spec class to deal with such comparisons
* Improve documentation
* Simplify code in Version.match (delegates to Spec.match)
@tomschr tomschr linked a pull request Aug 13, 2024 that will close this issue
@tomschr tomschr pinned this issue Nov 14, 2024
@levimatheri
Copy link

Any update on the progress of this?

@tomschr
Copy link
Member Author

tomschr commented Feb 25, 2025

@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
Labels
Enhancement Not a bug, but increases or improves in value, quality, desirability, or attractiveness Question Unclear or open issue subject for debate Release_3.x.y Only for the major release 3
Projects
None yet
2 participants