From ddbd0ba1d925b8b58ce9356cb68b59d18d14c28f Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 16 Jan 2020 15:12:58 +0000 Subject: [PATCH] trivial: Update to hacking 2.x Fixes an issue we're seeing in the python3-based gate plus some other random things. Change-Id: I417c0a7669090ee3419c406024f6f3e3289b4c4b Signed-off-by: Stephen Finucane --- git_review/cmd.py | 69 ++++++++++++++++-------- git_review/tests/__init__.py | 13 ++--- git_review/tests/check_test_id_hashes.py | 1 + git_review/tests/prepare.py | 1 + git_review/tests/test_git_review.py | 4 +- git_review/tests/utils.py | 31 +++++------ test-requirements.txt | 2 +- tox.ini | 2 +- 8 files changed, 75 insertions(+), 48 deletions(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index bba5a563..0bc7c219 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -1,23 +1,21 @@ # -*- coding: utf-8 -*- + +# Copyright (C) 2011-2020 OpenStack LLC. +# +# 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. + from __future__ import print_function -COPYRIGHT = """\ -Copyright (C) 2011-2012 OpenStack LLC. - -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.""" - import argparse import datetime import getpass @@ -48,6 +46,24 @@ USER_CONFIG = os.path.join(CONFIGDIR, "git-review.conf") DEFAULTS = dict(scheme='ssh', hostname=False, port=None, project=False, branch='master', remote="gerrit", rebase="1", track="0", usepushurl="0") +COPYRIGHT = """\ +Copyright (C) 2011-2020 OpenStack LLC. + +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. +""" + _branch_name = None _has_color = None @@ -469,8 +485,8 @@ def alias_url(url, rewrite_push): # there is a longer insteadOf alias. longest = None for alias in rewrites: - if (url.startswith(alias) - and (longest is None or len(longest) < len(alias))): + if url.startswith(alias) and ( + longest is None or len(longest) < len(alias)): longest = alias if longest: @@ -1183,7 +1199,7 @@ def fetch_review(review, masterbranch, remote, project): except KeyError: topic = review try: - author = re.sub('\W+', '_', review_info['owner']['name']).lower() + author = re.sub(r'\W+', '_', review_info['owner']['name']).lower() except KeyError: author = 'unknown' remote_branch = review_info['branch'] @@ -1216,7 +1232,7 @@ def checkout_review(branch_name, remote, remote_branch): branch_name) except CheckoutNewBranchFailed as e: - if re.search("already exists\.?", e.output): + if re.search(r"already exists\.?", e.output): print("Branch %s already exists - reusing" % branch_name) track_remote, track_branch = parse_tracking( ref='refs/heads/' + branch_name) @@ -1389,7 +1405,14 @@ class _DownloadFlag(argparse.Action): def _main(): usage = "git review [OPTIONS] ... [BRANCH]" - parser = argparse.ArgumentParser(usage=usage, description=COPYRIGHT) + description = """\ +A git command for submitting branches to Gerrit. + +git-review is a tool that helps submitting git branches to gerrit for +review. +""" + + parser = argparse.ArgumentParser(usage=usage, description=description) topic_arg_group = parser.add_mutually_exclusive_group() topic_arg_group.add_argument("-t", "--topic", dest="topic", @@ -1707,7 +1730,7 @@ def main(): # would report utf-8 # see: https://stackoverflow.com/a/23847316/99834 stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr - reload(sys) + reload(sys) # noqa sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr sys.setdefaultencoding(os.environ.get('PYTHONIOENCODING', 'utf-8')) diff --git a/git_review/tests/__init__.py b/git_review/tests/__init__.py index 128aae6e..fdc47ddb 100644 --- a/git_review/tests/__init__.py +++ b/git_review/tests/__init__.py @@ -20,6 +20,13 @@ import stat import struct import sys +import fixtures +import requests +import testtools +from testtools import content + +from git_review.tests import utils + if sys.version < '3': import urllib import urlparse @@ -29,12 +36,6 @@ else: import urllib.request urlparse = urllib.parse.urlparse -import fixtures -import requests -import testtools -from testtools import content - -from git_review.tests import utils WAR_URL = 'http://tarballs.openstack.org/' \ 'ci/gerrit/gerrit-v2.11.4.13.cb9800e.war' diff --git a/git_review/tests/check_test_id_hashes.py b/git_review/tests/check_test_id_hashes.py index a8aec24c..3b0ca3c2 100644 --- a/git_review/tests/check_test_id_hashes.py +++ b/git_review/tests/check_test_id_hashes.py @@ -53,5 +53,6 @@ def main(argv): ) return 2 + if __name__ == "__main__": sys.exit(main(sys.argv)) diff --git a/git_review/tests/prepare.py b/git_review/tests/prepare.py index 089f9419..a92a7e64 100644 --- a/git_review/tests/prepare.py +++ b/git_review/tests/prepare.py @@ -22,5 +22,6 @@ def main(): helpers.ensure_gerrit_war() helpers.init_gerrit() + if __name__ == "__main__": main() diff --git a/git_review/tests/test_git_review.py b/git_review/tests/test_git_review.py index 9546e7f1..8754428f 100644 --- a/git_review/tests/test_git_review.py +++ b/git_review/tests/test_git_review.py @@ -287,8 +287,8 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase): br_out = self._run_git('checkout', '-b', 'test_branch', 'origin/maint') - expected_track = ".*\nBranch '?test_branch'? set up to track remote" + \ - " branch '?maint'? from '?origin'?." + expected_track = (".*\nBranch '?test_branch'? set up to track remote " + "branch '?maint'? from '?origin'?.") track_matcher = testtools.matchers.MatchesRegex(expected_track) self.assertThat(br_out, track_matcher) branches = self._run_git('branch', '-a') diff --git a/git_review/tests/utils.py b/git_review/tests/utils.py index 337f48aa..10013f70 100644 --- a/git_review/tests/utils.py +++ b/git_review/tests/utils.py @@ -18,6 +18,22 @@ import subprocess import traceback +GERRIT_CONF_TMPL = """ +[gerrit] + basePath = git + canonicalWebUrl = http://nonexistent/ +[database] + type = h2 + database = db/ReviewDB +[auth] + type = DEVELOPMENT_BECOME_ANY_ACCOUNT +[sshd] + listenAddress = %s:%s +[httpd] + listenUrl = http://%s:%s/ +""" + + def run_cmd(*args, **kwargs): """Run command and check the return code.""" preexec_fn = None @@ -64,21 +80,6 @@ def write_to_file(path, content): with open(path, 'wb') as file_: file_.write(content) -GERRIT_CONF_TMPL = """ -[gerrit] - basePath = git - canonicalWebUrl = http://nonexistent/ -[database] - type = h2 - database = db/ReviewDB -[auth] - type = DEVELOPMENT_BECOME_ANY_ACCOUNT -[sshd] - listenAddress = %s:%s -[httpd] - listenUrl = http://%s:%s/ -""" - def get_gerrit_conf(ssh_addr, ssh_port, http_addr, http_port): return GERRIT_CONF_TMPL % (ssh_addr, ssh_port, http_addr, http_port) diff --git a/test-requirements.txt b/test-requirements.txt index 028581a7..19da82ed 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -hacking>=0.10.0,<0.11 +hacking>=2.0.0,<2.1.0 mock fixtures>=0.3.14 stestr>=2.2.0 diff --git a/tox.ini b/tox.ini index b1661623..4441d575 100644 --- a/tox.ini +++ b/tox.ini @@ -36,6 +36,6 @@ commands = commands = {posargs} [flake8] -ignore = E125,H202,H405,H904 +ignore = E125,H202,H405,H904,W504 show-source = True exclude = .venv,.git,.tox,dist,doc,releasenotes,*lib/python*,*egg,build