2dbf39295c
Having the data validation happening inside the unit tests makes understanding requirement update failures confusing because the output is hard to read and does not explain what the error actually is. Move the checks to their own command and set up a tox env to run it. A separate patch in project-config will add a new job for the repository. Address the dedent comment from https://review.openstack.org/#/c/204181/3/openstack_requirements/tests/test_requirement.py,cm Add a test to ensure that all items in global-requirements.txt are also listed in either upper-constraints.txt or blacklist.txt. Ignore a few items that we don't know how to constrain yet. Add a test to ensure that items in blacklist.txt are not in upper-constraints.txt. Change-Id: Icb717b0f36afb6ea29f50bc6935917dddf47fd4c
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
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
|
|
#
|
|
# 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
|
|
|
|
from openstack_requirements import constraints
|
|
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(
|
|
'global_requirements',
|
|
default='global-requirements.txt',
|
|
help='path to the global-requirements.txt file',
|
|
)
|
|
parser.add_argument(
|
|
'upper_constraints',
|
|
default='upper-constraints.txt',
|
|
help='path to the upper-constraints.txt file',
|
|
)
|
|
parser.add_argument(
|
|
'blacklist',
|
|
default='blacklist.txt',
|
|
help='path to the blacklist.txt file',
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
error_count = 0
|
|
|
|
# Check the format of the constraints file.
|
|
print('\nChecking %s' % args.upper_constraints)
|
|
upper_constraints = read_requirements_file(args.upper_constraints)
|
|
for msg in constraints.check_format(upper_constraints):
|
|
print(msg)
|
|
error_count += 1
|
|
|
|
# Check that the constraints and requirements are compatible.
|
|
print('\nChecking %s' % args.global_requirements)
|
|
global_reqs = read_requirements_file(args.global_requirements)
|
|
for msg in constraints.check_compatible(global_reqs, upper_constraints):
|
|
print(msg)
|
|
error_count += 1
|
|
|
|
# Check that all of the items in the global-requirements list
|
|
# appear in exactly one of the constraints file or the blacklist.
|
|
print('\nChecking %s' % args.blacklist)
|
|
blacklist = read_requirements_file(args.blacklist)
|
|
for msg in constraints.check_blacklist_coverage(global_reqs,
|
|
upper_constraints,
|
|
blacklist,
|
|
'upper-constraints.txt'):
|
|
print(msg)
|
|
error_count += 1
|
|
|
|
return 1 if error_count else 0
|