Replace hard-coded setup version setting
The pbr library is used to generate version numbers for Barbican, and should typically do so by forming the version using the latest tag (such as '2014.2.b2') as a base version, and then appending git commit info if after the tag. However, if setup.cfg has a 'version' property set, this overrides the base version essentially 'hard coding' it. This CR removes that override and instead lets the versionbuild.py script, used during deployment processing, generate this version override based on the current PBR generated version with a timestamp injected into it. Closes-Bug: #1349238 Change-Id: I32cf9b32265569c1e2ae182efa32a0d1449de15c
This commit is contained in:
parent
081aa6b4d2
commit
f7d240801c
@ -33,6 +33,8 @@ import os
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import mktime
|
from time import mktime
|
||||||
|
|
||||||
|
import pbr.version
|
||||||
|
|
||||||
|
|
||||||
# Determine version of this application.
|
# Determine version of this application.
|
||||||
SETUP_FILE = 'setup.cfg'
|
SETUP_FILE = 'setup.cfg'
|
||||||
@ -54,29 +56,74 @@ def get_patch():
|
|||||||
|
|
||||||
|
|
||||||
def update_versionfile(patch):
|
def update_versionfile(patch):
|
||||||
"""Update the 'patch' version information per the provided patch."""
|
"""Update the version information in setup.cfg per the provided patch.
|
||||||
|
|
||||||
|
PBR will generate a version stamp per the docstring of _get_pbr_version()
|
||||||
|
below, which then stamps the version on source tarballs used for
|
||||||
|
packaging. This version stamp is not packaging friendly as it is not
|
||||||
|
monotonically increasing alphabetically. If a 'version' attribute is added
|
||||||
|
to setup.cfg, PBR will override the output major, minor and build
|
||||||
|
versions of the stamped version. By injecting a patch into this version
|
||||||
|
structure per this function, the desired monotonic version number can
|
||||||
|
be created.
|
||||||
|
"""
|
||||||
temp_name = VERSIONFILE + '~'
|
temp_name = VERSIONFILE + '~'
|
||||||
file_new = open(temp_name, 'w')
|
with open(VERSIONFILE, 'r') as file_old:
|
||||||
try:
|
with open(temp_name, 'w') as file_new:
|
||||||
with open(VERSIONFILE, 'r') as file_old:
|
|
||||||
for line in file_old:
|
for line in file_old:
|
||||||
if line.startswith('version ='):
|
if line.startswith('[metadata]'):
|
||||||
subs = line.split('.')
|
file_new.write(line)
|
||||||
if len(subs) <= 2:
|
|
||||||
file_new.write(''.join([line[:-1], '.',
|
# Add a 'version =' line to override the version info.
|
||||||
str(patch), '\n']))
|
base, extension = _get_pbr_version()
|
||||||
|
if extension:
|
||||||
|
file_new.write('version = '
|
||||||
|
'{0}.{1}.{2}\n'.format(base, patch,
|
||||||
|
extension))
|
||||||
else:
|
else:
|
||||||
subs[2] = str(patch)
|
file_new.write('version = {0}.{1}\n'.format(base, patch))
|
||||||
file_new.write('.'.join(subs))
|
|
||||||
if len(subs) == 3:
|
elif line.startswith('version'):
|
||||||
file_new.write('\n')
|
raise ValueError("The file 'setup.cfg' must not already "
|
||||||
|
"contain a 'version =' line.")
|
||||||
else:
|
else:
|
||||||
file_new.write(line)
|
file_new.write(line)
|
||||||
finally:
|
|
||||||
file_new.close()
|
# Replace the original setup.cfg with the modified one.
|
||||||
os.rename(temp_name, VERSIONFILE)
|
os.rename(temp_name, VERSIONFILE)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_pbr_version():
|
||||||
|
"""Returns the version stamp from PBR.
|
||||||
|
|
||||||
|
PBR versions are either of the form yyyy.s.bm.devx.gitsha (for milestone
|
||||||
|
releases) or yyyy.s.devx.gitsha for series releases. This function returns
|
||||||
|
the base part (yyyy.s) and the optional extension without the devx.gitsha
|
||||||
|
portions (so either None or bm). The devx.gitsha portion should not be
|
||||||
|
returned, as it will be supplied by PBR as part of its version generation
|
||||||
|
process when 'python setup.py sdist' is later invoked.
|
||||||
|
"""
|
||||||
|
version_info = pbr.version.VersionInfo('barbican')
|
||||||
|
base = version_info.version_string()
|
||||||
|
full = version_info.release_string()
|
||||||
|
if base != full:
|
||||||
|
extension = _trim_base_from_version(full, base)
|
||||||
|
if _is_milestone_release(extension):
|
||||||
|
return base, extension.split('.')[0]
|
||||||
|
|
||||||
|
return base, None
|
||||||
|
|
||||||
|
|
||||||
|
def _trim_base_from_version(full_version, base_version):
|
||||||
|
"""Removes the base version information from the full version."""
|
||||||
|
return full_version[len(base_version) + 1:]
|
||||||
|
|
||||||
|
|
||||||
|
def _is_milestone_release(extension):
|
||||||
|
"""Tests if extension corresponds to an OpenStack milestone release."""
|
||||||
|
return extension.startswith('b')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
patch = get_patch()
|
patch = get_patch()
|
||||||
print 'patch: ', patch
|
|
||||||
update_versionfile(patch)
|
update_versionfile(patch)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = barbican
|
name = barbican
|
||||||
version = 2014.1
|
|
||||||
description = Service for storing sensitive client information for OpenStack
|
description = Service for storing sensitive client information for OpenStack
|
||||||
description-file =
|
description-file =
|
||||||
README.md
|
README.md
|
||||||
|
Loading…
Reference in New Issue
Block a user