Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: update versioning/release #265

Merged
merged 3 commits into from Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 31 additions & 20 deletions setup.py
Expand Up @@ -54,18 +54,20 @@
MAJOR = 1
MINOR = 0
PATCH = 0
ISRELEASED = True
VERSION = '%d.%d.%d' % (MAJOR, MINOR, PATCH)


# Return the git revision as a string
def git_version():
try:
rev = check_output(['git', 'rev-parse', 'HEAD'])
GIT_REVISION = rev.strip().decode('ascii')
git_rev = check_output(['git', 'describe', '--tags', '--long'])
git_hash = check_output(['git', 'rev-parse', 'HEAD'])
GIT_REVISION = git_rev.strip().decode('ascii')
GIT_HASH = git_hash.strip().decode('ascii')
except (CalledProcessError, OSError):
GIT_REVISION = 'unknown'
return GIT_REVISION
GIT_HASH = 'unknown'
return GIT_REVISION, GIT_HASH


# This is a bit hackish: we are setting a global variable so that the main
Expand All @@ -77,39 +79,48 @@ def git_version():
def write_version_py(filename='wradlib/version.py'):
cnt = """
# THIS FILE IS GENERATED FROM WRADLIB SETUP.PY
short_version = '%(version)s'
short_version = '%(short_version)s'
version = '%(version)s'
full_version = '%(full_version)s'
git_revision = '%(git_revision)s'
release = %(isrelease)s
if not release:
version = full_version
"""
# Adding the git rev number needs to be done inside write_version_py(),
# otherwise the import of wradlib.version messes up the build under
# Python 3.
FULLVERSION = VERSION
SHORT_VERSION = VERSION
FULL_VERSION = VERSION
GIT_REVISION = VERSION + '-unknown'
GIT_HASH = 'unknown'
ISRELEASED = "'unknown'"

if os.path.exists('.git'):
GIT_REVISION = git_version()
GIT_REVISION, GIT_HASH = git_version()
elif os.path.exists('wradlib/version.py'):
# must be a source distribution, use existing version file
try:
from wradlib.version import git_revision as GIT_REVISION
from wradlib.version import full_version as GIT_REVISION
from wradlib.version import git_revision as GIT_HASH
except ImportError:
raise ImportError("Unable to import git_revision. Try removing "
"wradlib/version.py and the build directory "
"before building.")
else:
GIT_REVISION = "Unknown"
raise ImportError('Unable to import git_revision. Try removing '
'wradlib/version.py and the build directory '
'before building.')

if not ISRELEASED:
FULLVERSION += '.dev+' + GIT_REVISION[:7]
# get commit count, 0 means tagged commit -> release
try:
ISRELEASED = not bool(int(GIT_REVISION.split('-')[1]))
if not ISRELEASED:
FULL_VERSION = GIT_REVISION
except ValueError:
pass

print(VERSION, FULL_VERSION, GIT_REVISION, GIT_HASH, ISRELEASED)
a = open(filename, 'w')
try:
a.write(cnt % {'version': VERSION,
'full_version': FULLVERSION,
'git_revision': GIT_REVISION,
a.write(cnt % {'short_version': SHORT_VERSION,
'version': FULL_VERSION,
'full_version': GIT_REVISION,
'git_revision': GIT_HASH,
'isrelease': str(ISRELEASED)})
finally:
a.close()
Expand Down