From 4f6629021e085e1c2c477deb1047e90a7ecd4c86 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 14 Jan 2020 09:39:30 +1100 Subject: [PATCH] Update hacking, fix errors/warnings This version of hacking doesn't understand f-strings as usable in Python 3. Update to the latest and fix current issues, which are all just formatting fixes. Change-Id: I0a7d6f93f07477b6dd29ab143130dd9064c250be --- .../files/release-tools/launchpad_add_comment.py | 2 +- .../files/release-tools/process_release_requests.py | 10 +++++----- tools/batch_update_projects.py | 4 ++-- tools/check_gerrit_projects_changed.py | 4 ++-- tools/check_irc_access.py | 1 + tools/ci2project.py | 4 ++-- tools/fix-neutron-stadium.py | 5 +++-- tools/irc_tests.py | 1 + tools/normalize_acl.py | 6 +++--- tools/normalize_channels_yaml.py | 1 + tools/normalize_projects_yaml.py | 5 +++-- tox.ini | 2 +- 12 files changed, 25 insertions(+), 20 deletions(-) diff --git a/roles/copy-release-tools-scripts/files/release-tools/launchpad_add_comment.py b/roles/copy-release-tools-scripts/files/release-tools/launchpad_add_comment.py index e179c1d13d..3f2f382efe 100755 --- a/roles/copy-release-tools-scripts/files/release-tools/launchpad_add_comment.py +++ b/roles/copy-release-tools-scripts/files/release-tools/launchpad_add_comment.py @@ -72,7 +72,7 @@ def main(): bug = launchpad.bugs[bugid] bug.newMessage(subject=args.subject, content=args.content) print(" done.") - except lazr.restfulclient.errors.ServerError as e: + except lazr.restfulclient.errors.ServerError: print(" TIMEOUT during save !") except Exception as e: print(" ERROR during save ! (%s)" % e) diff --git a/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py b/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py index f858e2888b..b2f884f1fd 100755 --- a/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py +++ b/roles/copy-release-tools-scripts/files/release-tools/process_release_requests.py @@ -43,7 +43,7 @@ CLOSED_SERIES = set([ 'newton', ]) -PRE_RELEASE_RE = re.compile(''' +PRE_RELEASE_RE = re.compile(r''' \.(\d+(?:[ab]|rc)+\d*)$ ''', flags=re.VERBOSE | re.UNICODE) @@ -61,8 +61,8 @@ def find_modified_deliverable_files(reporoot): filenames = [ l.strip() for l in results.splitlines() - if (l.startswith('deliverables/') and - not l.endswith('series_status.yaml')) + if (l.startswith('deliverables/') + and not l.endswith('series_status.yaml')) ] return filenames @@ -178,8 +178,8 @@ def process_release_requests(reporoot, filenames, meta_data): if not PRE_RELEASE_RE.search(r['version']) ] first_full_release = 'yes' if ( - final_versions and - this_version['version'] == final_versions[0] + final_versions + and this_version['version'] == final_versions[0] ) else 'no' diff_start = this_version.get('diff-start', '-') diff --git a/tools/batch_update_projects.py b/tools/batch_update_projects.py index dba9858b2a..c6e4680407 100644 --- a/tools/batch_update_projects.py +++ b/tools/batch_update_projects.py @@ -92,8 +92,8 @@ def handle_repo(path): repo.git.checkout(branch) repo.git.reset('--hard', 'remotes/origin/' + branch) for files in os.listdir(path): - if not ('zuul.yaml' in files or '.zuul.yaml' in files or - 'zuul.d' in files or '.zuul.d' in files): + if not ('zuul.yaml' in files or '.zuul.yaml' in files + or 'zuul.d' in files or '.zuul.d' in files): continue files = handle_branch(path) if files: diff --git a/tools/check_gerrit_projects_changed.py b/tools/check_gerrit_projects_changed.py index 3352732601..16be494fe1 100644 --- a/tools/check_gerrit_projects_changed.py +++ b/tools/check_gerrit_projects_changed.py @@ -80,8 +80,8 @@ def main(): upstream_old = p_old.get('upstream') else: upstream_old = "" - if (upstream != upstream_old and - 'track-upstream' in p.get('options', [])): + if (upstream != upstream_old + and 'track-upstream' in p.get('options', [])): print("%s has changed" % name) found_errors += check_repo(upstream) diff --git a/tools/check_irc_access.py b/tools/check_irc_access.py index ff6a72081f..8de0e6eee3 100755 --- a/tools/check_irc_access.py +++ b/tools/check_irc_access.py @@ -168,5 +168,6 @@ def main(): a.connect(args.server, int(args.port), mynick) a.start() + if __name__ == "__main__": main() diff --git a/tools/ci2project.py b/tools/ci2project.py index 4e1c8b3331..371b0b2381 100644 --- a/tools/ci2project.py +++ b/tools/ci2project.py @@ -61,8 +61,8 @@ while not done: r = requests.get(url, params=params) changes = json.loads(r.text[4:]) for change in changes: - if (not change.get('labels') or - not change.get('labels').get('Verified')): + if (not change.get('labels') or not + change.get('labels').get('Verified')): continue for key, value in change['labels']['Verified'].items(): if key == 'value': diff --git a/tools/fix-neutron-stadium.py b/tools/fix-neutron-stadium.py index b357a8e0a7..17a8bbb783 100644 --- a/tools/fix-neutron-stadium.py +++ b/tools/fix-neutron-stadium.py @@ -22,7 +22,7 @@ import yaml # from : -# http://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data # flake8: noqa +# http://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data # noqa: E501 def should_use_block(value): for c in u"\u000a\u000d\u001c\u001d\u001e\u0085\u2028\u2029": if c in value: @@ -42,6 +42,7 @@ def my_represent_scalar(self, tag, value, style=None): self.represented_objects[self.alias_key] = node return node + def project_representer(dumper, data): return dumper.represent_mapping('tag:yaml.org,2002:map', data.items()) @@ -150,7 +151,6 @@ def has_single_key(var): return True - def main(): subprocess.run(['git', 'checkout', '--', 'zuul.d/projects.yaml']) yaml = ruamel.yaml.YAML() @@ -185,5 +185,6 @@ def main(): main_out.write('\n') main_out.write(line[2:]) + if __name__ == '__main__': main() diff --git a/tools/irc_tests.py b/tools/irc_tests.py index b5194b2012..3c4e980ea2 100755 --- a/tools/irc_tests.py +++ b/tools/irc_tests.py @@ -71,5 +71,6 @@ def main(): print("No errors found in channel setup!") return errors + if __name__ == "__main__": sys.exit(main()) diff --git a/tools/normalize_acl.py b/tools/normalize_acl.py index 8880b2722f..3c524d5f4c 100755 --- a/tools/normalize_acl.py +++ b/tools/normalize_acl.py @@ -91,7 +91,7 @@ else: aclfd = open(aclfile) for line in aclfd: # condense whitespace to single spaces and get rid of leading/trailing - line = re.sub('\s+', ' ', line).strip() + line = re.sub(r'\s+', ' ', line).strip() # skip empty lines if not line: continue @@ -128,8 +128,8 @@ if '3' in transformations: if '4' in transformations: for section in acl.keys(): - acl[section] = [x for x in acl[section] if x != - 'owner = group Administrators'] + acl[section] = [x for x in acl[section] + if x != 'owner = group Administrators'] if '5' in transformations: for section in acl.keys(): diff --git a/tools/normalize_channels_yaml.py b/tools/normalize_channels_yaml.py index 1c986affb7..e11b11cedb 100755 --- a/tools/normalize_channels_yaml.py +++ b/tools/normalize_channels_yaml.py @@ -30,5 +30,6 @@ def main(): yaml.dump(chandata, stream=sys.stdout) + if __name__ == '__main__': main() diff --git a/tools/normalize_projects_yaml.py b/tools/normalize_projects_yaml.py index 2651b3a875..26e42732b1 100755 --- a/tools/normalize_projects_yaml.py +++ b/tools/normalize_projects_yaml.py @@ -23,12 +23,13 @@ def main(): data = yaml.load(open('gerrit/projects.yaml')) for project in data: - if ('upstream' in project and - 'track-upstream' not in project.get('options', [])): + if ('upstream' in project + and 'track-upstream' not in project.get('options', [])): del project['upstream'] with open('gerrit/projects.yaml', 'w') as out: yaml.dump(data, stream=out) + if __name__ == '__main__': main() diff --git a/tox.ini b/tox.ini index 3c6b136d16..a2bfd07e07 100644 --- a/tox.ini +++ b/tox.ini @@ -34,7 +34,7 @@ deps = # zuul requirements.txt ansible>=2.7.0,<2.8 ansible-lint<4 - hacking>=1.1,<1.2 + hacking>=2.0.0,<2.1.0 bashate>=0.2 commands = {toxinidir}/tools/run-bashate.sh