npm-style version ranges (Effect's SemVerRange)::
r = semver_range.parse_unsafe("^1.2.3 || >=3")
r.matches("1.9.0") # True
r.max_satisfying(["1.2.0", "1.4.1", "2.0.0"]) # SemVer 1.4.1The grammar is node-semver's: ^ / ~, comparators (<, <=,
>, >=, =), x-ranges (1.x, 1.2.*, *), hyphen ranges
(1.2.3 - 2) and || alternatives; build metadata is rejected. A
pre-release matches only through a bound with a pre-release on the same
MAJOR.MINOR.PATCH, unless include_prerelease. Two ranges are equal
when they format the same.
Values#
| Attribute | Type | Description |
|---|---|---|
any_ | SemVerRange |
|
Types#
| Type | Definition | Description |
|---|---|---|
Operator | type Operator = Literal['=', '<', '<=', '>', '>=', '~', '^'] | |
Input | type Input = SemVerRange | str |
Classes#
Functions#
parse#
parse(text) -> Result[SemVerRange, SemVerError]An npm-style range, or the reason it is not one; blank text is *.
| Parameter | Type | Description |
|---|---|---|
text | str |
Returns Result[SemVerRange, SemVerError]
def parse(text: str) -> Result[SemVerRange, SemVerError]:
"""An npm-style range, or the reason it is not one; blank text is ``*``."""
return try_parse("SemVer range", text, _parse_or_raise)parse_unsafe#
parse_unsafe(text) -> SemVerRangeparse; raises its SemVerError.
| Parameter | Type | Description |
|---|---|---|
text | str |
Returns SemVerRange
def parse_unsafe(text: str) -> SemVerRange:
"""``parse``; raises its ``SemVerError``."""
return _or_raise(parse(text))from_input#
from_input(value) -> Result[SemVerRange, SemVerError]| Parameter | Type | Description |
|---|---|---|
value | Input |
Returns Result[SemVerRange, SemVerError]
def from_input(value: Input) -> Result[SemVerRange, SemVerError]:
return Ok(value) if isinstance(value, SemVerRange) else parse(value)from_input_unsafe#
from_input_unsafe(value) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
value | Input |
Returns SemVerRange
def from_input_unsafe(value: Input) -> SemVerRange:
return _or_raise(from_input(value))exact#
exact(version) -> SemVerRange=version (build metadata dropped); raises SemVerError for an
invalid version, as the other constructors do.
| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def exact(version: VersionInput) -> SemVerRange:
"""``=version`` (build metadata dropped); raises ``SemVerError`` for an
invalid version, as the other constructors do."""
return _single("=", version)greater_than#
greater_than(version) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def greater_than(version: VersionInput) -> SemVerRange:
return _single(">", version)greater_than_or_equal_to#
greater_than_or_equal_to(version) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def greater_than_or_equal_to(version: VersionInput) -> SemVerRange:
return _single(">=", version)less_than#
less_than(version) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def less_than(version: VersionInput) -> SemVerRange:
return _single("<", version)less_than_or_equal_to#
less_than_or_equal_to(version) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def less_than_or_equal_to(version: VersionInput) -> SemVerRange:
return _single("<=", version)caret#
caret(version) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def caret(version: VersionInput) -> SemVerRange:
return _single("^", version)tilde#
tilde(version) -> SemVerRange| Parameter | Type | Description |
|---|---|---|
version | VersionInput |
Returns SemVerRange
def tilde(version: VersionInput) -> SemVerRange:
return _single("~", version)between#
between(*, minimum, maximum) -> SemVerRange>=minimum <=maximum.
| Parameter | Type | Description |
|---|---|---|
minimum | VersionInput | |
maximum | VersionInput |
Returns SemVerRange
def between(*, minimum: VersionInput, maximum: VersionInput) -> SemVerRange:
"""``>=minimum <=maximum``."""
return SemVerRange(((_clause(">=", minimum), _clause("<=", maximum)),))