Version
Version
Bases: Representation
, String
Represents versions.
Source code in versions/version.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 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 146 147 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 174 175 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 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 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 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 |
|
epoch: Epoch = field(factory=Epoch, eq=False, order=False)
class-attribute
instance-attribute
The epoch segment of the version.
release: Release = field(factory=Release, eq=False, order=False)
class-attribute
instance-attribute
The release segment of the version.
pre: Optional[PreTag] = field(default=None, eq=False, order=False)
class-attribute
instance-attribute
The pre-release tag of the version.
post: Optional[PostTag] = field(default=None, eq=False, order=False)
class-attribute
instance-attribute
The post-release tag of the version.
dev: Optional[DevTag] = field(default=None, eq=False, order=False)
class-attribute
instance-attribute
The dev-release tag of the version.
local: Optional[Local] = field(default=None, eq=False, order=False)
class-attribute
instance-attribute
The local segment of the version.
precision: int
property
The precision of the Release
.
last_index: int
property
The last index of the Release
.
major: int
property
The major part of the Release
.
minor: int
property
The minor part of the Release
.
micro: int
property
The micro part of the Release
.
extra: Extra
property
The extra parts of the Release
.
from_string(string: str) -> Self
classmethod
Parses a Version
from string
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string |
str
|
The string to parse. |
required |
Returns:
Type | Description |
---|---|
Self
|
The parsed version. |
Source code in versions/version.py
110 111 112 113 114 115 116 117 118 119 120 |
|
to_string() -> str
Converts a Version
to its string representation.
Returns:
Type | Description |
---|---|
str
|
The version string. |
Source code in versions/version.py
187 188 189 190 191 192 193 |
|
to_short_string() -> str
Converts a Version
to its short string representation.
Returns:
Type | Description |
---|---|
str
|
The short version string. |
Source code in versions/version.py
195 196 197 198 199 200 201 |
|
to_pep440_string() -> str
Converts a Version
to its
PEP 440 representation.
version.to_pep440_string()
Is equivalent to the following:
version.normalize().to_short_string()
Returns:
Type | Description |
---|---|
str
|
The PEP 440 version string. |
Source code in versions/version.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
get_at(index: int, default: int = DEFAULT_VALUE) -> int
Gets the Release
part at the index
,
defaulting to default
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The index of the part to get. |
required |
default |
int
|
The default value to use. |
DEFAULT_VALUE
|
Returns:
Type | Description |
---|---|
int
|
The release part at |
Source code in versions/version.py
260 261 262 263 264 265 266 267 268 269 270 271 |
|
get_at_unchecked(index: int) -> int
Gets the Release
part at the index
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The index of the part to get. |
required |
Raises:
Type | Description |
---|---|
IndexError
|
The index is out-of-bounds. |
Returns:
Type | Description |
---|---|
int
|
The release part at the |
Source code in versions/version.py
273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
is_semantic() -> bool
Checks if the Release
matches the semantic versioning schema.
Returns:
Type | Description |
---|---|
bool
|
Whether the release matches the |
Source code in versions/version.py
287 288 289 290 291 292 293 294 |
|
to_semantic() -> Self
Converts the Release
to match the SemVer
schema.
Returns:
Type | Description |
---|---|
Self
|
The converted version. |
Source code in versions/version.py
296 297 298 299 300 301 302 303 |
|
set_major(value: int) -> Self
Sets the major part of the Release
to the value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
int
|
The value to set the major part to. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
320 321 322 323 324 325 326 327 328 329 |
|
set_minor(value: int) -> Self
Sets the minor part of the Release
to the value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
int
|
The value to set the minor part to. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
331 332 333 334 335 336 337 338 339 340 |
|
set_micro(value: int) -> Self
Sets the micro part of the Release
to the value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
int
|
The value to set the micro part to. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
342 343 344 345 346 347 348 349 350 351 |
|
set_patch(value: int) -> Self
Sets the patch part of the Release
to the value
.
This is equivalent to set_micro
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
int
|
The value to set the patch part to. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
353 354 355 356 357 358 359 360 361 362 363 364 |
|
set_at(index: int, value: int) -> Self
Sets the Release
part at the index
to the value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The index to set the |
required |
value |
int
|
The value to set the part to. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
366 367 368 369 370 371 372 373 374 375 376 |
|
set_at_unchecked(index: int, value: int) -> Self
Sets the Release
part at the index
to the value
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The index to set the |
required |
value |
int
|
The value to set the part to. |
required |
Raises:
Type | Description |
---|---|
IndexError
|
The index is out-of-bounds. |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
next_major() -> Self
Bumps the major part of the Release
if the version is stable, otherwise converts the version to be stable.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
next_minor() -> Self
Bumps the minor part of the Release
if the version is stable, otherwise converts the version to be stable.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
next_micro() -> Self
Bumps the micro part of the Release
if the version is stable, otherwise converts the version to be stable.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
next_patch() -> Self
Bumps the patch part of the Release
if the version is stable, otherwise converts the version to be stable.
This is equivalent to next_micro
.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
|
next_at(index: int) -> Self
Bumps the part of the Release
at the index
if the version is stable, otherwise converts the version to be stable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The index to bump the part at. |
required |
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
has_major() -> bool
Checks if the Release
has the major part.
Returns:
Type | Description |
---|---|
bool
|
Whether the major part is present. |
Source code in versions/version.py
471 472 473 474 475 476 477 |
|
has_minor() -> bool
Checks if the Release
has the minor part.
Returns:
Type | Description |
---|---|
bool
|
Whether the minor part is present. |
Source code in versions/version.py
479 480 481 482 483 484 485 |
|
has_micro() -> bool
Checks if the Release
has the micro part.
Returns:
Type | Description |
---|---|
bool
|
Whether the micro part is present. |
Source code in versions/version.py
487 488 489 490 491 492 493 |
|
has_patch() -> bool
Checks if the Release
has the patch part.
This is equivalent to has_micro
.
Returns:
Type | Description |
---|---|
bool
|
Whether the patch part is present. |
Source code in versions/version.py
495 496 497 498 499 500 501 502 503 |
|
has_extra() -> bool
Checks if the Release
has any extra parts.
Returns:
Type | Description |
---|---|
bool
|
Whether the extra parts are present. |
Source code in versions/version.py
505 506 507 508 509 510 511 |
|
has_at(index: int) -> bool
Checks if the Release
has a part at the index
.
Returns:
Type | Description |
---|---|
bool
|
Whether the part at the |
Source code in versions/version.py
513 514 515 516 517 518 519 |
|
pad_to(length: int, padding: int = DEFAULT_PADDING) -> Self
Pads the Release
to the length
with padding
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
length |
int
|
The length to pad the release to. |
required |
padding |
int
|
The padding to use. |
DEFAULT_PADDING
|
Returns:
Type | Description |
---|---|
Self
|
The padded version. |
Source code in versions/version.py
521 522 523 524 525 526 527 528 529 530 531 |
|
pad_to_index(index: int, padding: int = DEFAULT_PADDING) -> Self
Pads the Release
to the index
with padding
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The index to pad the release to. |
required |
padding |
int
|
The padding to use. |
DEFAULT_PADDING
|
Returns:
Type | Description |
---|---|
Self
|
The padded version. |
Source code in versions/version.py
533 534 535 536 537 538 539 540 541 542 543 |
|
pad_to_next(padding: int = DEFAULT_PADDING) -> Self
Pads the Release
to the next index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
padding |
int
|
The padding to use. |
DEFAULT_PADDING
|
Returns:
Type | Description |
---|---|
Self
|
The padded version. |
Source code in versions/version.py
545 546 547 548 549 550 551 552 553 554 |
|
is_pre_release() -> bool
Checks if the version is pre-release.
Returns:
Type | Description |
---|---|
bool
|
Whether the version is pre-release. |
Source code in versions/version.py
556 557 558 559 560 561 562 |
|
is_post_release() -> bool
Checks if the version is post-release.
Returns:
Type | Description |
---|---|
bool
|
Whether the version is post-release. |
Source code in versions/version.py
564 565 566 567 568 569 570 |
|
is_dev_release() -> bool
Checks if the version is dev-release.
Returns:
Type | Description |
---|---|
bool
|
Whether the version is dev-release. |
Source code in versions/version.py
572 573 574 575 576 577 578 |
|
is_local() -> bool
Checks if the version is local.
Returns:
Type | Description |
---|---|
bool
|
Whether the version is local. |
Source code in versions/version.py
580 581 582 583 584 585 586 |
|
is_unstable() -> bool
Checks if the version is unstable.
Returns:
Type | Description |
---|---|
bool
|
Whether the version is unstable. |
Source code in versions/version.py
588 589 590 591 592 593 594 |
|
is_stable() -> bool
Checks if the version is stable.
Returns:
Type | Description |
---|---|
bool
|
Whether the version is stable. |
Source code in versions/version.py
596 597 598 599 600 601 602 |
|
next_pre() -> Self
Bumps the PreTag
if it is present,
otherwise adds one to the version.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
|
next_pre_phase() -> Optional[Self]
Bumps the PreTag
phase if it is present (and if possible),
otherwise adds one to the version.
Returns:
Type | Description |
---|---|
Optional[Self]
|
The bumped version (if the next |
Source code in versions/version.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
|
next_post() -> Self
Bumps the PostTag
if it is present,
otherwise adds one to the version.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
next_dev() -> Self
Bumps the DevTag
if it is present,
otherwise adds one to the version.
Returns:
Type | Description |
---|---|
Self
|
The bumped version. |
Source code in versions/version.py
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
|
with_pre(pre: PreTag) -> Self
Updates a version to include PreTag
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pre |
PreTag
|
The pre-release tag to include. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
711 712 713 714 715 716 717 718 719 720 |
|
with_post(post: PostTag) -> Self
Updates a version to include PostTag
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
post |
PostTag
|
The post-release tag to include. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
722 723 724 725 726 727 728 729 730 731 |
|
with_dev(dev: DevTag) -> Self
Updates a version to include DevTag
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dev |
DevTag
|
The dev-release tag to include. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
733 734 735 736 737 738 739 740 741 742 |
|
with_local(local: Local) -> Self
Updates a version to include Local
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local |
Local
|
The local segment to include. |
required |
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
747 748 749 750 751 752 753 754 755 756 |
|
without_pre() -> Self
Updates a version, removing any PreTag
from it.
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
764 765 766 767 768 769 770 |
|
without_post() -> Self
Updates a version, removing any PostTag
from it.
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
772 773 774 775 776 777 778 |
|
without_dev() -> Self
Updates a version, removing any DevTag
from it.
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
780 781 782 783 784 785 786 |
|
without_local() -> Self
Updates a version, removing any Local
segment from it.
Returns:
Type | Description |
---|---|
Self
|
The updated version. |
Source code in versions/version.py
791 792 793 794 795 796 797 |
|
weaken(other: Self) -> Self
Weakens the other
version for further comparison.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Self
|
The version to weaken. |
required |
Returns:
Type | Description |
---|---|
Self
|
The weakened version. |
Source code in versions/version.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
|
to_stable() -> Self
Forces a version to be stable.
Returns:
Type | Description |
---|---|
Self
|
The stable version. |
Source code in versions/version.py
822 823 824 825 826 827 828 |
|
to_stable_unchecked() -> Self
Forces a version to be stable, without checking whether it is already stable.
Returns:
Type | Description |
---|---|
Self
|
The stable version. |
Source code in versions/version.py
830 831 832 833 834 835 836 |
|
next_breaking() -> Self
Returns the next breaking version.
This function is slightly convoluted due to how 0.x.y
and 0.0.z
versions are handled:
version | next breaking |
---|---|
1.2.3 |
2.0.0 |
1.2.0 |
2.0.0 |
1.0.0 |
2.0.0 |
0.2.3 |
0.3.0 |
0.0.3 |
0.0.4 |
0.0.0 |
0.0.1 |
0.0 |
0.1.0 |
0 |
1.0.0 |
Returns:
Type | Description |
---|---|
Self
|
The next breaking |
Source code in versions/version.py
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 |
|
normalize() -> Self
Normalizes all version tags.
Returns:
Type | Description |
---|---|
Self
|
The normalized version. |
Source code in versions/version.py
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
|
create(epoch: Optional[Epoch] = None, release: Optional[Release] = None, pre: Optional[PreTag] = None, post: Optional[PostTag] = None, dev: Optional[DevTag] = None, local: Optional[Local] = None) -> Self
classmethod
Creates a Version
from epoch
, release
,
pre
, post
, dev
and local
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch |
Optional[Epoch]
|
The epoch to use. |
None
|
release |
Optional[Release]
|
The release to use. |
None
|
pre |
Optional[PreTag]
|
The pre-release tag to use. |
None
|
post |
Optional[PostTag]
|
The post-release tag to use. |
None
|
dev |
Optional[DevTag]
|
The dev-release tag to use. |
None
|
local |
Optional[Local]
|
The local segment to use. |
None
|
Returns:
Type | Description |
---|---|
Self
|
The newly created |
Source code in versions/version.py
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 |
|
from_parts(*parts: int, epoch: Optional[Epoch] = None, pre: Optional[PreTag] = None, post: Optional[PostTag] = None, dev: Optional[DevTag] = None, local: Optional[Local] = None) -> Self
classmethod
Creates a Version
from parts
,
epoch
, pre
, post
, dev
and local
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*parts |
int
|
The parts of the release to use. |
()
|
epoch |
Optional[Epoch]
|
The epoch to use. |
None
|
pre |
Optional[PreTag]
|
The pre-release tag to use. |
None
|
post |
Optional[PostTag]
|
The post-release tag to use. |
None
|
dev |
Optional[DevTag]
|
The dev-release tag to use. |
None
|
local |
Optional[Local]
|
The local segment to use. |
None
|
Returns:
Type | Description |
---|---|
Self
|
The newly created |
Source code in versions/version.py
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 |
|
matches(specification: Specification) -> bool
Checks if a version matches the specification
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
specification |
Specification
|
The specification to check the version against. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the version matches the specification. |
Source code in versions/version.py
955 956 957 958 959 960 961 962 963 964 |
|