1
+
1
2
# This file helps to compute a version number in source trees obtained from
2
3
# git-archive tarball (such as those provided by githubs download-from-tag
3
4
# feature). Distribution tarballs (built by setup.py sdist) and build
4
5
# directories (produced by setup.py build) will contain a much shorter file
5
6
# that just contains the computed version number.
6
7
7
- # This file is released into the public domain. Generated by
8
- # versioneer-0.23.dev0 (https://github.com/python-versioneer/python-versioneer)
8
+ # This file is released into the public domain.
9
+ # Generated by versioneer-0.28
10
+ # https://github.com/python-versioneer/python-versioneer
9
11
10
12
"""Git implementation of _version.py."""
11
13
12
14
import errno
13
- import functools
14
15
import os
15
16
import re
16
17
import subprocess
17
18
import sys
18
19
from typing import Callable , Dict
20
+ import functools
19
21
20
22
21
23
def get_keywords ():
@@ -59,18 +61,17 @@ class NotThisMethod(Exception):
59
61
60
62
def register_vcs_handler (vcs , method ): # decorator
61
63
"""Create decorator to mark a method as the handler of a VCS."""
62
-
63
64
def decorate (f ):
64
65
"""Store f in HANDLERS[vcs][method]."""
65
66
if vcs not in HANDLERS :
66
67
HANDLERS [vcs ] = {}
67
68
HANDLERS [vcs ][method ] = f
68
69
return f
69
-
70
70
return decorate
71
71
72
72
73
- def run_command (commands , args , cwd = None , verbose = False , hide_stderr = False , env = None ):
73
+ def run_command (commands , args , cwd = None , verbose = False , hide_stderr = False ,
74
+ env = None ):
74
75
"""Call the given command(s)."""
75
76
assert isinstance (commands , list )
76
77
process = None
@@ -86,14 +87,10 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
86
87
try :
87
88
dispcmd = str ([command ] + args )
88
89
# remember shell=False, so use git.cmd on windows, not just git
89
- process = subprocess .Popen (
90
- [command ] + args ,
91
- cwd = cwd ,
92
- env = env ,
93
- stdout = subprocess .PIPE ,
94
- stderr = (subprocess .PIPE if hide_stderr else None ),
95
- ** popen_kwargs
96
- )
90
+ process = subprocess .Popen ([command ] + args , cwd = cwd , env = env ,
91
+ stdout = subprocess .PIPE ,
92
+ stderr = (subprocess .PIPE if hide_stderr
93
+ else None ), ** popen_kwargs )
97
94
break
98
95
except OSError :
99
96
e = sys .exc_info ()[1 ]
@@ -105,7 +102,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
105
102
return None , None
106
103
else :
107
104
if verbose :
108
- print (f "unable to find command, tried { commands } " )
105
+ print ("unable to find command, tried %s" % ( commands ,) )
109
106
return None , None
110
107
stdout = process .communicate ()[0 ].strip ().decode ()
111
108
if process .returncode != 0 :
@@ -128,21 +125,15 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
128
125
for _ in range (3 ):
129
126
dirname = os .path .basename (root )
130
127
if dirname .startswith (parentdir_prefix ):
131
- return {
132
- "version" : dirname [len (parentdir_prefix ) :],
133
- "full-revisionid" : None ,
134
- "dirty" : False ,
135
- "error" : None ,
136
- "date" : None ,
137
- }
128
+ return {"version" : dirname [len (parentdir_prefix ):],
129
+ "full-revisionid" : None ,
130
+ "dirty" : False , "error" : None , "date" : None }
138
131
rootdirs .append (root )
139
132
root = os .path .dirname (root ) # up a level
140
133
141
134
if verbose :
142
- print (
143
- "Tried directories %s but none started with prefix %s"
144
- % (str (rootdirs ), parentdir_prefix )
145
- )
135
+ print ("Tried directories %s but none started with prefix %s" %
136
+ (str (rootdirs ), parentdir_prefix ))
146
137
raise NotThisMethod ("rootdir doesn't start with parentdir_prefix" )
147
138
148
139
@@ -155,7 +146,7 @@ def git_get_keywords(versionfile_abs):
155
146
# _version.py.
156
147
keywords = {}
157
148
try :
158
- with open (versionfile_abs ) as fobj :
149
+ with open (versionfile_abs , "r" ) as fobj :
159
150
for line in fobj :
160
151
if line .strip ().startswith ("git_refnames =" ):
161
152
mo = re .search (r'=\s*"(.*)"' , line )
@@ -201,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
201
192
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
202
193
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
203
194
TAG = "tag: "
204
- tags = {r [len (TAG ) :] for r in refs if r .startswith (TAG )}
195
+ tags = {r [len (TAG ):] for r in refs if r .startswith (TAG )}
205
196
if not tags :
206
197
# Either we're using git < 1.8.3, or there really are no tags. We use
207
198
# a heuristic: assume all version tags have a digit. The old git %d
@@ -210,39 +201,32 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
210
201
# between branches and tags. By ignoring refnames without digits, we
211
202
# filter out many common branch names like "release" and
212
203
# "stabilization", as well as "HEAD" and "master".
213
- tags = {r for r in refs if re .search (r"\d" , r )}
204
+ tags = {r for r in refs if re .search (r'\d' , r )}
214
205
if verbose :
215
206
print ("discarding '%s', no digits" % "," .join (refs - tags ))
216
207
if verbose :
217
208
print ("likely tags: %s" % "," .join (sorted (tags )))
218
209
for ref in sorted (tags ):
219
210
# sorting will prefer e.g. "2.0" over "2.0rc1"
220
211
if ref .startswith (tag_prefix ):
221
- r = ref [len (tag_prefix ) :]
212
+ r = ref [len (tag_prefix ):]
222
213
# Filter out refs that exactly match prefix or that don't start
223
214
# with a number once the prefix is stripped (mostly a concern
224
215
# when prefix is '')
225
- if not re .match (r"\d" , r ):
216
+ if not re .match (r'\d' , r ):
226
217
continue
227
218
if verbose :
228
219
print ("picking %s" % r )
229
- return {
230
- "version" : r ,
231
- "full-revisionid" : keywords ["full" ].strip (),
232
- "dirty" : False ,
233
- "error" : None ,
234
- "date" : date ,
235
- }
220
+ return {"version" : r ,
221
+ "full-revisionid" : keywords ["full" ].strip (),
222
+ "dirty" : False , "error" : None ,
223
+ "date" : date }
236
224
# no suitable tags, so version is "0+unknown", but full hex is still there
237
225
if verbose :
238
226
print ("no suitable tags, using unknown + full revision id" )
239
- return {
240
- "version" : "0+unknown" ,
241
- "full-revisionid" : keywords ["full" ].strip (),
242
- "dirty" : False ,
243
- "error" : "no suitable tags" ,
244
- "date" : None ,
245
- }
227
+ return {"version" : "0+unknown" ,
228
+ "full-revisionid" : keywords ["full" ].strip (),
229
+ "dirty" : False , "error" : "no suitable tags" , "date" : None }
246
230
247
231
248
232
@register_vcs_handler ("git" , "pieces_from_vcs" )
@@ -264,21 +248,19 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
264
248
env .pop ("GIT_DIR" , None )
265
249
runner = functools .partial (runner , env = env )
266
250
267
- _ , rc = runner (GITS , ["rev-parse" , "--git-dir" ], cwd = root , hide_stderr = True )
251
+ _ , rc = runner (GITS , ["rev-parse" , "--git-dir" ], cwd = root ,
252
+ hide_stderr = not verbose )
268
253
if rc != 0 :
269
254
if verbose :
270
255
print ("Directory %s not under git control" % root )
271
256
raise NotThisMethod ("'git rev-parse --git-dir' returned error" )
272
257
273
- MATCH_ARGS = ["--match" , "%s*" % tag_prefix ] if tag_prefix else []
274
-
275
258
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
276
259
# if there isn't one, this yields HEX[-dirty] (no NUM)
277
- describe_out , rc = runner (
278
- GITS ,
279
- ["describe" , "--tags" , "--dirty" , "--always" , "--long" , * MATCH_ARGS ],
280
- cwd = root ,
281
- )
260
+ describe_out , rc = runner (GITS , [
261
+ "describe" , "--tags" , "--dirty" , "--always" , "--long" ,
262
+ "--match" , f"{ tag_prefix } [[:digit:]]*"
263
+ ], cwd = root )
282
264
# --long was added in git-1.5.5
283
265
if describe_out is None :
284
266
raise NotThisMethod ("'git describe' failed" )
@@ -293,7 +275,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
293
275
pieces ["short" ] = full_out [:7 ] # maybe improved later
294
276
pieces ["error" ] = None
295
277
296
- branch_name , rc = runner (GITS , ["rev-parse" , "--abbrev-ref" , "HEAD" ], cwd = root )
278
+ branch_name , rc = runner (GITS , ["rev-parse" , "--abbrev-ref" , "HEAD" ],
279
+ cwd = root )
297
280
# --abbrev-ref was added in git-1.6.3
298
281
if rc != 0 or branch_name is None :
299
282
raise NotThisMethod ("'git rev-parse --abbrev-ref' returned error" )
@@ -333,16 +316,17 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
333
316
dirty = git_describe .endswith ("-dirty" )
334
317
pieces ["dirty" ] = dirty
335
318
if dirty :
336
- git_describe = git_describe [: git_describe .rindex ("-dirty" )]
319
+ git_describe = git_describe [:git_describe .rindex ("-dirty" )]
337
320
338
321
# now we have TAG-NUM-gHEX or HEX
339
322
340
323
if "-" in git_describe :
341
324
# TAG-NUM-gHEX
342
- mo = re .search (r" ^(.+)-(\d+)-g([0-9a-f]+)$" , git_describe )
325
+ mo = re .search (r' ^(.+)-(\d+)-g([0-9a-f]+)$' , git_describe )
343
326
if not mo :
344
327
# unparsable. Maybe git-describe is misbehaving?
345
- pieces ["error" ] = "unable to parse git-describe output: '%s'" % describe_out
328
+ pieces ["error" ] = ("unable to parse git-describe output: '%s'"
329
+ % describe_out )
346
330
return pieces
347
331
348
332
# tag
@@ -351,12 +335,10 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
351
335
if verbose :
352
336
fmt = "tag '%s' doesn't start with prefix '%s'"
353
337
print (fmt % (full_tag , tag_prefix ))
354
- pieces ["error" ] = "tag '{}' doesn't start with prefix '{}'" .format (
355
- full_tag ,
356
- tag_prefix ,
357
- )
338
+ pieces ["error" ] = ("tag '%s' doesn't start with prefix '%s'"
339
+ % (full_tag , tag_prefix ))
358
340
return pieces
359
- pieces ["closest-tag" ] = full_tag [len (tag_prefix ) :]
341
+ pieces ["closest-tag" ] = full_tag [len (tag_prefix ):]
360
342
361
343
# distance: number of commits since tag
362
344
pieces ["distance" ] = int (mo .group (2 ))
@@ -367,8 +349,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
367
349
else :
368
350
# HEX: no tags
369
351
pieces ["closest-tag" ] = None
370
- count_out , rc = runner (GITS , ["rev-list" , "HEAD" , "--count " ], cwd = root )
371
- pieces ["distance" ] = int ( count_out ) # total number of commits
352
+ out , rc = runner (GITS , ["rev-list" , "HEAD" , "--left-right " ], cwd = root )
353
+ pieces ["distance" ] = len ( out . split () ) # total number of commits
372
354
373
355
# commit date: see ISO-8601 comment in git_versions_from_keywords()
374
356
date = runner (GITS , ["show" , "-s" , "--format=%ci" , "HEAD" ], cwd = root )[0 ].strip ()
@@ -405,7 +387,8 @@ def render_pep440(pieces):
405
387
rendered += ".dirty"
406
388
else :
407
389
# exception #1
408
- rendered = "0+untagged.%d.g%s" % (pieces ["distance" ], pieces ["short" ])
390
+ rendered = "0+untagged.%d.g%s" % (pieces ["distance" ],
391
+ pieces ["short" ])
409
392
if pieces ["dirty" ]:
410
393
rendered += ".dirty"
411
394
return rendered
@@ -434,7 +417,8 @@ def render_pep440_branch(pieces):
434
417
rendered = "0"
435
418
if pieces ["branch" ] != "master" :
436
419
rendered += ".dev0"
437
- rendered += "+untagged.%d.g%s" % (pieces ["distance" ], pieces ["short" ])
420
+ rendered += "+untagged.%d.g%s" % (pieces ["distance" ],
421
+ pieces ["short" ])
438
422
if pieces ["dirty" ]:
439
423
rendered += ".dirty"
440
424
return rendered
@@ -595,13 +579,11 @@ def render_git_describe_long(pieces):
595
579
def render (pieces , style ):
596
580
"""Render the given version pieces into the requested style."""
597
581
if pieces ["error" ]:
598
- return {
599
- "version" : "unknown" ,
600
- "full-revisionid" : pieces .get ("long" ),
601
- "dirty" : None ,
602
- "error" : pieces ["error" ],
603
- "date" : None ,
604
- }
582
+ return {"version" : "unknown" ,
583
+ "full-revisionid" : pieces .get ("long" ),
584
+ "dirty" : None ,
585
+ "error" : pieces ["error" ],
586
+ "date" : None }
605
587
606
588
if not style or style == "default" :
607
589
style = "pep440" # the default
@@ -625,13 +607,9 @@ def render(pieces, style):
625
607
else :
626
608
raise ValueError ("unknown style '%s'" % style )
627
609
628
- return {
629
- "version" : rendered ,
630
- "full-revisionid" : pieces ["long" ],
631
- "dirty" : pieces ["dirty" ],
632
- "error" : None ,
633
- "date" : pieces .get ("date" ),
634
- }
610
+ return {"version" : rendered , "full-revisionid" : pieces ["long" ],
611
+ "dirty" : pieces ["dirty" ], "error" : None ,
612
+ "date" : pieces .get ("date" )}
635
613
636
614
637
615
def get_versions ():
@@ -645,7 +623,8 @@ def get_versions():
645
623
verbose = cfg .verbose
646
624
647
625
try :
648
- return git_versions_from_keywords (get_keywords (), cfg .tag_prefix , verbose )
626
+ return git_versions_from_keywords (get_keywords (), cfg .tag_prefix ,
627
+ verbose )
649
628
except NotThisMethod :
650
629
pass
651
630
@@ -654,16 +633,13 @@ def get_versions():
654
633
# versionfile_source is the relative path from the top of the source
655
634
# tree (where the .git directory might live) to this file. Invert
656
635
# this to find the root from __file__.
657
- for _ in cfg .versionfile_source .split ("/" ):
636
+ for _ in cfg .versionfile_source .split ('/' ):
658
637
root = os .path .dirname (root )
659
638
except NameError :
660
- return {
661
- "version" : "0+unknown" ,
662
- "full-revisionid" : None ,
663
- "dirty" : None ,
664
- "error" : "unable to find root of source tree" ,
665
- "date" : None ,
666
- }
639
+ return {"version" : "0+unknown" , "full-revisionid" : None ,
640
+ "dirty" : None ,
641
+ "error" : "unable to find root of source tree" ,
642
+ "date" : None }
667
643
668
644
try :
669
645
pieces = git_pieces_from_vcs (cfg .tag_prefix , root , verbose )
@@ -677,10 +653,6 @@ def get_versions():
677
653
except NotThisMethod :
678
654
pass
679
655
680
- return {
681
- "version" : "0+unknown" ,
682
- "full-revisionid" : None ,
683
- "dirty" : None ,
684
- "error" : "unable to compute version" ,
685
- "date" : None ,
686
- }
656
+ return {"version" : "0+unknown" , "full-revisionid" : None ,
657
+ "dirty" : None ,
658
+ "error" : "unable to compute version" , "date" : None }
0 commit comments