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
|
Checking for a Compatible Semver Version
========================================
To check if a *change* from a semver version ``a`` to a semver
version ``b`` is *compatible* according to semver rule, use the method
:meth:`~semver.version.Version.is_compatible`.
The expression ``a.is_compatible(b) is True`` if one of the following
statements is true:
* both versions are equal, or
* both majors are equal and higher than 0. The same applies for both
minor parts. Both pre-releases are equal, or
* both majors are equal and higher than 0. The minor of ``b``'s
minor version is higher then ``a``'s. Both pre-releases are equal.
In all other cases, the result is false.
Keep in mind, the method *does not* check patches!
* Two different majors:
.. code-block:: python
>>> a = Version(1, 1, 1)
>>> b = Version(2, 0, 0)
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
False
* Two different minors:
.. code-block:: python
>>> a = Version(1, 1, 0)
>>> b = Version(1, 0, 0)
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
True
* The same two majors and minors:
.. code-block:: python
>>> a = Version(1, 1, 1)
>>> b = Version(1, 1, 0)
>>> a.is_compatible(b)
True
>>> b.is_compatible(a)
True
* Release and pre-release:
.. code-block:: python
>>> a = Version(1, 1, 1)
>>> b = Version(1, 0, 0,'rc1')
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
False
* Different pre-releases:
.. code-block:: python
>>> a = Version(1, 0, 0, 'rc1')
>>> b = Version(1, 0, 0, 'rc2')
>>> a.is_compatible(b)
False
>>> b.is_compatible(a)
False
* Identical pre-releases:
.. code-block:: python
>>> a = Version(1, 0, 0,'rc1')
>>> b = Version(1, 0, 0,'rc1')
>>> a.is_compatible(b)
True
* All major zero versions are incompatible with anything but itself:
.. code-block:: python
>>> Version(0, 1, 0).is_compatible(Version(0, 1, 1))
False
# Only identical versions are compatible for major zero versions:
>>> Version(0, 1, 0).is_compatible(Version(0, 1, 0))
True
|