2
2
import datetime
3
3
import warnings
4
4
import re
5
- from itertools import chain , repeat , islice
6
5
7
6
from .config import Configuration
8
7
from .utils import trace , string_types , utc
16
15
SEMVER_LEN = 3
17
16
18
17
19
- def _pad (iterable , size , padding = None ):
20
- padded = chain (iterable , repeat (padding ))
21
- return list (islice (padded , size ))
22
-
23
-
24
18
def _parse_version_tag (tag , config ):
25
19
tagstring = tag if not isinstance (tag , string_types ) else str (tag )
26
20
match = config .tag_regex .match (tagstring )
@@ -132,6 +126,7 @@ def __init__(
132
126
dirty = False ,
133
127
preformatted = False ,
134
128
branch = None ,
129
+ config = None ,
135
130
** kw
136
131
):
137
132
if kw :
@@ -146,6 +141,7 @@ def __init__(
146
141
self .dirty = dirty
147
142
self .preformatted = preformatted
148
143
self .branch = branch
144
+ self .config = config
149
145
150
146
@property
151
147
def extra (self ):
@@ -193,7 +189,14 @@ def _parse_tag(tag, preformatted, config):
193
189
194
190
195
191
def meta (
196
- tag , distance = None , dirty = False , node = None , preformatted = False , config = None , ** kw
192
+ tag ,
193
+ distance = None ,
194
+ dirty = False ,
195
+ node = None ,
196
+ preformatted = False ,
197
+ branch = None ,
198
+ config = None ,
199
+ ** kw
197
200
):
198
201
if not config :
199
202
warnings .warn (
@@ -203,7 +206,9 @@ def meta(
203
206
parsed_version = _parse_tag (tag , preformatted , config )
204
207
trace ("version" , tag , "->" , parsed_version )
205
208
assert parsed_version is not None , "cant parse version %s" % tag
206
- return ScmVersion (parsed_version , distance , node , dirty , preformatted , ** kw )
209
+ return ScmVersion (
210
+ parsed_version , distance , node , dirty , preformatted , branch , config , ** kw
211
+ )
207
212
208
213
209
214
def guess_next_version (tag_version ):
@@ -238,12 +243,14 @@ def guess_next_dev_version(version):
238
243
239
244
240
245
def guess_next_simple_semver (version , retain , increment = True ):
241
- parts = map (int , str (version ).split ("." ))
242
- parts = _pad (parts , retain , 0 )
246
+ parts = [int (i ) for i in str (version ).split ("." )[:retain ]]
247
+ while len (parts ) < retain :
248
+ parts .append (0 )
243
249
if increment :
244
250
parts [- 1 ] += 1
245
- parts = _pad (parts , SEMVER_LEN , 0 )
246
- return "." .join (map (str , parts ))
251
+ while len (parts ) < SEMVER_LEN :
252
+ parts .append (0 )
253
+ return "." .join (str (i ) for i in parts )
247
254
248
255
249
256
def simplified_semver_version (version ):
@@ -260,6 +267,25 @@ def simplified_semver_version(version):
260
267
)
261
268
262
269
270
+ def release_branch_semver (version ):
271
+ if version .exact :
272
+ return version .format_with ("{tag}" )
273
+ if version .branch is not None :
274
+ # Does the branch name (stripped of namespace) parse as a version?
275
+ branch_ver = _parse_version_tag (version .branch .split ("/" )[- 1 ], version .config )
276
+ if branch_ver is not None :
277
+ # Does the branch version up to the minor part match the tag? If not it
278
+ # might be like, an issue number or something and not a version number, so
279
+ # we only want to use it if it matches.
280
+ tag_ver_up_to_minor = str (version .tag ).split ("." )[:SEMVER_MINOR ]
281
+ branch_ver_up_to_minor = branch_ver ["version" ].split ("." )[:SEMVER_MINOR ]
282
+ if branch_ver_up_to_minor == tag_ver_up_to_minor :
283
+ # We're in a release/maintenance branch, next is a patch/rc/beta bump:
284
+ return version .format_next_version (guess_next_version )
285
+ # We're in a development branch, next is a minor bump:
286
+ return version .format_next_version (guess_next_simple_semver , retain = SEMVER_MINOR )
287
+
288
+
263
289
def _format_local_with_time (version , time_format ):
264
290
265
291
if version .exact or version .node is None :
0 commit comments