Operators
Matches = Binary[Version, Version, bool]
module-attribute
The (version, against) -> bool
function.
PartialMatches = Unary[Version, bool]
module-attribute
The (version) -> bool
function.
Translate = Unary[Version, VersionSet]
module-attribute
The (version) -> version_set
function.
OperatorType
Bases: Enum
Represents operator types.
Source code in versions/operators.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
|
TILDE_EQUAL = TILDE_EQUAL
class-attribute
instance-attribute
The binary ~=
operator.
DOUBLE_EQUAL = DOUBLE_EQUAL
class-attribute
instance-attribute
The binary ==
operator.
NOT_EQUAL = NOT_EQUAL
class-attribute
instance-attribute
The binary !=
operator.
LESS = LESS
class-attribute
instance-attribute
The binary <
operator.
LESS_OR_EQUAL = LESS_OR_EQUAL
class-attribute
instance-attribute
The binary <=
operator.
GREATER = GREATER
class-attribute
instance-attribute
The binary >
operator.
GREATER_OR_EQUAL = GREATER_OR_EQUAL
class-attribute
instance-attribute
The binary >=
operator.
CARET = CARET
class-attribute
instance-attribute
The unary ^
operator.
EQUAL = EQUAL
class-attribute
instance-attribute
The binary =
operator.
TILDE = TILDE
class-attribute
instance-attribute
The unary ~
operator.
WILDCARD_DOUBLE_EQUAL = WILDCARD_DOUBLE_EQUAL
class-attribute
instance-attribute
The wildcard binary ==*
operator.
WILDCARD_EQUAL = WILDCARD_EQUAL
class-attribute
instance-attribute
The wildcard binary =*
operator.
WILDCARD_NOT_EQUAL = WILDCARD_NOT_EQUAL
class-attribute
instance-attribute
The wildcard binary !=*
operator.
is_wildcard() -> bool
Checks if an operator is wildcard.
Returns:
Type | Description |
---|---|
bool
|
Whether the operator is wildcard. |
Source code in versions/operators.py
736 737 738 739 740 741 742 |
|
is_unary() -> bool
Checks if an operator is unary.
Returns:
Type | Description |
---|---|
bool
|
Whether the operator is unary. |
Source code in versions/operators.py
750 751 752 753 754 755 756 |
|
Operator
Bases: Representation
, ToString
Represents operators.
Source code in versions/operators.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
|
type: OperatorType
instance-attribute
The operator type.
version: Version
instance-attribute
The operator version.
matches: Matches
property
The matches
function representing the operator.
translate: Translate
property
The translate
function representing the operator.
partial_matches: PartialMatches
property
The partial matches
function with
self.version
as the against
version.
is_unary() -> bool
Checks if an operator is unary.
Returns:
Type | Description |
---|---|
bool
|
Whether the operator is unary. |
Source code in versions/operators.py
861 862 863 864 865 866 867 |
|
is_wildcard() -> bool
Checks if an operator is wildcard.
Returns:
Type | Description |
---|---|
bool
|
Whether the operator is wildcard. |
Source code in versions/operators.py
869 870 871 872 873 874 875 |
|
to_string() -> str
Converts an Operator
to its string representation.
Returns:
Type | Description |
---|---|
str
|
The operator string. |
Source code in versions/operators.py
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
|
to_short_string() -> str
Converts an Operator
to its short string representation.
Returns:
Type | Description |
---|---|
str
|
The short operator string. |
Source code in versions/operators.py
970 971 972 973 974 975 976 977 978 979 980 981 982 |
|
next_caret_breaking(version: V) -> V
Returns the next breaking version according to the caret (^
) strategy.
This function is slightly convoluted due to handling 0.x.y
and 0.0.z
versions.
See next_breaking
for more information.
Example
>>> from versions import next_caret_breaking, parse_version
>>> version = parse_version("1.0.0")
>>> version
<Version (1.0.0)>
>>> next_caret_breaking(version)
<Version (2.0.0)>
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
V
|
The version to find next breaking version of. |
required |
Returns:
Type | Description |
---|---|
V
|
The next breaking version according to the |
Source code in versions/operators.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
next_tilde_equal_breaking(version: V) -> V
Returns the next breaking version according to the tilde-equal (~=
) strategy.
This function simply bumps the second to last part of the release.
Example
>>> from versions import next_tilde_equal_breaking, parse_version
>>> version = parse_version("1.2.0")
>>> version
<Version (1.2.0)>
>>> next_tilde_equal_breaking(version)
<Version (1.3.0)>
>>> invalid = parse_version("1")
>>> next_tilde_equal_breaking(invalid)
Traceback (most recent call last):
...
ValueError: `~=` can not be used with with a single version segment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
V
|
The version to find the next breaking version of. |
required |
Returns:
Type | Description |
---|---|
V
|
The next breaking |
Source code in versions/operators.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
next_tilde_breaking(version: V) -> V
Returns the next breaking version according to the tilde (~
) strategy.
This function simply bumps the minor part of the release if it is present, otherwise the major part is bumped.
Example
>>> from versions import next_tilde_equal_breaking, parse_version
>>> version = parse_version("2.1.0")
>>> version
<Version (2.1.0)>
>>> next_tilde_breaking(version)
<Version (2.2.0)>
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
V
|
The version to find the next breaking version of. |
required |
Returns:
Type | Description |
---|---|
V
|
The next breaking |
Source code in versions/operators.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
next_wildcard_breaking(version: V) -> Optional[V]
Returns the next breaking version according to the wildcard (*
) strategy.
There are three cases to handle:
-
If the wildcard is used within the pre-release tag of the version, next breaking version has the same release with pre-release tag removed. For example,
x.y.z-rc.*
is bumped tox.y.z
. -
If the wildcard is used within the post-release tag of the version, next breaking version has the last part of the release bumped. For instance,
x.y.z-post.*
is bumped tox.y.z'
, wherez' = z + 1
. -
Otherwise, the second to last part of the release is bumped. For example,
x.y.*
is bumped tox.y'.0
, wherey' = y + 1
.
Note
This function returns None
if the given version is *
.
Example
>>> from versions import next_wildcard_breaking, parse_version
>>> version = parse_version("4.2.0")
>>> version
<Version (4.2.0)>
>>> next_wildcard_breaking(version)
<Version (4.3.0)>
>>> other = parse_version("1.2.3-rc.0")
>>> other
<Version (1.2.3-rc.0)>
>>> next_wildcard_breaking(other)
<Version (1.2.3)>
>>> another = parse_version("0.6.8-post.0")
>>> another
<Version (0.6.8-post.0)>
>>> next_wildcard_breaking(another)
<Version (0.6.9)> # nice
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
V
|
The version to find the next breaking version of. |
required |
Returns:
Type | Description |
---|---|
Optional[V]
|
Source code in versions/operators.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
matches_caret(version: Version, against: Version) -> bool
Checks if the version
matches the caret (^
) specification.
This is equivalent to:
against <= version < next_caret_breaking(against)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
matches_tilde_equal(version: Version, against: Version) -> bool
Checks if the version
matches the tilde-equal (~=
) specification.
This is equivalent to:
against <= version < next_tilde_equal_breaking(against)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
matches_tilde(version: Version, against: Version) -> bool
Checks if the version
matches the tilde (~
) specification.
This is equivalent to:
against <= version < next_tilde_breaking(against)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
matches_equal(version: Version, against: Version) -> bool
Checks if the version
matches the equal (=
) specification.
This is equivalent to:
version == against
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
matches_not_equal(version: Version, against: Version) -> bool
Checks if the version
matches the not-equal (!=
) specification.
This is equivalent to:
version != against
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
matches_less(version: Version, against: Version) -> bool
Checks if the version
matches the less (<
) specification.
This is equivalent to:
version < against
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
matches_less_or_equal(version: Version, against: Version) -> bool
Checks if the version
matches the less-or-equal (<=
) specification.
This is equivalent to:
version <= against
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
matches_greater(version: Version, against: Version) -> bool
Checks if the version
matches the greater (>
) specification.
This is equivalent to:
version > against
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
matches_greater_or_equal(version: Version, against: Version) -> bool
Checks if the version
matches the greater-or-equal (>=
) specification.
This is equivalent to:
version >= against
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
matches_wildcard_equal(version: Version, against: Version) -> bool
Checks if the version
matches the wildcard-equal (=*
) specification.
This is equivalent to:
wildcard = next_wildcard_breaking(against)
wildcard is None or against <= version < wildcard
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
matches_wildcard_not_equal(version: Version, against: Version) -> bool
Checks if the version
matches the wildcard-not-equal (!=*
) specification.
This is equivalent to:
wildcard = next_wildcard_breaking(against)
wildcard is not None and (version < against or version >= wildcard)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to check. |
required |
against |
Version
|
The version to check the |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the |
Source code in versions/operators.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
translate_caret(version: Version) -> VersionRange
Translates the version
into a version set according to the caret (^
) strategy.
This function returns the [version, next_caret_breaking(version))
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the caret specification. |
Source code in versions/operators.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
translate_tilde_equal(version: Version) -> VersionRange
Translates the version
into a version set according to the tilde-equal (~=
) strategy.
This function returns the [version, next_tilde_equal_breaking(version))
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the tilde-equal specification. |
Source code in versions/operators.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
|
translate_tilde(version: Version) -> VersionRange
Translates the version
into a version set according to the tilde (~
) strategy.
This function returns the [version, next_tilde_breaking(version))
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the tilde-equal specification. |
Source code in versions/operators.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
|
translate_equal(version: Version) -> VersionPoint
Translates the version
into a version set according to the equal (=
) strategy.
This function returns the [version, version]
range (aka single version
, {version}
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionPoint
|
The version set representing the equal specification. |
Source code in versions/operators.py
526 527 528 529 530 531 532 533 534 535 536 537 |
|
translate_not_equal(version: Version) -> VersionUnion
Translates the version
into a version set according to the not-equal (!=
) strategy.
This function returns the (ε, version) | (version, ω)
union.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionUnion
|
The version set representing the not-equal specification. |
Source code in versions/operators.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
translate_less(version: Version) -> VersionRange
Translates the version
into a version set according to the less (<
) strategy.
This function returns the (ε, version)
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the less specification. |
Source code in versions/operators.py
562 563 564 565 566 567 568 569 570 571 572 573 |
|
translate_less_or_equal(version: Version) -> VersionRange
Translates the version
into a version set according to the less-or-equal (<=
) strategy.
This function returns the (ε, version]
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the less-or-equal specification. |
Source code in versions/operators.py
576 577 578 579 580 581 582 583 584 585 586 587 |
|
translate_greater(version: Version) -> VersionRange
Translates the version
into a version set according to the greater (>
) strategy.
This function returns the (version, ω)
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the greater specification. |
Source code in versions/operators.py
590 591 592 593 594 595 596 597 598 599 600 601 |
|
translate_greater_or_equal(version: Version) -> VersionRange
Translates the version
into a version set according to
the greater-or-equal (>=
) strategy.
This function returns the [version, ω)
range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the greater-or-equal specification. |
Source code in versions/operators.py
604 605 606 607 608 609 610 611 612 613 614 615 616 |
|
translate_wildcard_equal(version: Version) -> VersionRange
Translates the version
into a version set according to
the wildcard-equal (==*
) strategy.
This function returns the [version, next_wildcard_version(version))
range in most cases,
except for when the version is *
; then the (ε, ω)
range is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
VersionRange
|
The version set representing the wildcard-equal specification. |
Source code in versions/operators.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
|
translate_wildcard_not_equal(version: Version) -> Union[VersionEmpty, VersionUnion]
Translates the version
into a version set according to
the wildcard-not-equal (!=*
) strategy.
This function returns the (ε, version) | (next_wildcard_breaking(version), ω)
union
in most cases, except for when the version is *
; then the 0
empty set is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version |
Version
|
The version to translate. |
required |
Returns:
Type | Description |
---|---|
Union[VersionEmpty, VersionUnion]
|
The version set representing the wildcard-not-equal specification. |
Source code in versions/operators.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|