summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Warner <warner@lothar.com>2010-06-05 13:18:58 -0700
committerBrian Warner <warner@lothar.com>2010-06-05 13:18:58 -0700
commit0ed702a9d4057ecf33eea969b8cf280eaccd89a1 (patch)
treed17f3c5f297a99f609ad512c1164f16c89eb13da
parent6fe96c0f9186697af391487b25c4c3430e6dca24 (diff)
downloadecdsa-0ed702a9d4057ecf33eea969b8cf280eaccd89a1.tar.gz
fix version-setting code, tolerate lack of git or .git/ (work from sdists)
-rwxr-xr-xsetup.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/setup.py b/setup.py
index 5506d8b..2bf775a 100755
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import re, sys, subprocess
+import os, sys, subprocess, re
from distutils.core import setup, Command
from distutils.command.sdist import sdist as _sdist
@@ -39,19 +39,26 @@ __version__ = '%s'
"""
def update_version_py():
+ if not os.path.isdir(".git"):
+ print "This does not appear to be a Git repository."
+ return
try:
- ver = subprocess.Popen(["git", "describe", "--dirty", "--always"],
- stdout=subprocess.PIPE,
- ).communicate()[0]
- # we use tags like "python-ecdsa-0.5", so strip the prefix
- assert ver.startswith("python-ecdsa-")
- ver = ver[len("python-ecdsa-"):].strip()
- f = open("ecdsa/_version.py", "w")
- f.write(VERSION_PY % ver)
- f.close()
- print "set ecdsa/_version.py to '%s'" % ver
- except IndexError:
+ p = subprocess.Popen(["git", "describe", "--dirty", "--always"],
+ stdout=subprocess.PIPE)
+ except EnvironmentError:
+ print "unable to run git, leaving ecdsa/_version.py alone"
+ return
+ stdout = p.communicate()[0]
+ if p.returncode != 0:
print "unable to run git, leaving ecdsa/_version.py alone"
+ return
+ # we use tags like "python-ecdsa-0.5", so strip the prefix
+ assert stdout.startswith("python-ecdsa-")
+ ver = stdout[len("python-ecdsa-"):].strip()
+ f = open("ecdsa/_version.py", "w")
+ f.write(VERSION_PY % ver)
+ f.close()
+ print "set ecdsa/_version.py to '%s'" % ver
def get_version():
try:
@@ -75,10 +82,14 @@ class Version(Command):
pass
def run(self):
update_version_py()
+ print "Version is now", get_version()
class sdist(_sdist):
def run(self):
update_version_py()
+ # unless we update this, the sdist command will keep using the old
+ # version
+ self.distribution.metadata.version = get_version()
return _sdist.run(self)
setup(name="ecdsa",