Skip to content

Commit 0b8a0da

Browse files
committed
fixed 'setup.py build' from a git-archive tree
I think that's the full matrix of possibilities.
1 parent 3d7ab19 commit 0b8a0da

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

NOTES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@
7373
- _version.py will need to import that
7474
*** setup.py build
7575

76+
* current problems
77+
** DONE running 'setup.py build' from a git-archive tree
78+
- need version_from_expanded_variable() in versioneer.py too, not just
79+
_version.py

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ def get(fn): return open(fn, "r").read()
1414
for line in open("src/%s/parse.py" % vcs, "r").readlines():
1515
if line.startswith("#### START"):
1616
f.write("LONG_VERSION_PY = '''\n")
17+
elif line.startswith("#### SUBPROCESS_HELPER"):
1718
f.write(unquote(get("src/subprocess-helper.py")))
1819
elif line.startswith("#### VERSION_FROM_CHECKOUT"):
1920
f.write(unquote(get("src/%s/from-checkout.py" % vcs)))
21+
elif line.startswith("#### VERSION_FROM_VARIABLE"):
22+
f.write(unquote(get("src/%s/from-variable.py" % vcs)))
2023
elif line.startswith("#### END"):
2124
f.write("'''\n")
2225
else:
2326
f.write(line)
2427
f.write(get("src/%s/from-checkout.py" % vcs))
28+
f.write(get("src/%s/from-variable.py" % vcs))
2529
f.write(get("src/%s/setup.py" % vcs))
2630
f.write(get("src/trailer.py"))
2731
f.close()

src/git/from-checkout.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ def version_from_vcs(tag_prefix, verbose=False):
1515
(stdout, tag_prefix)
1616
return None
1717
return stdout[len(tag_prefix):]
18+

src/git/from-variable.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def version_from_expanded_variable(s, tag_prefix):
2+
s = s.strip()
3+
if "$Format" in s: # unexpanded
4+
return version_from_vcs(tag_prefix)
5+
refs = set([r.strip() for r in s.strip("()").split(",")])
6+
refs.discard("HEAD") ; refs.discard("master")
7+
for r in reversed(sorted(refs)):
8+
if r.startswith(tag_prefix):
9+
return r[len(tag_prefix):]
10+
return "unknown"
11+

src/git/parse.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@
88
# this string will be replaced by git during git-archive
99
verstr = "%(DOLLAR)sFormat:%%d%(DOLLAR)s"
1010

11+
#### SUBPROCESS_HELPER
1112
#### VERSION_FROM_CHECKOUT
12-
13-
def parse(s):
14-
tag_prefix = "%(TAG_PREFIX)s"
15-
if "%(DOLLAR)sFormat" in s: # unexpanded
16-
return version_from_vcs(tag_prefix)
17-
refs = set([r.strip() for r in s.strip("()").split(",")])
18-
refs.discard("HEAD") ; refs.discard("master")
19-
for r in reversed(sorted(refs)):
20-
if r.startswith(tag_prefix):
21-
return r[len(tag_prefix):]
22-
return "unknown"
23-
24-
__version__ = parse(verstr.strip())
13+
#### VERSION_FROM_VARIABLE
14+
tag_prefix = "%(TAG_PREFIX)s"
15+
__version__ = version_from_expanded_variable(verstr.strip(), tag_prefix)
2516
#### END
2617

src/trailer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ def write_to_version_file(filename, ver):
3333
f.close()
3434
print "set %s to '%s'" % (filename, ver)
3535

36+
def get_expanded_variable(versionfile_source):
37+
# the code embedded in _version.py can just fetch the value of this
38+
# variable. We don't want to import _version.py, so we do it with a
39+
# regexp instead
40+
try:
41+
for line in open(versionfile_source,"r").readlines():
42+
if line.strip().startswith("verstr ="):
43+
mo = re.search(r'=\s*"(.*)"', line)
44+
if mo:
45+
return mo.group(1)
46+
except EnvironmentError:
47+
pass
48+
return None
49+
3650
def get_best_version(versionfile, tag_prefix, parentdir_prefix,
3751
default=None, verbose=False):
3852
# extract version from first of: 'git describe', _version.py, parentdir.
@@ -45,6 +59,13 @@ def get_best_version(versionfile, tag_prefix, parentdir_prefix,
4559
if verbose: print "got version from git"
4660
return ver
4761

62+
verstr = get_expanded_variable(versionfile_source)
63+
if verstr:
64+
ver = version_from_expanded_variable(verstr, tag_prefix)
65+
if ver is not None:
66+
if verbose: print "got version from expanded variable"
67+
return ver
68+
4869
ver = version_from_file(versionfile)
4970
if ver is not None:
5071
if verbose: print "got version from file %s" % versionfile

0 commit comments

Comments
 (0)