Permalink
Browse files

improving version.py -- more robust

  • Loading branch information...
1 parent 06322c1 commit 2bba9d4fd341341406e4ce17888a3a168d99bcfe @johnrfrank johnrfrank committed Feb 23, 2014
Showing with 65 additions and 28 deletions.
  1. +4 −10 Makefile
  2. +9 −3 setup.py
  3. +52 −15 version.py
View
@@ -1,23 +1,17 @@
+.PHONY : clean build install test register check
clean:
+ python setup.py clean --all
rm -rf build dist src/*.egg-info/
-.PHONY : build
build: clean
python setup.py build
-build_eggs: build
- python setup.py bdist_egg
-
-build_packages: build_eggs
- python setup.py bdist_rpm
-
install: build
- python setup.py clean --all
- python setup.py install
+ pip install .
test:
- python runtests.py src
+ run_tests.sh
register:
python setup.py sdist bdist_egg upload -r pypi
View
@@ -3,6 +3,7 @@
#
import os
+import sys
try:
import subprocess
@@ -96,9 +97,11 @@ def run(self):
"""
+VERSION, HASH = version.get_git_version()
+
setup(
name = 'pyaccumulo',
- version = version.get_git_version(),
+ version = VERSION,
author = 'Jason Trost',
author_email = 'jason.trost AT gmail.com',
maintainer = 'Jason Trost',
@@ -113,7 +116,10 @@ def run(self):
],
install_requires = ['thrift'],
py_modules=['ez_setup'],
- cmdclass={"doc": doc, "rpm": rpm},
+ cmdclass=dict(
+ doc = doc,
+ rpm = rpm,
+ ),
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
@@ -126,5 +132,5 @@ def run(self):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Topic :: Software Development :: Libraries :: Python Modules'
- ]
+ ],
)
View
@@ -32,20 +32,55 @@
# include RELEASE-VERSION
__all__ = ("get_git_version")
-
+
+import os
+import sys
+import traceback
from subprocess import Popen, PIPE
def call_git_describe(abbrev=4):
+ line = None
+ p = None
try:
p = Popen(['git', 'describe', '--abbrev=%d' % abbrev],
stdout=PIPE, stderr=PIPE)
p.stderr.close()
- line = p.stdout.readlines()[0]
- return line.strip()
-
- except:
- return None
+ describe_line = p.stdout.readlines()[0].strip()
+
+ p = Popen(['git', 'rev-parse', 'HEAD'],
+ stdout=PIPE, stderr=PIPE)
+ p.stderr.close()
+ source_hash = p.stdout.readlines()[0].strip()
+ source_hash = source_hash[:abbrev]
+
+ parts = describe_line.split('-')
+ if len(parts) == 1:
+ version = parts[0]
+
+ else:
+ ver, rel, source_hash = parts
+ ver_x, ver_y, ver_z = ver.split('.')
+ ## go to the next z-increment or "patch" release
+ ver_z = int(ver_z) + 1
+ version = '%s.%s.%d.dev%s' % (ver_x, ver_y, ver_z, rel)
+
+ return version, source_hash
+
+ except Exception, exc:
+ '''
+ sys.stderr.write('line: %r\n' % line)
+ sys.stderr.write(traceback.format_exc(exc))
+ try:
+ sys.stderr.write('p.stderr.read()=%s\n' % p.stderr.read())
+ except Exception, exc:
+ sys.stderr.write(traceback.format_exc(exc))
+ try:
+ sys.stderr.write('os.getcwd()=%s\n' % os.getcwd())
+ except Exception, exc:
+ sys.stderr.write(traceback.format_exc(exc))
+ '''
+ return None, None
def read_release_version():
@@ -54,51 +89,53 @@ def read_release_version():
try:
version = f.readlines()[0]
- return version.strip()
+ return version.strip().split(',')
finally:
f.close()
except:
- return None
+ return None, None
-def write_release_version(version):
+def write_release_version(version, source_hash):
f = open("RELEASE-VERSION", "w")
- f.write("%s\n" % version)
+ f.write("%s,%s\n" % (version, source_hash))
f.close()
def get_git_version(abbrev=4):
# Read in the version that's currently in RELEASE-VERSION.
- release_version = read_release_version()
+ release_version, release_source_hash = read_release_version()
# First try to get the current version using “git describe”.
- version = call_git_describe(abbrev)
+ version, source_hash = call_git_describe(abbrev)
# If that doesn't work, fall back on the value that's in
# RELEASE-VERSION.
if version is None:
version = release_version
+ source_hash = release_source_hash
# If we still don't have anything, that's an error.
if version is None:
# raise ValueError("Cannot find the version number!")
version = '0.1.0'
+ source_hash = ''
# If the current version is different from what's in the
# RELEASE-VERSION file, update the file to be current.
- if version != release_version:
- write_release_version(version)
+ if version != release_version or source_hash != release_source_hash:
+ write_release_version(version, source_hash)
# Finally, return the current version.
- return version
+ return version, source_hash
if __name__ == "__main__":

0 comments on commit 2bba9d4

Please sign in to comment.