66# that just contains the computed version number.
77
88# 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)
1010
1111"""Git implementation of _version.py."""
1212
@@ -25,7 +25,8 @@ def get_keywords():
2525 # get_keywords().
2626 git_refnames = "$Format:%d$"
2727 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 }
2930 return keywords
3031
3132
@@ -39,7 +40,7 @@ def get_config():
3940 # _version.py
4041 cfg = VersioneerConfig ()
4142 cfg .VCS = "git"
42- cfg .style = "pep440"
43+ cfg .style = "pep440-post "
4344 cfg .tag_prefix = "v"
4445 cfg .parentdir_prefix = "None"
4546 cfg .versionfile_source = "ciscosparkapi/_version.py"
@@ -66,15 +67,17 @@ def decorate(f):
6667 return decorate
6768
6869
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 ):
7072 """Call the given command(s)."""
7173 assert isinstance (commands , list )
7274 p = None
7375 for c in commands :
7476 try :
7577 dispcmd = str ([c ] + args )
7678 # 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 ,
7881 stderr = (subprocess .PIPE if hide_stderr
7982 else None ))
8083 break
@@ -85,36 +88,45 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
8588 if verbose :
8689 print ("unable to run %s" % dispcmd )
8790 print (e )
88- return None
91+ return None , None
8992 else :
9093 if verbose :
9194 print ("unable to find command, tried %s" % (commands ,))
92- return None
95+ return None , None
9396 stdout = p .communicate ()[0 ].strip ()
9497 if sys .version_info [0 ] >= 3 :
9598 stdout = stdout .decode ()
9699 if p .returncode != 0 :
97100 if verbose :
98101 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
101105
102106
103107def versions_from_parentdir (parentdir_prefix , root , verbose ):
104108 """Try to determine the version from the parent directory name.
105109
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
108113 """
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" )
118130
119131
120132@register_vcs_handler ("git" , "get_keywords" )
@@ -136,6 +148,10 @@ def git_get_keywords(versionfile_abs):
136148 mo = re .search (r'=\s*"(.*)"' , line )
137149 if mo :
138150 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 )
139155 f .close ()
140156 except EnvironmentError :
141157 pass
@@ -147,6 +163,15 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
147163 """Get version information from git keywords."""
148164 if not keywords :
149165 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 )
150175 refnames = keywords ["refnames" ].strip ()
151176 if refnames .startswith ("$Format" ):
152177 if verbose :
@@ -167,7 +192,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
167192 # "stabilization", as well as "HEAD" and "master".
168193 tags = set ([r for r in refs if re .search (r'\d' , r )])
169194 if verbose :
170- print ("discarding '%s', no digits" % "," .join (refs - tags ))
195+ print ("discarding '%s', no digits" % "," .join (refs - tags ))
171196 if verbose :
172197 print ("likely tags: %s" % "," .join (sorted (tags )))
173198 for ref in sorted (tags ):
@@ -178,14 +203,14 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
178203 print ("picking %s" % r )
179204 return {"version" : r ,
180205 "full-revisionid" : keywords ["full" ].strip (),
181- "dirty" : False , "error" : None
182- }
206+ "dirty" : False , "error" : None ,
207+ "date" : date }
183208 # no suitable tags, so version is "0+unknown", but full hex is still there
184209 if verbose :
185210 print ("no suitable tags, using unknown + full revision id" )
186211 return {"version" : "0+unknown" ,
187212 "full-revisionid" : keywords ["full" ].strip (),
188- "dirty" : False , "error" : "no suitable tags" }
213+ "dirty" : False , "error" : "no suitable tags" , "date" : None }
189214
190215
191216@register_vcs_handler ("git" , "pieces_from_vcs" )
@@ -196,25 +221,28 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
196221 expanded, and _version.py hasn't already been rewritten with a short
197222 version string, meaning we're inside a checked out source tree.
198223 """
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-
204224 GITS = ["git" ]
205225 if sys .platform == "win32" :
206226 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+
207235 # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
208236 # 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 )
213241 # --long was added in git-1.5.5
214242 if describe_out is None :
215243 raise NotThisMethod ("'git describe' failed" )
216244 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 )
218246 if full_out is None :
219247 raise NotThisMethod ("'git rev-parse' failed" )
220248 full_out = full_out .strip ()
@@ -265,10 +293,15 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
265293 else :
266294 # HEX: no tags
267295 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 )
270298 pieces ["distance" ] = int (count_out ) # total number of commits
271299
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+
272305 return pieces
273306
274307
@@ -415,7 +448,8 @@ def render(pieces, style):
415448 return {"version" : "unknown" ,
416449 "full-revisionid" : pieces .get ("long" ),
417450 "dirty" : None ,
418- "error" : pieces ["error" ]}
451+ "error" : pieces ["error" ],
452+ "date" : None }
419453
420454 if not style or style == "default" :
421455 style = "pep440" # the default
@@ -436,7 +470,8 @@ def render(pieces, style):
436470 raise ValueError ("unknown style '%s'" % style )
437471
438472 return {"version" : rendered , "full-revisionid" : pieces ["long" ],
439- "dirty" : pieces ["dirty" ], "error" : None }
473+ "dirty" : pieces ["dirty" ], "error" : None ,
474+ "date" : pieces .get ("date" )}
440475
441476
442477def get_versions ():
@@ -465,7 +500,8 @@ def get_versions():
465500 except NameError :
466501 return {"version" : "0+unknown" , "full-revisionid" : None ,
467502 "dirty" : None ,
468- "error" : "unable to find root of source tree" }
503+ "error" : "unable to find root of source tree" ,
504+ "date" : None }
469505
470506 try :
471507 pieces = git_pieces_from_vcs (cfg .tag_prefix , root , verbose )
@@ -481,4 +517,4 @@ def get_versions():
481517
482518 return {"version" : "0+unknown" , "full-revisionid" : None ,
483519 "dirty" : None ,
484- "error" : "unable to compute version" }
520+ "error" : "unable to compute version" , "date" : None }
0 commit comments