66from functools import wraps
77import re
88import sys
9+ import warnings
910
1011
1112__version__ = "2.9.1"
@@ -27,10 +28,44 @@ def cmp(a, b):
2728 return (a > b ) - (a < b )
2829
2930
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 ()
3062def parse (version ):
3163 """
3264 Parse version to major, minor, patch, pre-release, build parts.
3365
66+ .. deprecated:: 2.9.2
67+ Use :func:`semver.VersionInfo.format_parse` instead.
68+
3469 :param version: version string
3570 :return: dictionary with the keys 'build', 'major', 'minor', 'patch',
3671 and 'prerelease'. The prerelease or build keys can be None
@@ -186,7 +221,7 @@ def bump_major(self):
186221 VersionInfo(major=4, minor=0, patch=0, prerelease=None, build=None)
187222 """
188223 cls = type (self )
189- return cls (self ._major + 1 )
224+ return cls (self ._major + 1 )
190225
191226 def bump_minor (self ):
192227 """
@@ -201,7 +236,7 @@ def bump_minor(self):
201236 VersionInfo(major=3, minor=5, patch=0, prerelease=None, build=None)
202237 """
203238 cls = type (self )
204- return cls (self ._major , self ._minor + 1 )
239+ return cls (self ._major , self ._minor + 1 )
205240
206241 def bump_patch (self ):
207242 """
@@ -216,7 +251,7 @@ def bump_patch(self):
216251 VersionInfo(major=3, minor=4, patch=6, prerelease=None, build=None)
217252 """
218253 cls = type (self )
219- return cls (self ._major , self ._minor , self ._patch + 1 )
254+ return cls (self ._major , self ._minor , self ._patch + 1 )
220255
221256 def bump_prerelease (self , token = "rc" ):
222257 """
@@ -233,9 +268,7 @@ def bump_prerelease(self, token="rc"):
233268 build=None)
234269 """
235270 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" )
239272 return cls (self ._major , self ._minor , self ._patch , prerelease )
240273
241274 def bump_build (self , token = "build" ):
@@ -253,9 +286,7 @@ def bump_build(self, token="build"):
253286 build='build.10')
254287 """
255288 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" )
259290 return cls (self ._major , self ._minor , self ._patch , self ._prerelease , build )
260291
261292 @comparator
@@ -389,10 +420,14 @@ def _to_dict(obj):
389420 return obj
390421
391422
423+ @deprecated ("parse" )
392424def parse_version_info (version ):
393425 """
394426 Parse version string to a VersionInfo instance.
395427
428+ .. deprecated:: 2.9.2
429+ Use :func:`semver.VersionInfo.parse` instead.
430+
396431 :param version: version string
397432 :return: a :class:`VersionInfo` instance
398433 :rtype: :class:`VersionInfo`
@@ -569,10 +604,14 @@ def min_ver(ver1, ver2):
569604 return ver2
570605
571606
607+ @deprecated ()
572608def format_version (major , minor , patch , prerelease = None , build = None ):
573609 """
574610 Format a version according to the Semantic Versioning specification.
575611
612+ .. deprecated:: 2.9.2
613+ Use :func:`semver.VersionInfo.format_version` instead.
614+
576615 :param int major: the required major part of a version
577616 :param int minor: the required minor part of a version
578617 :param int patch: the required patch part of a version
@@ -601,10 +640,14 @@ def _increment_string(string):
601640 return string
602641
603642
643+ @deprecated ()
604644def bump_major (version ):
605645 """
606646 Raise the major part of the version.
607647
648+ .. deprecated:: 2.9.2
649+ Use :func:`semver.VersionInfo.bump_major` instead.
650+
608651 :param: version string
609652 :return: the raised version string
610653 :rtype: str
@@ -615,10 +658,14 @@ def bump_major(version):
615658 return str (VersionInfo .parse (version ).bump_major ())
616659
617660
661+ @deprecated ()
618662def bump_minor (version ):
619663 """
620664 Raise the minor part of the version.
621665
666+ .. deprecated:: 2.9.2
667+ Use :func:`semver.VersionInfo.bump_minor` instead.
668+
622669 :param: version string
623670 :return: the raised version string
624671 :rtype: str
@@ -629,10 +676,14 @@ def bump_minor(version):
629676 return str (VersionInfo .parse (version ).bump_minor ())
630677
631678
679+ @deprecated ()
632680def bump_patch (version ):
633681 """
634682 Raise the patch part of the version.
635683
684+ .. deprecated:: 2.9.2
685+ Use :func:`semver.VersionInfo.bump_patch` instead.
686+
636687 :param: version string
637688 :return: the raised version string
638689 :rtype: str
@@ -643,10 +694,14 @@ def bump_patch(version):
643694 return str (VersionInfo .parse (version ).bump_patch ())
644695
645696
697+ @deprecated ()
646698def bump_prerelease (version , token = "rc" ):
647699 """
648700 Raise the prerelease part of the version.
649701
702+ .. deprecated:: 2.9.2
703+ Use :func:`semver.VersionInfo.bump_prerelease` instead.
704+
650705 :param version: version string
651706 :param token: defaults to 'rc'
652707 :return: the raised version string
@@ -658,10 +713,14 @@ def bump_prerelease(version, token="rc"):
658713 return str (VersionInfo .parse (version ).bump_prerelease (token ))
659714
660715
716+ @deprecated ()
661717def bump_build (version , token = "build" ):
662718 """
663719 Raise the build part of the version.
664720
721+ .. deprecated:: 2.9.2
722+ Use :func:`semver.VersionInfo.bump_build` instead.
723+
665724 :param version: version string
666725 :param token: defaults to 'build'
667726 :return: the raised version string
@@ -673,10 +732,14 @@ def bump_build(version, token="build"):
673732 return str (VersionInfo .parse (version ).bump_build (token ))
674733
675734
735+ @deprecated ()
676736def finalize_version (version ):
677737 """
678738 Remove any prerelease and build metadata from the version.
679739
740+ .. deprecated:: 2.9.2
741+ Use :func:`semver.VersionInfo.bump_format_version` instead.
742+
680743 :param version: version string
681744 :return: the finalized version string
682745 :rtype: str
@@ -688,10 +751,14 @@ def finalize_version(version):
688751 return VersionInfo .format_version (verinfo .major , verinfo .minor , verinfo .patch )
689752
690753
754+ @deprecated ()
691755def replace (version , ** parts ):
692756 """
693757 Replace one or more parts of a version and return the new string.
694758
759+ .. deprecated:: 2.9.2
760+ Use :func:`semver.VersionInfo.replace` instead.
761+
695762 :param str version: the version string to replace
696763 :param dict parts: the parts to be updated. Valid keys are:
697764 ``major``, ``minor``, ``patch``, ``prerelease``, or ``build``
0 commit comments