Skip to content

Commit

Permalink
Fix: Version identification for tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
frosch123 committed Apr 11, 2015
1 parent c7501c3 commit 00d9a56
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions nml/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,33 @@ def get_hg_version():
path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
version = ''
if os.path.isdir(os.path.join(path,'.hg')):
# Define the next version released from this branch
next_release_version = '0.4.0'
# we want to return to where we were. So save the old path
try:
version_list = get_child_output(['hg', '-R', path, 'id', '-n', '-t', '-i'])
except OSError as e:
print("Mercurial checkout found but cannot determine its version. Error({0}): {1}".format(e.errno, e.strerror))
return version

if version_list[1].endswith('+'):
modified = 'M'
else:
modified = ''
hash = version_list[0].rstrip('+')

# Get the date of the commit of the current NML version in days since January 1st 2000
ctimes = get_child_output(["hg", "-R", path, "parent", "--template='{date|hgdate} {date|shortdate}\n'"])
ctime = (int((ctimes[0].split("'"))[1]) - 946684800) // (60 * 60 * 24)
revision = str(ctime) # version_list[1].rstrip('+')

# Combine the version string
version += "{}.r{}{}:{} from {}".format(next_release_version, revision, modified, hash, ctimes[2].split("'", 1)[0])

# Test whether we have a tag (=release version) and add it, if found
if len(version_list) > 2 and version_list[2] != 'tip' and modified == '':
version += ' (Released as {})'.format(version_list[2])
# Tagged release
version = version_list[2]
else:
# Branch or modified version
hash = version_list[0].rstrip('+')

# Get the date of the commit of the current NML version in days since January 1st 2000
ctimes = get_child_output(["hg", "-R", path, "parent", "--template='{date|hgdate} {date|shortdate}\n'"])
ctime = (int((ctimes[0].split("'"))[1]) - 946684800) // (60 * 60 * 24)
cversion = str(ctime)

# Combine the version string
version = "v{}{}:{} from {}".format(cversion, modified, hash, ctimes[2].split("'", 1)[0])
return version

def get_lib_versions():
Expand Down Expand Up @@ -116,6 +118,6 @@ def get_and_write_version():
f.write('# this file is autogenerated by setup.py\n')
f.write('version = "{}"\n'.format(version))
f.close()
return get_nml_version().split()[0]
return version.split()[0]
except IOError:
print("Version file NOT written")

0 comments on commit 00d9a56

Please sign in to comment.