1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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
|
.. _VERSIONING:
Versioning
##########
The :mod:`pyTooling.Versioning` package provides auxiliary classes to implement :ref:`VERSIONING/SemanticVersion`
(following `SemVer <https://semver.org/>`__ rules) and :ref:`VERSIONING/CalendarVersion` (following
`CalVer <https://calver.org/>`__ rules). The latter one has multiple variants due to the meaning of the version's parts
like: year-month version or year-week version.
Versions can be grouped by :ref:`version sets <VERSIONING/VersionSet>` and :ref:`version ranges <VERSIONING/VersionRange>`.
.. _VERSIONING/SemanticVersion:
Semantic Versioning
*******************
The :class:`~pyTooling.Versioning.SemanticVersion` class represents of a version number like ``v3.7.12``. It consists of
a major, minor and micro number. The micro number is also known as patch number. The minor and micro numbers are
optional, but usually used by most semantic version numbering schemes. In addition, optional parts can be added like a
prefix, a postfix or a build number.
.. hint::
Given a version number ``MAJOR.MINOR.MICRO``, increment the:
* ``MAJOR`` version when you make incompatible API changes,
* ``MINOR`` version when you add functionality in a backwards compatible manner, and
* ``MICRO`` version when you make backwards compatible bug fixes.
* Additional labels for pre-release and build metadata are available as extensions to the ``MAJOR.MINOR.MICRO``
format.
Summary taken from `semver.org <https://semver.org/>`__.
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Direct Instantiation
A semantic version can be constructed from parts like major, minor and micro numbers.
.. code-block:: python
# Construct from numbers
version = SemanticVersion(1, 5, 2)
.. rubric:: Construction from String
Alternatively, a semantic version can be created from a string containing a semantic version number by using the
class-method :meth:`~pyTooling.Versioning.SemanticVersion.Parse`. The string is parsed and a semantic version gets
returned.
.. code-block:: python
# Construct from string
version = SemanticVersion.Parse("0.22.8")
.. rubric:: Usage
.. code-block:: python
# Compare versions
if version2 > version1:
# Compare versions
if version2 >= "1.4.8":
.. rubric:: Features
Prefix string
Represents the prefix like: ``v`` (version), ``r`` (revision), ``i`` (internal version/release), ``ver``
(version), ``rev`` (revision).
:green:`v`\ 1.2.3
Major number
Represents the major version number in semantic version.
v\ :green:`1`\ .2.3
Minor number
Represents the minor version number in semantic version.
v1.\ :green:`2`\ .3
Micro number
Represents the micro or patch version number in semantic version.
v1.2.\ :green:`3`
Build number
Represents the build number.
v1.2.3.\ :green:`4`
Release Level / Release number
Distinguishes if a version is in *alpha*, *beta*, *release candidate* or *final* release level.
v1.2.3.\ :green:`alpha4` |br|
v1.2.3.\ :green:`beta4` |br|
v1.2.3.\ :green:`rc4`
Post number
tbd
v1.2.3.\ :green:`post4`
Development number
tbd
v1.2.3.\ :green:`dev4`
Postfix string
v1.2.3+\ :green:`deb11u5`
Comparison operators
Operators for ``==``, ``!=``, ``<``, ``<=``, ``>``, ``>=``, ``>>``.
String formatting
The version number can be formatted as a string with a fixed formatting pattern based on present version parts
as well as a user-defined formatting via :meth:`~pyTooling.Versioning.SemanticVersion.__format__`
.. rubric:: Examples
.. hlist::
:columns: 3
* ``v1``
* ``r1.12``
* ``i1.2.13+linux_86_64``
* ``rev1.2.3.14``
* ``v1.2.3-dev``
* ``v1.2.3.dev23``
* ``v1.2.3.alpha1``
* ``v1.2.3.beta1``
* ``v1.2.3.rc1+deb25``
* ``1.2.8.post2``
* ``1.2.8.post2.dev4``
* ``v1.2.3.alpha4.post5.dev6+deb11u35``
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class SemanticVersion(Version):
@classmethod
def Parse(cls, versionString: Nullable[str], validator: Nullable[Callable[["SemanticVersion"], bool]] = None) -> "Version":
pass
@readonly
def Parts(self) -> Parts:
pass
@readonly
def Prefix(self) -> str:
pass
@readonly
def Major(self) -> int:
pass
@readonly
def Minor(self) -> int:
pass
@readonly
def Micro(self) -> int:
pass
@readonly
def Patch(self) -> int:
pass
@readonly
def ReleaseLevel(self) -> ReleaseLevel:
pass
@readonly
def ReleaseNumber(self) -> int:
pass
@readonly
def Post(self) -> int:
pass
@readonly
def Dev(self) -> int:
pass
@readonly
def Build(self) -> int:
pass
@readonly
def Postfix(self) -> str:
pass
@readonly
def Hash(self) -> str:
pass
@readonly
def Flags(self) -> Flags:
pass
def __eq__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __ne__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __lt__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __le__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __gt__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __ge__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __imod__(self, other: Union["SemanticVersion", str, int, None]) -> bool:
pass
def __format__(self, formatSpec: str) -> str:
pass
def __repr__(self) -> str:
pass
def __str__(self) -> str:
pass
.. _VERSIONING/SemVerVariants:
Variants
========
.. tab-set::
.. tab-item:: Python Version
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Examples
* 3.13.0
* 3.13.0a4
* 3.13.0b2
* 3.13.0rc2
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class PythonVersion(SemanticVersion):
@classmethod
def FromSysVersionInfo(cls) -> "PythonVersion":
pass
.. _VERSIONING/CalendarVersion:
Calendar Versioning
*******************
The :class:`~pyTooling.Versioning.CalendarVersion` class represents of a version number like ``2021.10``.
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Direct Instantiation
Alternatively, a calendar version can be constructed from parts like major, minor and micro numbers. The
unified naming of parts can be used to map years to major numbers, months to minor numbers, etc.
.. code-block:: python
# Construct from numbers
version = CalendarVersion(2024, 5)
.. rubric:: Construction from String
A calendar version can be created from a string containing a calendar version number by using the class-method
:meth:`~pyTooling.Versioning.CalendarVersion.Parse`. The string is parsed and a calendar version gets returned.
.. code-block:: python
# Construct from string
version = CalendarVersion.Parse("2024.05")
.. rubric:: Usage
.. code-block:: python
# Compare versions
if version2 > version1:
# Compare versions
if version2 >= "2023.02":
.. rubric:: Features
Major number
Represents the major version number in semantic version.
Minor number
Represents the minor version number in semantic version.
Micro number
Represents the micro or patch version number in semantic version.
Build number
Represents the build number.
Prefix string
Represents the prefix like: ``v`` (version), ``r`` (revision), ``i`` (internal version/release), ``ver``
(version), ``rev`` (revision).
Comparison operators
Operators for ``==``, ``!=``, ``<``, ``<=``, ``>``, ``>=``, ``%=``.
.. rubric:: Missing Features
* release-level: additional labels like ``dev``, ``rc``, ``pl``, ``alpha``
* pre-version and post-version
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class CalendarVersion(Version):
@classmethod
def Parse(cls, versionString: Nullable[str], validator: Nullable[Callable[["CalendarVersion"], bool]] = None) -> "CalendarVersion":
pass
@readonly
def Parts(self) -> Parts:
pass
@readonly
def Major(self) -> int:
pass
@readonly
def Minor(self) -> int:
pass
@readonly
def Micro(self) -> int:
pass
@readonly
def Patch(self) -> int:
pass
@readonly
def Build(self) -> int:
pass
@readonly
def Flags(self) -> Flags:
pass
@readonly
def Prefix(self) -> str:
pass
@readonly
def Postfix(self) -> str:
pass
def __eq__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __ne__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __lt__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __le__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __gt__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __ge__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __imod__(self, other: Union["CalendarVersion", str, int, None]) -> bool:
pass
def __format__(self, formatSpec: str) -> str:
pass
def __repr__(self) -> str:
pass
def __str__(self) -> str:
pass
.. _VERSIONING/CalVerVariants:
Variants
========
.. hint::
Calendar versions have multiple format variants:
* ``YY.MINOR.MICRO``
* ``YYYY.MINOR.MICRO``
* ``YY.MM``
* ``YYYY.0M``
* ``YYYY.MM.DD``
* ``YYYY.MM.DD_MICRO``
* ``YYYY-MM-DD``
Formats taken from `calver.org <https://calver.org/>`__.
.. tab-set::
.. tab-item:: Year-Month Version
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Direct Instantiation
A year-month version can be constructed from year and month numbers.
.. code-block:: python
# Construct from numbers
version = YearMonthVersion(2024, 5)
.. rubric:: Construction from String
A semantic version can also be created from a string containing a year-month version number by using the
class-method :meth:`~pyTooling.Versioning.YearMonthVersion.Parse`. The string is parsed and a year-month
version gets returned.
.. code-block:: python
# Construct from string
version = YearMonthVersion.Parse("2024.05")
.. rubric:: Examples
* OSVVM: 2024.07
* Ubuntu: 2024.10
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class YearMonthVersion(CalendarVersion):
@classmethod
def Parse(cls, versionString: Nullable[str], validator: Nullable[Callable[["YearMonthVersion"], bool]] = None) -> "YearMonthVersion":
pass
@readonly
def Year(self) -> int:
pass
@readonly
def Month(self) -> int:
pass
.. tab-item:: Year-Week Version
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Direct Instantiation
A year-week version can be constructed from year and month numbers.
.. code-block:: python
# Construct from numbers
version = YearWeekVersion(2024, 5)
.. rubric:: Construction from String
A semantic version can also be created from a string containing a year-week version number by using the
class-method :meth:`~pyTooling.Versioning.YearWeekVersion.Parse`. The string is parsed and a year-week
version gets returned.
.. code-block:: python
# Construct from string
version = YearWeekVersion.Parse("2024.05")
.. rubric:: Examples
* Production date codes
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class YearWeekVersion(CalendarVersion):
@classmethod
def Parse(cls, versionString: Nullable[str], validator: Nullable[Callable[["YearWeekVersion"], bool]] = None) -> "YearWeekVersion":
pass
@readonly
def Year(self) -> int:
pass
@readonly
def Week(self) -> int:
pass
.. tab-item:: Year-Release Version
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Direct Instantiation
A year-release version can be constructed from year and month numbers.
.. code-block:: python
# Construct from numbers
version = YearReleaseVersion(2024, 2)
.. rubric:: Construction from String
A semantic version can also be created from a string containing a year-release version number by using the
class-method :meth:`~pyTooling.Versioning.YearReleaseVersion.Parse`. The string is parsed and a year-release
version gets returned.
.. code-block:: python
# Construct from string
version = YearReleaseVersion.Parse("2024.2")
.. rubric:: Examples
* Vivado: 2024.1
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class YearReleaseVersion(CalendarVersion):
@classmethod
def Parse(cls, versionString: Nullable[str], validator: Nullable[Callable[["YearReleaseVersion"], bool]] = None) -> "YearReleaseVersion":
pass
@readonly
def Year(self) -> int:
pass
@readonly
def Release(self) -> int:
pass
.. tab-item:: Year-Month-Day Version
.. grid:: 2
.. grid-item::
:columns: 6
.. rubric:: Direct Instantiation
A year-month-day version can be constructed from year, month and day numbers.
.. code-block:: python
# Construct from numbers
version = YearMonthDayVersion(2024, 10, 5)
.. rubric:: Construction from String
A semantic version can also be created from a string containing a year-month-day version number by using the
class-method :meth:`~pyTooling.Versioning.YearMonthDayVersion.Parse`. The string is parsed and a
year-month-day version gets returned.
.. code-block:: python
# Construct from string
version = YearMonthDayVersion.Parse("2024.10.05")
.. rubric:: Examples
* Furo: 2024.04.27
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: Python
@export
class YearMonthDayVersion(CalendarVersion):
@classmethod
def Parse(cls, versionString: Nullable[str], validator: Nullable[Callable[["YearMonthDayVersion"], bool]] = None) -> "YearMonthDayVersion":
pass
@readonly
def Year(self) -> int:
pass
@readonly
def Month(self) -> int:
pass
@readonly
def Day(self) -> int:
pass
.. _VERSIONING/VersionRange:
VersionRange
************
.. grid:: 2
.. grid-item::
:columns: 6
A :class:`~pyTooling.Versioning.VersionRange` defines a range of versions reaching from a lower to an upper bound.
It equivalently supports :ref:`semantic <VERSIONING/SemanticVersion>` and :ref:`calendar <VERSIONING/CalendarVersion>`
versions or derived subclasses thereof. When initializing a version range, an optional
:class:`~pyTooling.Versioning.RangeBoundHandling` flag specifies if the bounds are inclusive (default) or
exclusive.
.. rubric:: Features
Access bounds and bound handling behavior
The lower bound of the version range can be read or updated by accessing the
:attr:`~pyTooling.Versioning.VersionRange.LowerBound` property. Similarly, the upper bound of the version range
can be read or updated by accessing the :attr:`~pyTooling.Versioning.VersionRange.UpperBound` property.
The behavior how lower and upper bound are handled can be read or modified by accessing the
:attr:`~pyTooling.Versioning.VersionRange.BoundHandling` property.
Comparison of two version ranges
A version range can be compare to another version range using comparison operators: ``<``, ``<=``, ``>``, ``>=``.
Comparison of a version range and a version
A version can be compared with a version range and vise versa using comparison operators: ``<``, ``<=``, ``>``,
``>=``.
The behavior is influenced by the bound handling behavior.
Contains checks
A version can be checked if it's contained in a version range using *contains* operators: ``in``, ``not in``.
The behavior is influenced by the bound handling behavior.
Intersection
Two version ranges can be intersected using the ``&`` operator creating a new version range.
In case of an empty intersection result, an exception is raised.
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: python
@export
class VersionRange(Generic[V], metaclass=ExtendedType, slots=True):
def __init__(self, lowerBound: V, upperBound: V, boundHandling: RangeBoundHandling = RangeBoundHandling.BothBoundsInclusive) -> None:
@property
def LowerBound(self) -> V:
pass
@property
def UpperBound(self) -> V:
pass
@property
def BoundHandling(self) -> RangeBoundHandling:
pass
def __and__(self, other: Any) -> VersionRange[T]:
pass
def __lt__(self, other: Any) -> bool:
pass
def __le__(self, other: Any) -> bool:
pass
def __gt__(self, other: Any) -> bool:
pass
def __ge__(self, other: Any) -> bool:
pass
def __contains__(self, version: Version) -> bool:
pass
.. tab-set::
.. tab-item:: Instantiation (Inclusive Bounds)
.. code-block:: python
from pyTooling.Versioning import SemanticVersion, VersionRange
versionRange = VersionRange(
lowerBound=SemanticVersion(1, 0, 0),
upperBound=SemanticVersion(1, 9, 0)
)
testVersion = SemanticVersion(1, 4, 3)
if testVersion in versionRange:
pass
.. tab-item:: Instantiation (Exclusive Upper Bound)
.. code-block:: python
from pyTooling.Versioning import SemanticVersion, VersionRange
versionRange = VersionRange(
lowerBound=YearWeekVersion(2023, 34),
upperBound=YearWeekVersion(2023, 51),
boundHandling=RangeBoundHandling.UpperBoundExclusive)
)
testVersion = YearWeekVersion(2023, 51)
if testVersion not in versionRange:
pass
.. _VERSIONING/VersionSet:
VersionSet
**********
.. grid:: 2
.. grid-item::
:columns: 6
A :class:`~pyTooling.Versioning.VersionSet` defines an ordered set (actually a list) of versions. It equivalently
supports :ref:`semantic <VERSIONING/SemanticVersion>` and :ref:`calendar <VERSIONING/CalendarVersion>` versions or
derived subclasses thereof.
.. rubric:: Features
Accessing versions in the set
The versions within a version set can be accessed via index operation (``__getitem__``) or iterating
(``__iter__``) the version set.
The number of elements is accessible via length operation (``__len__``).
Comparison of two version sets
A version set can be compare to another version set using comparison operators: ``<``, ``<=``, ``>``, ``>=``.
Comparison of a version set and a version
A version can be compared with a version set and vise versa using comparison operators: ``<``, ``<=``, ``>``,
``>=``.
Contains checks
A version can be checked if it's contained in a version set using *contains* operators: ``in``, ``not in``.
Intersection
Two version set can be intersected using the ``&`` operator creating a new version set.
In case of an empty intersection result, an exception is raised.
Union
Two version sets can be united using the ``|`` operator creating a new version set.
.. grid-item::
:columns: 6
.. rubric:: Condensed Class Definition
.. code-block:: python
@export
class VersionSet(Generic[V], metaclass=ExtendedType, slots=True):
def __init__(self, versions: Union[Version, Iterable[V]]):
pass
def __and__(self, other: VersionSet[V]) -> VersionSet[T]:
pass
def __or__(self, other: VersionSet[V]) -> VersionSet[T]:
pass
def __lt__(self, other: Any) -> bool:
pass
def __le__(self, other: Any) -> bool:
pass
def __gt__(self, other: Any) -> bool:
pass
def __ge__(self, other: Any) -> bool:
pass
def __contains__(self, version: V) -> bool:
pass
def __len__(self) -> int:
pass
def __iter__(self) -> Iterator[V]:
pass
def __getitem__(self, index: int) -> V:
pass
.. tab-set::
.. tab-item:: Instantiation
.. code-block:: python
from pyTooling.Versioning import SemanticVersion, VersionSet
versionSet = VersionSet((
YearMonthVersion(2024, 4),
YearMonthVersion(2025, 1),
YearMonthVersion(2019, 3)
))
testVersion = YearMonthVersion(2019, 3)
if testVersion in versionSet:
pass
.. tab-item:: Iterating Elements
.. code-block:: python
from pyTooling.Versioning import SemanticVersion, VersionSet
versionSet = VersionSet((
YearMonthVersion(2024, 4),
YearMonthVersion(2025, 1),
YearMonthVersion(2019, 3)
))
for version in versionSet:
pass
|