8000 Bug fixes from PR. · drinkingjava/python-versioneer@5a0e28a · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a0e28a

Browse files
committed
Bug fixes from PR.
python-versioneer#28 - Moved vcs_function up in scope. - Thinned code within try blocks. - Removed to-do. - Removed unnecessary slash. - Re-added necessary but redundant injections.
1 parent 2376f62 commit 5a0e28a

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_vcs_list():
3939
project_path = path.join(path.abspath(path.dirname(__file__)), 'src')
4040
return [filename
4141
for filename
42-
in os.listdir(project_path) \
42+
in os.listdir(project_path)
4343
if path.isdir(path.join(project_path, filename))]
4444

4545
def generate_versioneer():
@@ -56,7 +56,10 @@ def generate_versioneer():
5656
s.write(unquote(get("src/%s/from_vcs.py" % VCS)))
5757
s.write(unquote(get("src/%s/long_get_versions.py" % VCS)))
5858
s.write(u"'''\n")
59-
59+
60+
s.write(get("src/%s/from_keywords.py" % VCS))
61+
s.write(get("src/%s/from_vcs.py" % VCS))
62+
6063
s.write(get("src/%s/install.py" % VCS))
6164

6265
s.write(get("src/from_parentdir.py"))

src/get_versions.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ def get_root():
66
except NameError:
77
return os.path.dirname(os.path.abspath(sys.argv[0]))
88

9+
def vcs_function(vcs, suffix):
10+
return getattr(sys.modules[__name__], '%s_%s' % (vcs, suffix))
11+
912
def get_versions(default=DEFAULT, verbose=False):
1013
# returns dict with two keys: 'version' and 'full'
1114
assert versionfile_source is not None, "please set versioneer.versionfile_source"
@@ -28,19 +31,22 @@ def get_versions(default=DEFAULT, verbose=False):
2831
# tarball/zipball created by 'git archive' or github's download-from-tag
2932
# feature.
3033

31-
def vcs_function(vcs, suffix):
32-
return getattr(sys.modules[__name__], '%s_%s' % (vcs, suffix))
34+
ver = None
3335

3436
try:
3537
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:
3642
vcs_keywords = get_keywords_f(versionfile_abs)
3743

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?
43-
ver = None
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)
4450

4551
if ver:
4652
if verbose: print("got version from expanded keyword %s" % ver)
@@ -53,11 +59,11 @@ def vcs_function(vcs, suffix):
5359

5460
try:
5561
versions_from_vcs_f = vcs_function(VCS, 'versions_from_vcs')
56-
ver = versions_from_vcs_f(tag_prefix, root, verbose)
5762
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?
6063
ver = None
64+
else:
65+
ver = versions_from_vcs_f(tag_prefix, root, verbose)
66+
6167

6268
if ver:
6369
if verbose: print("got version from VCS %s" % ver)

0 commit comments

Comments
 (0)
0