|
| 1 | +Checking for a Compatible Semver Version |
| 2 | +======================================== |
| 3 | + |
| 4 | +To check if a *change* from a semver version ``a`` to a semver |
| 5 | +version ``b`` is *compatible* according to semver rule, use the method |
| 6 | +:meth:`Version.is_compatible <semver.version.Version.is_compatible>`. |
| 7 | + |
| 8 | +The expression ``a.is_compatible(b) is True`` if one of the following |
| 9 | +statements is true: |
| 10 | + |
| 11 | +* both versions are equal, or |
| 12 | +* both majors are equal and higher than 0. The same applies for both |
| 13 | + minor parts. Both pre-releases are equal, or |
| 14 | +* both majors are equal and higher than 0. The minor of ``b``'s |
| 15 | + minor version is higher then ``a``'s. Both pre-releases are equal. |
| 16 | + |
| 17 | +In all other cases, the result is false. |
| 18 | + |
| 19 | +Keep in mind, the method *does not* check patches! |
| 20 | + |
| 21 | + |
| 22 | +* Two different majors: |
| 23 | + |
| 24 | + .. code-block:: python |
| 25 | +
|
| 26 | + >>> a = Version(1, 1, 1) |
| 27 | + >>> b = Version(2, 0, 0) |
| 28 | + >>> a.is_compatible(b) |
| 29 | + False |
| 30 | + >>> b.is_compatible(a) |
| 31 | + False |
| 32 | +
|
| 33 | +* Two different minors: |
| 34 | + |
| 35 | + .. code-block:: python |
| 36 | +
|
| 37 | + >>> a = Version(1, 1, 0) |
| 38 | + >>> b = Version(1, 0, 0) |
| 39 | + >>> a.is_compatible(b) |
| 40 | + False |
| 41 | + >>> b.is_compatible(a) |
| 42 | + True |
| 43 | +
|
| 44 | +* The same two majors and minors: |
| 45 | + |
| 46 | + .. code-block:: python |
| 47 | +
|
| 48 | + >>> a = Version(1, 1, 1) |
| 49 | + >>> b = Version(1, 1, 0) |
| 50 | + >>> a.is_compatible(b) |
| 51 | + True |
| 52 | + >>> b.is_compatible(a) |
| 53 | + True |
| 54 | +
|
| 55 | +* Release and pre-release: |
| 56 | + |
| 57 | + .. code-block:: python |
| 58 | +
|
| 59 | + >>> a = Version(1, 1, 1) |
| 60 | + >>> b = Version(1, 0, 0,'rc1') |
| 61 | + >>> a.is_compatible(b) |
| 62 | + False |
| 63 | + >>> b.is_compatible(a) |
| 64 | + False |
| 65 | +
|
| 66 | +* Different pre-releases: |
| 67 | + |
| 68 | + .. code-block:: python |
| 69 | +
|
| 70 | + >>> a = Version(1, 0, 0, 'rc1') |
| 71 | + >>> b = Version(1, 0, 0, 'rc2') |
| 72 | + >>> a.is_compatible(b) |
| 73 | + False |
| 74 | + >>> b.is_compatible(a) |
| 75 | + False |
| 76 | +
|
| 77 | +* Identical pre-releases: |
| 78 | + |
| 79 | + .. code-block:: python |
| 80 | +
|
| 81 | + >>> a = Version(1, 0, 0,'rc1') |
| 82 | + >>> b = Version(1, 0, 0,'rc1') |
| 83 | + >>> a.is_compatible(b) |
| 84 | + True |
| 85 | +
|
| 86 | +* All major zero versions are incompatible with anything but itself: |
| 87 | + |
| 88 | + .. code-block:: python |
| 89 | +
|
| 90 | + >>> Version(0, 1, 0).is_compatible(Version(0, 1, 1)) |
| 91 | + False |
| 92 | +
|
| 93 | + # Only identical versions are compatible for major zero versions: |
| 94 | + >>> Version(0, 1, 0).is_compatible(Version(0, 1, 0)) |
| 95 | + True |
0 commit comments