8000 small cleanups · drinkingjava/python-versioneer@e6ac102 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6ac102

Browse files
committed
small cleanups
1 parent 37e7951 commit e6ac102

File tree

2 files changed

+26
-45
lines changed

2 files changed

+26
-45
lines changed

setup.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env python
22

33
import os, base64, tempfile, io, sys
4-
4+
from os import path
55
from distutils.core import setup, Command
66
from distutils.command.build_scripts import build_scripts
7-
from os import path
87

98
LONG="""
109
Versioneer is a tool to automatically update version strings (in setup.py and
@@ -19,8 +18,8 @@ def get(fn):
1918
with open(fn) as f:
2019
text = f.read()
2120

22-
# If we're in Python <3 and have a separate Unicode type, we would've read
23-
# a non-unicode string. Else, all strings will be unicode strings.
21+
# If we're in Python <3 and have a separate Unicode type, we would've
22+
# read a non-unicode string. Else, all strings will be unicode strings.
2423
try:
2524
__builtins__.unicode
2625
except AttributeError:
@@ -37,8 +36,8 @@ def readme(s):
3736

3837
def get_vcs_list():
3938
project_path = path.join(path.abspath(path.dirname(__file__)), 'src')
40-
return [filename
41-
for filename
39+
return [filename
40+
for filename
4241
in os.listdir(project_path)
4342
if path.isdir(path.join(project_path, filename))]
4443

@@ -56,10 +55,10 @@ def generate_versioneer():
5655
s.write(unquote(get("src/%s/from_vcs.py" % VCS)))
5756
s.write(unquote(get("src/%s/long_get_versions.py" % VCS)))
5857
s.write(u"'''\n")
59-
58+
6059
s.write(get("src/%s/from_keywords.py" % VCS))
6160
s.write(get("src/%s/from_vcs.py" % VCS))
62-
61+
6362
s.write(get("src/%s/install.py" % VCS))
6463

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

src/get_versions.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_root():
77
return os.path.dirname(os.path.abspath(sys.argv[0]))
88

99
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)
1111

1212
def get_versions(default=DEFAULT, verbose=False):
1313
# returns dict with two keys: 'version' and 'full'
@@ -24,57 +24,39 @@ def get_versions(default=DEFAULT, verbose=False):
2424
root = get_root()
2525
versionfile_abs = os.path.join(root, versionfile_source)
2626

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.
3332

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:
4236
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
5441

5542
ver = versions_from_file(versionfile_abs)
5643
if ver:
5744
if verbose: print("got version from file %s %s" % (versionfile_abs,ver))
5845
return ver
5946

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:
6549
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
7153

7254
ver = versions_from_parentdir(parentdir_prefix, root, verbose)
7355
if ver:
7456
if verbose: print("got version from parentdir %s" % ver)
7557
return ver
7658

77-
if verbose: print("got version from default %s" % ver)
59+
if verbose: print("got version from default %s" % default)
7860
return default
7961

8062
def get_version(verbose=False):

0 commit comments

Comments
 (0)
0