move sanity-check-version into releasetools package

Change-Id: If9e75653e5b62d3105d94951c53d90101f63b69f
This commit is contained in:
Doug Hellmann 2015-07-15 21:42:22 +00:00
parent 57d8279a00
commit f321702044
7 changed files with 55 additions and 47 deletions

View File

@ -1,4 +1,4 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -s ./tests . $LISTOPT $IDOPTION
test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -97,7 +97,7 @@ fi
cd $REPODIR
title "Sanity checking $VERSION"
if ! $TOOLSDIR/sanity_check_version.py $VERSION $(git tag)
if ! sanity-check-version $VERSION $(git tag)
then
read -s -p "Press Ctrl-C to cancel or Return to continue..."
fi

View File

@ -0,0 +1,45 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Check a proposed new release version against other existing versions.
"""
from __future__ import print_function
import argparse
from releasetools import semver
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'new_version',
help='the new version being proposed',
)
parser.add_argument(
'existing_versions',
nargs='*',
help='the existing versions in the repository',
)
args = parser.parse_args()
new_version = semver.parse_version(args.new_version)
if len(new_version) < 3:
new_version = new_version + [0]
existing_versions = sorted([
semver.parse_version(v)
for v in args.existing_versions
])
msgs = semver.sanity_check_version(new_version, existing_versions)
for msg in msgs:
print(msg)
return 1 if msgs else 0

41
sanity_check_version.py → releasetools/semver.py Executable file → Normal file
View File

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@ -11,13 +9,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Check a proposed new release version against other existing versions.
"""
from __future__ import print_function
import argparse
import sys
def try_int(val):
@ -38,33 +29,7 @@ def format_version(v):
return '.'.join(str(p) for p in v)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'new_version',
help='the new version being proposed',
)
parser.add_argument(
'existing_versions',
nargs='*',
help='the existing versions in the repository',
)
args = parser.parse_args()
new_version = parse_version(args.new_version)
if len(new_version) < 3:
new_version = new_version + [0]
existing_versions = sorted([
parse_version(v)
for v in args.existing_versions
])
msgs = apply_rules(new_version, existing_versions)
for msg in msgs:
print(msg)
return 1 if msgs else 0
def apply_rules(new_version, existing_versions):
def sanity_check_version(new_version, existing_versions):
warnings = []
if not existing_versions:
if new_version[0] != 0:
@ -124,7 +89,3 @@ def apply_rules(new_version, existing_versions):
(format_version(new_version), format_version(latest_version))
)
return warnings
if __name__ == '__main__':
sys.exit(main())

View File

@ -15,7 +15,7 @@
from oslotest import base
import testscenarios
import sanity_check_version as scv
from releasetools import semver
load_tests = testscenarios.load_tests_apply_scenarios
@ -24,13 +24,13 @@ load_tests = testscenarios.load_tests_apply_scenarios
class ParseVersionTest(base.BaseTestCase):
def test_all_ints(self):
self.assertEqual([1, 0, 1], scv.parse_version('1.0.1'))
self.assertEqual([1, 0, 1], semver.parse_version('1.0.1'))
def test_not_int(self):
self.assertEqual([1, 'a', 1], scv.parse_version('1.a.1'))
self.assertEqual([1, 'a', 1], semver.parse_version('1.a.1'))
def test_short(self):
self.assertEqual([1, 1, 0], scv.parse_version('1.1'))
self.assertEqual([1, 1, 0], semver.parse_version('1.1'))
class RulesTest(base.BaseTestCase):
@ -102,5 +102,6 @@ class RulesTest(base.BaseTestCase):
]
def test(self):
msgs = scv.apply_rules(self.new_version, self.existing_versions)
msgs = semver.sanity_check_version(self.new_version,
self.existing_versions)
self.assertEqual(self.expected, msgs)

View File

@ -27,3 +27,4 @@ console_scripts =
release-notes = releasetools.cmds.release_notes:main
list-repos = releasetools.cmds.list_repos:main
get-repo-owner = releasetools.cmds.get_repo_owner:main
sanity-check-version = releasetools.cmds.sanity_check_version:main