1
+ import sys
1
2
2
3
def get_root ():
3
4
try :
@@ -20,17 +21,27 @@ def get_versions(default=DEFAULT, verbose=False):
20
21
root = get_root ()
21
22
versionfile_abs = os .path .join (root , versionfile_source )
22
23
24
+ # TODO(dustin): Fix this comment to be VCS-agnostic.
23
25
# extract version from first of _version.py, 'git describe', parentdir.
24
26
# This is meant to work for developers using a source checkout, for users
25
27
# of a tarball created by 'setup.py sdist', and for users of a
26
28
# tarball/zipball created by 'git archive' or github's download-from-tag
27
29
# feature.
28
30
29
- if VCS == "git" :
30
- ver = git_versions_from_keywords (git_get_keywords (versionfile_abs ),
31
- tag_prefix )
32
- else :
31
+ def vcs_function (vcs , suffix ):
32
+ return getattr (sys .modules [__name__ ], '%s_%s' % (vcs , suffix ))
33
+
34
+ try :
35
+ get_keywords_f = vcs_function (VCS , 'get_keywords' )
36
+ vcs_keywords = get_keywords_f (versionfile_abs )
37
+
38
+ versions_from_keywords_f = vcs_function (VCS , 'versions_from_keywords' )
39
+ ver = versions_from_keywords_f (vcs_keywords , tag_prefix )
40
+ except AttributeError :
41
+ # TODO(dustin): We used to take Non when the VCS was unknown. Now we'll only
42
+ # take None if the VCS-specific function isn't defined. Is this okay?
33
43
ver = None
44
+
34
45
if ver :
35
46
if verbose : print ("got version from expanded keyword %s" % ver )
36
47
return ver
@@ -40,12 +51,16 @@ def get_versions(default=DEFAULT, verbose=False):
40
51
if verbose : print ("got version from file %s %s" % (versionfile_abs ,ver ))
41
52
return ver
42
53
43
- if VCS == "git" :
44
- ver = git_versions_from_vcs (tag_prefix , root , verbose )
45
- else :
54
+ try :
55
+ versions_from_vcs_f = vcs_function (VCS , 'versions_from_vcs' )
56
+ ver = versions_from_vcs_f (tag_prefix , root , verbose )
57
+ except AttributeError :
58
+ # TODO(dustin): We used to take Non when the VCS was unknown. Now we'll only
59
+ # take None if the VCS-specific function isn't defined. Is this okay?
46
60
ver = None
61
+
47
62
if ver :
48
- if verbose : print ("got version from git %s" % ver )
63
+ if verbose : print ("got version from VCS %s" % ver )
49
64
return ver
50
65
51
66
ver = versions_from_parentdir (parentdir_prefix , root , verbose )
0 commit comments