17
17
__maintainer_email__ = "s.celles@gmail.com"
18
18
19
19
20
- _LAST_NUMBER = re .compile (r"(?:[^\d]*(\d+)[^\d]*)+" )
21
-
22
20
#: Contains the implemented semver.org version of the spec
23
21
SEMVER_SPEC_VERSION = "2.0.0"
24
22
@@ -141,6 +139,7 @@ class VersionInfo(object):
141
139
"""
142
140
143
141
__slots__ = ("_major" , "_minor" , "_patch" , "_prerelease" , "_build" )
142
+ _LAST_NUMBER = re .compile (r"(?:[^\d]*(\d+)[^\d]*)+" )
144
143
_REGEX = re .compile (
145
144
r"""
146
145
^
@@ -268,6 +267,24 @@ def __iter__(self):
268
267
for v in self .to_tuple ():
269
268
yield v
270
269
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
+
271
288
def bump_major (self ):
272
289
"""
273
290
Raise the major part of the version, return a new object but leave self
@@ -328,7 +345,7 @@ def bump_prerelease(self, token="rc"):
328
345
build=None)
329
346
"""
330
347
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" )
332
349
return cls (self ._major , self ._minor , self ._patch , prerelease )
333
350
334
351
def bump_build (self , token = "build" ):
@@ -346,7 +363,7 @@ def bump_build(self, token="build"):
346
363
build='build.10')
347
364
"""
348
365
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" )
350
367
return cls (self ._major , self ._minor , self ._patch , self ._prerelease , build )
351
368
352
369
@comparator
@@ -692,20 +709,6 @@ def format_version(major, minor, patch, prerelease=None, build=None):
692
709
return str (VersionInfo (major , minor , patch , prerelease , build ))
693
710
694
711
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
-
709
712
@deprecated (version = "2.9.2" )
710
713
def bump_major (version ):
711
714
"""
0 commit comments