From 9e0ff3a550f69dfec3cd04bacef885d24819f4a4 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Tue, 31 May 2016 08:08:03 -0400 Subject: [PATCH] Check conflicts script Use pkg_resources.require to report conflicts to ensure co-installability. Co-Authored-By: Igor Yozhikov Change-Id: I7443496b6a06d02bb9cc9457b729dea71451f44a --- .../cmds/check_conflicts.py | 58 +++++++++++++++++++ setup.cfg | 1 + tox.ini | 1 + 3 files changed, 60 insertions(+) create mode 100644 openstack_requirements/cmds/check_conflicts.py diff --git a/openstack_requirements/cmds/check_conflicts.py b/openstack_requirements/cmds/check_conflicts.py new file mode 100644 index 0000000000..22ea0c89cc --- /dev/null +++ b/openstack_requirements/cmds/check_conflicts.py @@ -0,0 +1,58 @@ +# 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. + +"""Apply validation rules to the various requirements lists. + +""" + +import argparse +import sys +import traceback + +import pkg_resources + +from openstack_requirements import requirement + + +def read_requirements_file(filename): + with open(filename, 'rt') as f: + body = f.read() + return requirement.parse(body) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + 'upper_constraints', + default='upper-constraints.txt', + help='path to the upper-constraints.txt file', + ) + args = parser.parse_args() + + error_count = 0 + + print('\nChecking %s' % args.upper_constraints) + upper_constraints = read_requirements_file(args.upper_constraints) + for name, spec_list in upper_constraints.items(): + try: + if name: + print('Checking conflicts for %s' % name) + pyver = "python_version=='%s.%s'" % (sys.version_info[0], + sys.version_info[1]) + for req, original_line in spec_list: + if req.markers in ["", pyver]: + pkg_resources.require(name) + except pkg_resources.ContextualVersionConflict: + traceback.print_exc(file=sys.stdout) + error_count += 1 + + return 1 if error_count else 0 diff --git a/setup.cfg b/setup.cfg index 9533c88c31..e1c809662b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ source-dir = doc/source console_scripts = edit-constraints = openstack_requirements.cmds.edit_constraint:main generate-constraints = openstack_requirements.cmds.generate:main + check-conflicts = openstack_requirements.cmds.check_conflicts:main update-requirements = openstack_requirements.cmds.update:main validate-constraints = openstack_requirements.cmds.validate:main validate-projects = openstack_requirements.cmds.validate_projects:main diff --git a/tox.ini b/tox.ini index ffb646588c..4a57dd1723 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,7 @@ commands = [testenv:py27-with-upper-constraints] deps = -r{toxinidir}/upper-constraints.txt +commands = check-conflicts {toxinidir}/upper-constraints.txt [testenv:venv] commands = {posargs}