From 6ee15b0c7f1627350477ebf67e597b4acf17e80a Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 16 Jun 2016 12:33:50 +1000 Subject: [PATCH] Add Support for validating 4 digit verion strings The xstatic packages have a 4 digit verion number 3-digit semver as supplied by upstream and a local build number. PBR only supports 3 digit semver. To work with that create the concpet of a release type that can have slightly different validation rules. In this case use the 'packaging' library. This will allow the horizon team to use the standard release process. For refernce see: https://blueprints.launchpad.net/horizon/+spec/xstatic-release-process Change-Id: Ie0f33097c31ee4006ec58147b35731913f7b6f4b --- README.rst | 12 ++++++++++ openstack_releases/cmds/validate.py | 6 ++++- openstack_releases/versionutils.py | 34 ++++++++++++++++++++++++----- requirements.txt | 1 + 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 86ed317228..665647757c 100644 --- a/README.rst +++ b/README.rst @@ -232,6 +232,18 @@ The top level of a deliverable file is a mapping with keys: This repository is no longer used, but was present in old versions of a deliverable. +``release-type`` + This (optional) key sets the level of validation for the versions numbers. + + ``std`` + Default: Enforces 3 digit semver version numbers in releases and allows + for common alpha, beta and dev releases. This should be appropriate for + most OpenStack release requirements. + + ``xstatic`` + Allows a more flexible versioning in line with xstatic package guidelines + and requirements. + ``releases`` A list of the releases for the deliverable. diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 590b23e98b..1f1693cddb 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -129,6 +129,9 @@ def main(): warnings.append('Team %r in %s not in governance data' % (deliverable_info['team'], filename)) + # Look for the release-type + release_type = deliverable_info.get('release-type', 'std') + # Look for an email address to receive release announcements try: announce_to = deliverable_info['send-announcements-to'] @@ -262,7 +265,8 @@ def main(): else: for e in versionutils.validate_version( - release['version']): + release['version'], + release_type=release_type): msg = ('could not validate version %r ' 'for %s: %s' % (release['version'], filename, e)) diff --git a/openstack_releases/versionutils.py b/openstack_releases/versionutils.py index 5c705d87a5..21b0154c2d 100644 --- a/openstack_releases/versionutils.py +++ b/openstack_releases/versionutils.py @@ -14,23 +14,45 @@ from __future__ import unicode_literals +import packaging.version import pbr.version +# The keys for this dict are the valid release types for OpenStack releases. +# The values are a three-tuple that contains: +# 1. constructor: The function used to convert the version string in to a +# *Verion object. +# 2. exception: The excpetion raised by the constructor iff version string is invalid +# in some way. +# 3. canonicalise: The function used to canonicalise the *Version object. +# Used to verify that the version string is already in the +# canonical form +_VALIDATORS = {'std': (pbr.version.SemanticVersion.from_pip_string, + ValueError, + lambda x: x.release_string()), + 'xstatic': (packaging.version.Version, + packaging.version.InvalidVersion, + lambda x: str(x)), + } -def validate_version(versionstr): + +def validate_version(versionstr, release_type='std'): """Given a version string, yield error messages if it is "bad" Apply our SemVer rules to version strings and report all issues. """ - # Apply pbr rules + if release_type not in _VALIDATORS: + yield 'Release Type %s not valid using \'std\'' % release_type + release_type = 'std' + + constructor, exception, canonicalise = _VALIDATORS[release_type] try: - semver = pbr.version.SemanticVersion.from_pip_string(versionstr) - except ValueError as err: + semver = constructor(versionstr) + except exception as err: yield 'Invalid version: %s' % err else: - # Make sure pbr didn't change the version to meet the canonical form. - canonical = semver.release_string() + # Make sure we didn't change the version to meet the canonical form. + canonical = canonicalise(semver) if canonical != versionstr: yield 'Version %r does not match canonical form %r' % \ (versionstr, canonical) diff --git a/requirements.txt b/requirements.txt index 6337fcb265..6d7c419754 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ zuul yamlordereddictloader prompt_toolkit tqdm +packaging>=15.2