8000 Generalized git-specific code. · drinkingjava/python-versioneer@a2e354a · GitHub
[go: up one dir, main page]

Skip to content

Commit a2e354a

Browse files
committed
Generalized git-specific code.
1 parent bb191ea commit a2e354a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/get_versions.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12

23
def get_root():
34
try:
@@ -20,17 +21,27 @@ def get_versions(default=DEFAULT, verbose=False):
2021
root = get_root()
2122
versionfile_abs = os.path.join(root, versionfile_source)
2223

24+
# TODO(dustin): Fix this comment to be VCS-agnostic.
2325
# extract version from first of _version.py, 'git describe', parentdir.
2426
# This is meant to work for developers using a source checkout, for users
2527
# of a tarball created by 'setup.py sdist', and for users of a
2628
# tarball/zipball created by 'git archive' or github's download-from-tag
2729
# feature.
2830

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?
3343
ver = None
44+
3445
if ver:
3546
if verbose: print("got version from expanded keyword %s" % ver)
3647
return ver
@@ -40,12 +51,16 @@ def get_versions(default=DEFAULT, verbose=False):
4051
if verbose: print("got version from file %s %s" % (versionfile_abs,ver))
4152
return ver
4253

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?
4660
ver = None
61+
4762
if ver:
48-
if verbose: print("got version from git %s" % ver)
63+
if verbose: print("got version from VCS %s" % ver)
4964
return ver
5065

5166
ver = versions_from_parentdir(parentdir_prefix, root, verbose)

0 commit comments

Comments
 (0)
0