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
@@ -389,10 +420,14 @@ def _to_dict(obj):
389
420
return obj
390
421
391
422
423
+ @deprecated ("parse" )
392
424
def parse_version_info (version ):
393
425
"""
394
426
Parse version string to a VersionInfo instance.
395
427
428
+ .. deprecated:: 2.9.2
429
+ Use :func:`semver.VersionInfo.parse` instead.
430
+
396
431
:param version: version string
397
432
:return: a :class:`VersionInfo` instance
398
433
:rtype: :class:`VersionInfo`
@@ -569,10 +604,14 @@ def min_ver(ver1, ver2):
569
604
return ver2
570
605
571
606
607
+ @deprecated ()
572
608
def format_version (major , minor , patch , prerelease = None , build = None ):
573
609
"""
574
610
Format a version according to the Semantic Versioning specification.
575
611
612
+ .. deprecated:: 2.9.2
613
+ Use :func:`semver.VersionInfo.format_version` instead.
614
+
576
615
:param int major: the required major part of a version
577
616
:param int minor: the required minor part of a version
578
617
:param int patch: the required patch part of a version
@@ -601,10 +640,14 @@ def _increment_string(string):
601
640
return string
602
641
603
642
643
+ @deprecated ()
604
644
def bump_major (version ):
605
645
"""
606
646
Raise the major part of the version.
607
647
648
+ .. deprecated:: 2.9.2
649
+ Use :func:`semver.VersionInfo.bump_major` instead.
650
+
608
651
:param: version string
609
652
:return: the raised version string
610
653
:rtype: str
@@ -615,10 +658,14 @@ def bump_major(version):
615
658
return str (VersionInfo .parse (version ).bump_major ())
616
659
617
660
661
+ @deprecated ()
618
662
def bump_minor (version ):
619
663
"""
620
664
Raise the minor part of the version.
621
665
666
+ .. deprecated:: 2.9.2
667
+ Use :func:`semver.VersionInfo.bump_minor` instead.
668
+
622
669
:param: version string
623
670
:return: the raised version string
624
671
:rtype: str
@@ -629,10 +676,14 @@ def bump_minor(version):
629
676
return str (VersionInfo .parse (version ).bump_minor ())
630
677
631
678
679
+ @deprecated ()
632
680
def bump_patch (version ):
633
681
"""
634
682
Raise the patch part of the version.
635
683
684
+ .. deprecated:: 2.9.2
685
+ Use :func:`semver.VersionInfo.bump_patch` instead.
686
+
636
687
:param: version string
637
688
:return: the raised version string
638
689
:rtype: str
@@ -643,10 +694,14 @@ def bump_patch(version):
643
694
return str (VersionInfo .parse (version ).bump_patch ())
644
695
645
696
697
+ @deprecated ()
646
698
def bump_prerelease (version , token = "rc" ):
647
699
"""
648
700
Raise the prerelease part of the version.
649
701
702
+ .. deprecated:: 2.9.2
703
+ Use :func:`semver.VersionInfo.bump_prerelease` instead.
704
+
650
705
:param version: version string
651
706
:param token: defaults to 'rc'
652
707
:return: the raised version string
@@ -658,10 +713,14 @@ def bump_prerelease(version, token="rc"):
658
713
return str (VersionInfo .parse (version ).bump_prerelease (token ))
659
714
660
715
716
+ @deprecated ()
661
717
def bump_build (version , token = "build" ):
662
718
"""
663
719
Raise the build part of the version.
664
720
721
+ .. deprecated:: 2.9.2
722
+ Use :func:`semver.VersionInfo.bump_build` instead.
723
+
665
724
:param version: version string
666
725
:param token: defaults to 'build'
667
726
:return: the raised version string
@@ -673,10 +732,14 @@ def bump_build(version, token="build"):
673
732
return str (VersionInfo .parse (version ).bump_build (token ))
674
733
675
734
735
+ @deprecated ()
676
736
def finalize_version (version ):
677
737
"""
678
738
Remove any prerelease and build metadata from the version.
679
739
740
+ .. deprecated:: 2.9.2
741
+ Use :func:`semver.VersionInfo.bump_format_version` instead.
742
+
680
743
:param version: version string
681
744
:return: the finalized version string
682
745
:rtype: str
@@ -688,10 +751,14 @@ def finalize_version(version):
688
751
return VersionInfo .format_version (verinfo .major , verinfo .minor , verinfo .patch )
689
752
690
753
754
+ @deprecated ()
691
755
def replace (version , ** parts ):
692
756
"""
693
757
Replace one or more parts of a version and return the new string.
694
758
759
+ .. deprecated:: 2.9.2
760
+ Use :func:`semver.VersionInfo.replace` instead.
761
+
695
762
:param str version: the version string to replace
696
763
:param dict parts: the parts to be updated. Valid keys are:
697
764
``major``, ``minor``, ``patch``, ``prerelease``, or ``build``
0 commit comments