def main(): args = grab_args() branch = args.branch os.chdir(args.src_dir) reqdir = args.reqs print(sys.version_info) if reqdir is None: if args.local: print('selecting default requirements directory for local mode') reqdir = os.path.dirname( os.path.dirname(os.path.dirname(sys.argv[0]))) else: print('selecting default requirements directory for normal mode') reqdir = _DEFAULT_REQS_DIR print('Branch: {}'.format(branch)) print('Source: {}'.format(args.src_dir)) print('Requirements: {}'.format(reqdir)) sha, _ = run_command('git log -n 1 --format=%H') print('Patch under test: {}'.format(sha)) # build a list of requirements from the global list in the # openstack/requirements project so we can match them to the changes with tempdir() as reqroot: install_and_load_requirements(reqroot, reqdir) with open(reqdir + '/global-requirements.txt', 'rt') as f: global_reqs = check.get_global_reqs(f.read()) blacklist = requirement.parse( open(reqdir + '/blacklist.txt', 'rt').read()) cwd = os.getcwd() # build a list of requirements in the proposed change, # and check them for style violations while doing so head_proj = project.read(cwd) head_reqs = check.RequirementsList(sha, head_proj) # Don't apply strict parsing rules to stable branches. # Reasoning is: # - devstack etc protect us from functional issues # - we're backporting to stable, so guarding against # aesthetics and DRY concerns is not our business anymore # - if in future we have other not-functional linty style # things to add, we don't want them to affect stable # either. head_strict = not branch.startswith('stable/') head_reqs.process(strict=head_strict) failed = check.validate(head_reqs, blacklist, global_reqs) failed = (check.validate_lower_constraints( head_reqs, head_proj['lower-constraints.txt'], blacklist, ) or failed) # report the results if failed or head_reqs.failed: print("*** Incompatible requirement found!") print("*** See http://docs.openstack.org/developer/requirements") sys.exit(1) print("Updated requirements match openstack/requirements.")
def main(): args = grab_args() branch = args.branch os.chdir(args.src_dir) reqdir = args.reqs if reqdir is None: if args.local: reqdir = os.path.dirname( os.path.dirname( os.path.dirname(sys.argv[0]))) else: reqdir = _DEFAULT_REQS_DIR # build a list of requirements from the global list in the # openstack/requirements project so we can match them to the changes with tempdir() as reqroot: install_and_load_requirements(reqroot, reqdir) with open(reqdir + '/global-requirements.txt', 'rt') as f: global_reqs = check.get_global_reqs(f.read()) blacklist = requirement.parse( open(reqdir + '/blacklist.txt', 'rt').read()) cwd = os.getcwd() # build a list of requirements in the proposed change, # and check them for style violations while doing so head_proj = project.read(cwd) head_reqs = check.RequirementsList('HEAD', head_proj) # Don't apply strict parsing rules to stable branches. # Reasoning is: # - devstack etc protect us from functional issues # - we're backporting to stable, so guarding against # aesthetics and DRY concerns is not our business anymore # - if in future we have other not-functional linty style # things to add, we don't want them to affect stable # either. head_strict = not branch.startswith('stable/') head_reqs.process(strict=head_strict) if not args.local: # build a list of requirements already in the target branch, # so that we can create a diff and identify what's being changed run_command("git checkout HEAD^1") branch_proj = project.read(cwd) # switch back to the proposed change now run_command("git checkout %s" % branch) else: branch_proj = {'root': cwd} branch_reqs = check.RequirementsList(branch, branch_proj) # Don't error on the target branch being broken. branch_reqs.process(strict=False) failed = check.validate(head_reqs, branch_reqs, blacklist, global_reqs) failed = ( check.validate_lower_constraints( head_reqs, head_proj['lower-constraints.txt'], blacklist, ) or failed ) # report the results if failed or head_reqs.failed or branch_reqs.failed: print("*** Incompatible requirement found!") print("*** See http://docs.openstack.org/developer/requirements") sys.exit(1) print("Updated requirements match openstack/requirements.")