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
This commit is contained in:
parent
c3148de50f
commit
6ee15b0c7f
12
README.rst
12
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.
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
@ -6,3 +6,4 @@ zuul
|
||||
yamlordereddictloader
|
||||
prompt_toolkit
|
||||
tqdm
|
||||
packaging>=15.2
|
||||
|
Loading…
Reference in New Issue
Block a user