6
6
# that just contains the computed version number.
7
7
8
8
# This file is released into the public domain. Generated by
9
- # versioneer-0.16 (https://github.com/warner/python-versioneer)
9
+ # versioneer-0.18 (https://github.com/warner/python-versioneer)
10
10
11
11
"""Git implementation of _version.py."""
12
12
@@ -25,7 +25,8 @@ def get_keywords():
25
25
# get_keywords().
26
26
git_refnames = "$Format:%d$"
27
27
git_full = "$Format:%H$"
28
- keywords = {"refnames" : git_refnames , "full" : git_full }
28
+ git_date = "$Format:%ci$"
29
+ keywords = {"refnames" : git_refnames , "full" : git_full , "date" : git_date }
29
30
return keywords
30
31
31
32
@@ -39,7 +40,7 @@ def get_config():
39
40
# _version.py
40
41
cfg = VersioneerConfig ()
41
42
cfg .VCS = "git"
42
- cfg .style = "pep440"
43
+ cfg .style = "pep440-post "
43
44
cfg .tag_prefix = "v"
44
45
cfg .parentdir_prefix = "None"
45
46
cfg .versionfile_source = "ciscosparkapi/_version.py"
@@ -66,15 +67,17 @@ def decorate(f):
66
67
return decorate
67
68
68
69
69
- def run_command (commands , args , cwd = None , verbose = False , hide_stderr = False ):
70
+ def run_command (commands , args , cwd = None , verbose = False , hide_stderr = False ,
71
+ env = None ):
70
72
"""Call the given command(s)."""
71
73
assert isinstance (commands , list )
72
74
p = None
73
75
for c in commands :
74
76
try :
75
77
dispcmd = str ([c ] + args )
76
78
# remember shell=False, so use git.cmd on windows, not just git
77
- p = subprocess .Popen ([c ] + args , cwd = cwd , stdout = subprocess .PIPE ,
79
+ p = subprocess .Popen ([c ] + args , cwd = cwd , env = env ,
80
+ stdout = subprocess .PIPE ,
78
81
stderr = (subprocess .PIPE if hide_stderr
79
82
else None ))
80
83
break
@@ -85,36 +88,45 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
85
88
if verbose :
86
89
print ("unable to run %s" % dispcmd )
87
90
print (e )
88
- return None
91
+ return None , None
89
92
else :
90
93
if verbose :
91
94
print ("unable to find command, tried %s" % (commands ,))
92
- return None
95
+ return None , None
93
96
stdout = p .communicate ()[0 ].strip ()
94
97
if sys .version_info [0 ] >= 3 :
95
98
stdout = stdout .decode ()
96
99
if p .returncode != 0 :
97
100
if verbose :
98
101
print ("unable to run %s (error)" % dispcmd )
99
- return None
100
- return stdout
102
+ print ("stdout was %s" % stdout )
103
+ return None , p .returncode
104
+ return stdout , p .returncode
101
105
102
106
103
107
def versions_from_parentdir (parentdir_prefix , root , verbose ):
104
108
"""Try to determine the version from the parent directory name.
105
109
106
- Source tarballs conventionally unpack into a directory that includes
107
- both the project name and a version string.
110
+ Source tarballs conventionally unpack into a directory that includes both
111
+ the project name and a version string. We will also support searching up
112
+ two directory levels for an appropriately named parent directory
108
113
"""
109
- dirname = os .path .basename (root )
110
- if not dirname .startswith (parentdir_prefix ):
111
- if verbose :
112
- print ("guessing rootdir is '%s', but '%s' doesn't start with "
113
- "prefix '%s'" % (root , dirname , parentdir_prefix ))
114
- raise NotThisMethod ("rootdir doesn't start with parentdir_prefix" )
115
- return {"version" : dirname [len (parentdir_prefix ):],
116
- "full-revisionid" : None ,
117
- "dirty" : False , "error" : None }
114
+ rootdirs = []
115
+
116
+ for i in range (3 ):
117
+ dirname = os .path .basename (root )
118
+ if dirname .startswith (parentdir_prefix ):
119
+ return {"version" : dirname [len (parentdir_prefix ):],
120
+ "full-revisionid" : None ,
121
+ "dirty" : False , "error" : None , "date" : None }
122
+ else :
123
+ rootdirs .append (root )
124
+ root = os .path .dirname (root ) # up a level
125
+
126
+ if verbose :
127
+ print ("Tried directories %s but none started with prefix %s" %
128
+ (str (rootdirs ), parentdir_prefix ))
129
+ raise NotThisMethod ("rootdir doesn't start with parentdir_prefix" )
118
130
119
131
120
132
@register_vcs_handler ("git" , "get_keywords" )
@@ -136,6 +148,10 @@ def git_get_keywords(versionfile_abs):
136
148
mo = re .search (r'=\s*"(.*)"' , line )
137
149
if mo :
138
150
keywords ["full" ] = mo .group (1 )
151
+ if line .strip ().startswith ("git_date =" ):
152
+ mo = re .search (r'=\s*"(.*)"' , line )
153
+ if mo :
154
+ keywords ["date" ] = mo .group (1 )
139
155
f .close ()
140
156
except EnvironmentError :
141
157
pass
@@ -147,6 +163,15 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
147
163
"""Get version information from git keywords."""
148
164
if not keywords :
149
165
raise NotThisMethod ("no keywords at all, weird" )
166
+ date = keywords .get ("date" )
167
+ if date is not None :
168
+ # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
169
+ # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
170
+ # -like" string, which we must then edit to make compliant), because
171
+ # it's been around since git-1.5.3, and it's too difficult to
172
+ # discover which version we're using, or to work around using an
173
+ # older one.
174
+ date = date .strip ().replace (" " , "T" , 1 ).replace (" " , "" , 1 )
150
175
refnames = keywords ["refnames" ].strip ()
151
176
if refnames .startswith ("$Format" ):
152
177
if verbose :
@@ -167,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
167
192
# "stabilization", as well as "HEAD" and "master".
168
193
tags = set ([r for r in refs if re .search (r'\d' , r )])
169
194
if verbose :
170
- print ("discarding '%s', no digits" % "," .join (refs - tags ))
195
+ print ("discarding '%s', no digits" % "," .join (refs - tags ))
171
196
if verbose :
172
197
print ("likely tags: %s" % "," .join (sorted (tags )))
173
198
for ref in sorted (tags ):
@@ -178,14 +203,14 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
178
203
print ("picking %s" % r )
179
204
return {"version" : r ,
180
205
"full-revisionid" : keywords ["full" ].strip (),
181
- "dirty" : False , "error" : None
182
- }
206
+ "dirty" : False , "error" : None ,
207
+ "date" : date }
183
208
# no suitable tags, so version is "0+unknown", but full hex is still there
184
209
if verbose :
185
210
print ("no suitable tags, using unknown + full revision id" )
186
211
return {"version" : "0+unknown" ,
187
212
"full-revisionid" : keywords ["full" ].strip (),
188
- "dirty" : False , "error" : "no suitable tags" }
213
+ "dirty" : False , "error" : "no suitable tags" , "date" : None }
189
214
190
215
191
216
@register_vcs_handler ("git" , "pieces_from_vcs" )
@@ -196,25 +221,28 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
196
221
expanded, and _version.py hasn't already been rewritten with a short
197
222
version string, meaning we're inside a checked out source tree.
198
223
"""
199
- if not os .path .exists (os .path .join (root , ".git" )):
200
- if verbose :
201
- print ("no .git in %s" % root )
202
- raise NotThisMethod ("no .git directory" )
203
-
204
224
GITS = ["git" ]
205
225
if sys .platform == "win32" :
206
226
GITS = ["git.cmd" , "git.exe" ]
227
+
228
+ out , rc = run_command (GITS , ["rev-parse" , "--git-dir" ], cwd = root ,
229
+ hide_stderr = True )
230
+ if rc != 0 :
231
+ if verbose :
232
+ print ("Directory %s not under git control" % root )
233
+ raise NotThisMethod ("'git rev-parse --git-dir' returned error" )
234
+
207
235
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
208
236
# if there isn't one, this yields HEX[-dirty] (no NUM)
209
- describe_out = run_command (GITS , ["describe" , "--tags" , "--dirty" ,
210
- "--always" , "--long" ,
211
- "--match" , "%s*" % tag_prefix ],
212
- cwd = root )
237
+ describe_out , rc = run_command (GITS , ["describe" , "--tags" , "--dirty" ,
238
+ "--always" , "--long" ,
239
+ "--match" , "%s*" % tag_prefix ],
240
+ cwd = root )
213
241
# --long was added in git-1.5.5
214
242
if describe_out is None :
215
243
raise NotThisMethod ("'git describe' failed" )
216
244
describe_out = describe_out .strip ()
217
- full_out = run_command (GITS , ["rev-parse" , "HEAD" ], cwd = root )
245
+ full_out , rc = run_command (GITS , ["rev-parse" , "HEAD" ], cwd = root )
218
246
if full_out is None :
219
247
raise NotThisMethod ("'git rev-parse' failed" )
220
248
full_out = full_out .strip ()
@@ -265,10 +293,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
265
293
else :
266
294
# HEX: no tags
267
295
pieces ["closest-tag" ] = None
268
- count_out = run_command (GITS , ["rev-list" , "HEAD" , "--count" ],
269
- cwd = root )
296
+ count_out , rc = run_command (GITS , ["rev-list" , "HEAD" , "--count" ],
297
+ cwd = root )
270
298
pieces ["distance" ] = int (count_out ) # total number of commits
271
299
300
+ # commit date: see ISO-8601 comment in git_versions_from_keywords()
301
+ date = run_command (GITS , ["show" , "-s" , "--format=%ci" , "HEAD" ],
302
+ cwd = root )[0 ].strip ()
303
+ pieces ["date" ] = date .strip ().replace (" " , "T" , 1 ).replace (" " , "" , 1 )
304
+
272
305
return pieces
273
306
274
307
@@ -415,7 +448,8 @@ def render(pieces, style):
415
448
return {"version" : "unknown" ,
416
449
"full-revisionid" : pieces .get ("long" ),
417
450
"dirty" : None ,
418
- "error" : pieces ["error" ]}
451
+ "error" : pieces ["error" ],
452
+ "date" : None }
419
453
420
454
if not style or style == "default" :
421
455
style = "pep440" # the default
@@ -436,7 +470,8 @@ def render(pieces, style):
436
470
raise ValueError ("unknown style '%s'" % style )
437
471
438
472
return {"version" : rendered , "full-revisionid" : pieces ["long" ],
439
- "dirty" : pieces ["dirty" ], "error" : None }
473
+ "dirty" : pieces ["dirty" ], "error" : None ,
474
+ "date" : pieces .get ("date" )}
440
475
441
476
442
477
def get_versions ():
@@ -465,7 +500,8 @@ def get_versions():
465
500
except NameError :
466
501
return {"version" : "0+unknown" , "full-revisionid" : None ,
467
502
"dirty" : None ,
468
- "error" : "unable to find root of source tree" }
503
+ "error" : "unable to find root of source tree" ,
504
+ "date" : None }
469
505
470
506
try :
471
507
pieces = git_pieces_from_vcs (cfg .tag_prefix , root , verbose )
@@ -481,4 +517,4 @@ def get_versions():
481
517
482
518
return {"version" : "0+unknown" , "full-revisionid" : None ,
483
519
"dirty" : None ,
484
- "error" : "unable to compute version" }
520
+ "error" : "unable to compute version" , "date" : None }
0 commit comments