Description
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]+