@@ -7,7 +7,7 @@ def get_root():
7
7
return os .path .dirname (os .path .abspath (sys .argv [0 ]))
8
8
9
9
def vcs_function (vcs , suffix ):
10
- return getattr (sys .modules [__name__ ], '%s_%s' % (vcs , suffix ))
10
+ return getattr (sys .modules [__name__ ], '%s_%s' % (vcs , suffix ), None )
11
11
12
12
def get_versions (default = DEFAULT , verbose = False ):
13
13
# returns dict with two keys: 'version' and 'full'
@@ -24,57 +24,39 @@ def get_versions(default=DEFAULT, verbose=False):
24
24
root = get_root ()
25
25
versionfile_abs = os .path .join (root , versionfile_source )
26
26
27
- # TODO(dustin): Fix this comment to be VCS-agnostic.
28
- # extract version from first of _version.py, 'git describe', parentdir.
29
- # This is meant to work for developers using a source checkout, for users
30
- # of a tarball created by 'setup.py sdist', and for users of a
31
- # tarball/zipball created by 'git archive' or github's download-from-tag
32
- # feature.
27
+ # extract version from first of _version.py, VCS command (e.g. 'git
28
+ # describe'), parentdir. This is meant to work for developers using a
29
+ # source checkout, for users of a tarball created by 'setup.py sdist',
30
+ # and for users of a tarball/zipball created by 'git archive' or github's
31
+ # download-from-tag feature or the equivalent in other VCSes.
33
32
34
- ver = None
35
-
36
- try :
37
- get_keywords_f = vcs_function (VCS , 'get_keywords' )
38
- except AttributeError :
39
- get_keywords_f = None
40
-
41
- if get_keywords_f is not None :
33
+ get_keywords_f = vcs_function (VCS , "get_keywords" )
34
+ versions_from_keywords_f = vcs_function (VCS , "versions_from_keywords" )
35
+ if get_keywords_f and versions_from_keywords_f :
42
36
vcs_keywords = get_keywords_f (versionfile_abs )
43
-
44
- try :
45
- versions_from_keywords_f = vcs_function (VCS , 'versions_from_keywords' )
46
- except AttributeError :
47
- pass
48
- else :
49
- ver = versions_from_keywords_f (vcs_keywords , tag_prefix )
50
-
51
- if ver :
52
- if verbose : print ("got version from expanded keyword %s" % ver )
53
- return ver
37
+ ver = versions_from_keywords_f (vcs_keywords , tag_prefix )
38
+ if ver :
39
+ if verbose : print ("got version from expanded keyword %s" % ver )
40
+ return ver
54
41
55
42
ver = versions_from_file (versionfile_abs )
56
43
if ver :
57
44
if verbose : print ("got version from file %s %s" % (versionfile_abs ,ver ))
58
45
return ver
59
46
60
- try :
61
- versions_from_vcs_f = vcs_function (VCS , 'versions_from_vcs' )
62
- except AttributeError :
63
- ver = None
64
- else :
47
+ versions_from_vcs_f = vcs_function (VCS , "versions_from_vcs" )
48
+ if versions_from_vcs_f :
65
49
ver = versions_from_vcs_f (tag_prefix , root , verbose )
66
-
67
-
68
- if ver :
69
- if verbose : print ("got version from VCS %s" % ver )
70
- return ver
50
+ if ver :
51
+ if verbose : print ("got version from VCS %s" % ver )
52
+ return ver
71
53
72
54
ver = versions_from_parentdir (parentdir_prefix , root , verbose )
73
55
if ver :
74
56
if verbose : print ("got version from parentdir %s" % ver )
75
57
return ver
76
58
77
- if verbose : print ("got version from default %s" % ver )
59
+ if verbose : print ("got version from default %s" % default )
78
60
return default
79
61
80
62
def get_version (verbose = False ):
0 commit comments