6
6
from functools import wraps
7
7
import re
8
8
import sys
9
+ import warnings
9
10
10
11
11
12
__version__ = "2.9.1"
@@ -27,10 +28,44 @@ def cmp(a, b):
27
28
return (a > b ) - (a < b )
28
29
29
30
31
+ def deprecated (replace = None ):
32
+ """
33
+ Decorates a function to output a deprecation warning.
34
+
35
+ This function will be removed once major version 3 of semver is
36
+ released.
37
+ """
38
+ # we can't use the 'nonlocal' keyword in Python2, so we need
39
+ # to circumvent that with a dictionary:
40
+ r = {"r" : replace }
41
+
42
+ def decorator (func ):
43
+ @wraps (func )
44
+ def wrapper (* args , ** kwargs ):
45
+ # nonlocal replace
46
+ replace = r ["r" ] if r ["r" ] is not None else func .__name__
47
+ msg = (
48
+ "Function 'semver.{f}' is deprecated. "
49
+ "Use the respective 'semver.VersionInfo.{r}' instead."
50
+ )
51
+ warnings .warn (
52
+ msg .format (f = func .__name__ , r = replace ), category = DeprecationWarning
53
+ )
54
+ return func (* args , ** kwargs )
55
+
56
+ return wrapper
57
+
58
+ return decorator
59
+
60
+
61
+ @deprecated ()
30
62
def parse (version ):
31
63
"""
32
64
Parse version to major, minor, patch, pre-release, build parts.
33
65
66
+ .. deprecated:: 2.9.2
67
+ Use :func:`semver.VersionInfo.format_parse` instead.
68
+
34
69
:param version: version string
35
70
:return: dictionary with the keys 'build', 'major', 'minor', 'patch',
36
71
and 'prerelease'. The prerelease or build keys can be None
@@ -186,7 +221,7 @@ def bump_major(self):
186
221
VersionInfo(major=4, minor=0, patch=0, prerelease=None, build=None)
187
222
"""
188
223
cls = type (self )
189
- return cls (self ._major + 1 )
224
+ return cls (self ._major + 1 )
190
225
191
226
def bump_minor (self ):
192
227
"""
@@ -201,7 +236,7 @@ def bump_minor(self):
201
236
VersionInfo(major=3, minor=5, patch=0, prerelease=None, build=None)
202
237
"""
203
238
cls = type (self )
204
- return cls (self ._major , self ._minor + 1 )
239
+ return cls (self ._major , self ._minor + 1 )
205
240
206
241
def bump_patch (self ):
207
242
"""
@@ -216,7 +251,7 @@ def bump_patch(self):
216
251
VersionInfo(major=3, minor=4, patch=6, prerelease=None, build=None)
217
252
"""
218
253
cls = type (self )
219
- return cls (self ._major , self ._minor , self ._patch + 1 )
254
+ return cls (self ._major , self ._minor , self ._patch + 1 )
220
255
221
256
def bump_prerelease (self , token = "rc" ):
222
257
"""
@@ -233,9 +268,7 @@ def bump_prerelease(self, token="rc"):
233
268
build=None)
234
269
"""
235
270
cls = type (self )
236
- prerelease = _increment_string (
237
- self ._prerelease or (token or "rc" ) + ".0"
238
- )
271
+ prerelease = _increment_string (self ._prerelease or (token or "rc" ) + ".0" )
239
272
return cls (self ._major , self ._minor , self ._patch , prerelease )
240
273
241
274
def bump_build (self , token = "build" ):
@@ -253,9 +286,7 @@ def bump_build(self, token="build"):
253
286
build='build.10')
254
287
"""
255
288
cls = type (self )
256
- build = _increment_string (
257
- self ._build or (token or "build" ) + ".0"
258
- )
289
+ build = _increment_string (self ._build or (token or "build" ) + ".0" )
259
290
return cls (self ._major , self ._minor , self ._patch , self ._prerelease , build )
260
291
261
292
@comparator
@@ -395,13 +426,17 @@ def _to_dict(obj):
395
426
return obj
396
427
397
428
429
+ @deprecated ("parse" )
398
430
def parse_version_info (version ):
399
431
"""
400
432
Parse version string to a VersionInfo instance.
401
433
402
434
.. versionadded:: 2.7.2
403
435
Added :func:`parse_version_info`
404
436
437
+ .. deprecated:: 2.9.2
438
+ Use :func:`semver.VersionInfo.parse` instead.
439
+
405
440
:param version: version string
406
441
:return: a :class:`VersionInfo` instance
407
442
:rtype: :class:`VersionInfo`
@@ -578,10 +613,14 @@ def min_ver(ver1, ver2):
578
613
return ver2
579
614
580
615
616
+ @deprecated ()
581
617
def format_version (major , minor , patch , prerelease = None , build = None ):
582
618
"""
583
619
Format a version string according to the Semantic Versioning specification.
584
620
621
+ .. deprecated:: 2.9.2
622
+ Use :func:`semver.VersionInfo.format_version` instead.
623
+
585
624
:param int major: the required major part of a version
586
625
:param int minor: the required minor part of a version
587
626
:param int patch: the required patch part of a version
@@ -610,10 +649,14 @@ def _increment_string(string):
610
649
return string
611
650
612
651
652
+ @deprecated ()
613
653
def bump_major (version ):
614
654
"""
615
655
Raise the major part of the version string.
616
656
657
+ .. deprecated:: 2.9.2
658
+ Use :func:`semver.VersionInfo.bump_major` instead.
659
+
617
660
:param: version string
618
661
:return: the raised version string
619
662
:rtype: str
@@ -624,10 +667,14 @@ def bump_major(version):
624
667
return str (VersionInfo .parse (version ).bump_major ())
625
668
626
669
670
+ @deprecated ()
627
671
def bump_minor (version ):
628
672
"""
629
673
Raise the minor part of the version string.
630
674
675
+ .. deprecated:: 2.9.2
676
+ Use :func:`semver.VersionInfo.bump_minor` instead.
677
+
631
678
:param: version string
632
679
:return: the raised version string
633
680
:rtype: str
@@ -638,10 +685,14 @@ def bump_minor(version):
638
685
return str (VersionInfo .parse (version ).bump_minor ())
639
686
640
687
688
+ @deprecated ()
641
689
def bump_patch (version ):
642
690
"""
643
691
Raise the patch part of the version string.
644
692
693
+ .. deprecated:: 2.9.2
694
+ Use :func:`semver.VersionInfo.bump_patch` instead.
695
+
645
696
:param: version string
646
697
:return: the raised version string
647
698
:rtype: str
@@ -652,10 +703,14 @@ def bump_patch(version):
652
703
return str (VersionInfo .parse (version ).bump_patch ())
653
704
654
705
706
+ @deprecated ()
655
707
def bump_prerelease (version , token = "rc" ):
656
708
"""
657
709
Raise the prerelease part of the version string.
658
710
711
+ .. deprecated:: 2.9.2
712
+ Use :func:`semver.VersionInfo.bump_prerelease` instead.
713
+
659
714
:param version: version string
660
715
:param token: defaults to 'rc'
661
716
:return: the raised version string
@@ -667,10 +722,14 @@ def bump_prerelease(version, token="rc"):
667
722
return str (VersionInfo .parse (version ).bump_prerelease (token ))
668
723
669
724
725
+ @deprecated ()
670
726
def bump_build (version , token = "build" ):
671
727
"""
672
728
Raise the build part of the version string.
673
729
730
+ .. deprecated:: 2.9.2
731
+ Use :func:`semver.VersionInfo.bump_build` instead.
732
+
674
733
:param version: version string
675
734
:param token: defaults to 'build'
676
735
:return: the raised version string
@@ -682,13 +741,17 @@ def bump_build(version, token="build"):
682
741
return str (VersionInfo .parse (version ).bump_build (token ))
683
742
684
743
744
+ @deprecated ()
685
745
def finalize_version (version ):
686
746
"""
687
747
Remove any prerelease and build metadata from the version string.
688
748
689
749
.. versionadded:: 2.7.9
690
750
Added :func:`finalize_version`
691
751
752
+ .. deprecated:: 2.9.2
753
+ Use :func:`semver.VersionInfo.bump_format_version` instead.
754
+
692
755
:param version: version string
693
756
:return: the finalized version string
694
757
:rtype: str
@@ -700,10 +763,14 @@ def finalize_version(version):
700
763
return VersionInfo .format_version (verinfo .major , verinfo .minor , verinfo .patch )
701
764
702
765
766
+ @deprecated ()
703
767
def replace (version , ** parts ):
704
768
"""
705
769
Replace one or more parts of a version and return the new string.
706
770
771
+ .. deprecated:: 2.9.2
772
+ Use :func:`semver.VersionInfo.replace` instead.
773
+
707
774
:param str version: the version string to replace
708
775
:param dict parts: the parts to be updated. Valid keys are:
709
776
``major``, ``minor``, ``patch``, ``prerelease``, or ``build``
0 commit comments