Skip to content

Commit 467ea0c

Browse files
authored
Merge pull request #368 from tomschr/feature/284-compatibility
Fix #284: implement "is compatible with" method
2 parents 9b475f7 + 5485b6b commit 467ea0c

14 files changed

+221
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,6 @@ fabric.properties
268268

269269
docs/_api
270270
!docs/_api/semver.__about__.rst
271+
272+
# For node
273+
node_modules/

changelog.d/284.deprecation.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecate the use of :meth:`Version.isvalid`.
2+
3+
Rename :meth:`Version.isvalid <semver.version.Version.isvalid>`
4+
to :meth:`Version.is_valid <semver.version.Version.is_valid>`
5+
for consistency reasons with :meth:`Version.is_compatible <semver.version.Version.is_compatible>`

changelog.d/284.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document deprecation of :meth:`Version.isvalid`.

changelog.d/284.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement :meth:`Version.is_compatible <semver.version.Version.is_compatible>` to make "is self compatible with X".

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def find_version(*file_paths):
118118
# Markup to shorten external links
119119
# See https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
120120
extlinks = {
121-
"gh": ("https://github.com/python-semver/python-semver/issues/%s", "#"),
122-
"pr": ("https://github.com/python-semver/python-semver/pull/%s", "PR #"),
121+
"gh": ("https://github.com/python-semver/python-semver/issues/%s", "#%s"),
122+
"pr": ("https://github.com/python-semver/python-semver/pull/%s", "PR #%s"),
123123
}
124124

125125
# -- Options for HTML output ----------------------------------------------

docs/migration/migratetosemver3.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Migrating from semver2 to semver3
44
=================================
55

6-
This document describes the visible differences for
6+
This section describes the visible differences for
77
users and how your code stays compatible for semver3.
8+
Some changes are backward incompatible.
89

910
Although the development team tries to make the transition
1011
to semver3 as smooth as possible, at some point change
@@ -34,9 +35,16 @@ Use semver.cli instead of semver
3435
--------------------------------
3536

3637
All functions related to CLI parsing are moved to :mod:`semver.cli`.
37-
If you are such functions, like :func:`semver.cmd_bump <semver.cli.cmd_bump>`,
38+
If you need such functions, like :func:`semver.cmd_bump <semver.cli.cmd_bump>`,
3839
import it from :mod:`semver.cli` in the future:
3940

4041
.. code-block:: python
4142
4243
from semver.cli import cmd_bump
44+
45+
46+
Use semver.Version.is_valid instead of semver.Version.isvalid
47+
-------------------------------------------------------------
48+
49+
The pull request :pr:`284` introduced the method :meth:`Version.is_compatible <semver.Version.is_compatible>`. To keep consistency, the development team
50+
decided to rename the :meth:`isvalid <semver.Version.isvalid>` to :meth:`is_valid <semver.Version.is_valid>`.

docs/migration/replace-deprecated-functions.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ them with code which is compatible for future versions:
3131
3232
Likewise with the other module level functions.
3333

34+
* :func:`semver.Version.isvalid`
35+
36+
Replace it with :meth:`semver.Version.is_valid`:
37+
38+
3439
* :func:`semver.finalize_version`
3540

3641
Replace it with :func:`semver.Version.finalize_version`:
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

docs/usage/check-valid-semver-version.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ classmethod :func:`Version.isvalid <semver.version.Version.isvalid>`:
66

77
.. code-block:: python
88
9-
>>> Version.isvalid("1.0.0")
9+
>>> Version.is_valid("1.0.0")
1010
True
11-
>>> Version.isvalid("invalid")
11+
>>> Version.is_valid("invalid")
1212
False

docs/usage/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Using semver
88
create-a-version
99
parse-version-string
1010
check-valid-semver-version
11+
check-compatible-semver-version
1112
access-parts-of-a-version
1213
access-parts-through-index
1314
replace-parts-of-a-version

0 commit comments

Comments
 (0)