1717__maintainer_email__ = "s.celles@gmail.com"
1818
1919
20- _LAST_NUMBER = re .compile (r"(?:[^\d]*(\d+)[^\d]*)+" )
21-
2220#: Contains the implemented semver.org version of the spec
2321SEMVER_SPEC_VERSION = "2.0.0"
2422
@@ -141,6 +139,7 @@ class VersionInfo(object):
141139 """
142140
143141 __slots__ = ("_major" , "_minor" , "_patch" , "_prerelease" , "_build" )
142+ _LAST_NUMBER = re .compile (r"(?:[^\d]*(\d+)[^\d]*)+" )
144143 _REGEX = re .compile (
145144 r"""
146145 ^
@@ -268,6 +267,24 @@ def __iter__(self):
268267 for v in self .to_tuple ():
269268 yield v
270269
270+ @staticmethod
271+ def _increment_string (string ):
272+ """
273+ Look for the last sequence of number(s) in a string and increment.
274+
275+ :param str string: the string to search for.
276+ :return: the incremented string
277+
278+ Source:
279+ http://code.activestate.com/recipes/442460-increment-numbers-in-a-string/#c1
280+ """
281+ match = VersionInfo ._LAST_NUMBER .search (string )
282+ if match :
283+ next_ = str (int (match .group (1 )) + 1 )
284+ start , end = match .span (1 )
285+ string = string [: max (end - len (next_ ), start )] + next_ + string [end :]
286+ return string
287+
271288 def bump_major (self ):
272289 """
273290 Raise the major part of the version, return a new object but leave self
@@ -328,7 +345,7 @@ def bump_prerelease(self, token="rc"):
328345 build=None)
329346 """
330347 cls = type (self )
331- prerelease = _increment_string (self ._prerelease or (token or "rc" ) + ".0" )
348+ prerelease = cls . _increment_string (self ._prerelease or (token or "rc" ) + ".0" )
332349 return cls (self ._major , self ._minor , self ._patch , prerelease )
333350
334351 def bump_build (self , token = "build" ):
@@ -346,7 +363,7 @@ def bump_build(self, token="build"):
346363 build='build.10')
347364 """
348365 cls = type (self )
349- build = _increment_string (self ._build or (token or "build" ) + ".0" )
366+ build = cls . _increment_string (self ._build or (token or "build" ) + ".0" )
350367 return cls (self ._major , self ._minor , self ._patch , self ._prerelease , build )
351368
352369 @comparator
@@ -692,20 +709,6 @@ def format_version(major, minor, patch, prerelease=None, build=None):
692709 return str (VersionInfo (major , minor , patch , prerelease , build ))
693710
694711
695- def _increment_string (string ):
696- """
697- Look for the last sequence of number(s) in a string and increment, from:
698-
699- http://code.activestate.com/recipes/442460-increment-numbers-in-a-string/#c1
700- """
701- match = _LAST_NUMBER .search (string )
702- if match :
703- next_ = str (int (match .group (1 )) + 1 )
704- start , end = match .span (1 )
705- string = string [: max (end - len (next_ ), start )] + next_ + string [end :]
706- return string
707-
708-
709712@deprecated (version = "2.9.2" )
710713def bump_major (version ):
711714 """
0 commit comments