From ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Sat, 11 Mar 2023 06:46:20 +0000 Subject: Format codebase with black and check formatting in CQ Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught by flake8. Also check black formatting in run_tests (and CQ). Bug: b/267675342 Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474 Reviewed-by: Mike Frysinger Tested-by: Gavin Mak Commit-Queue: Gavin Mak --- release/util.py | 78 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 36 deletions(-) (limited to 'release/util.py') diff --git a/release/util.py b/release/util.py index 9d0eb1dc..df7a5638 100644 --- a/release/util.py +++ b/release/util.py @@ -20,54 +20,60 @@ import subprocess import sys -assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' +assert sys.version_info >= (3, 6), "This module requires Python 3.6+" TOPDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -HOMEDIR = os.path.expanduser('~') +HOMEDIR = os.path.expanduser("~") # These are the release keys we sign with. -KEYID_DSA = '8BB9AD793E8E6153AF0F9A4416530D5E920F5C65' -KEYID_RSA = 'A34A13BE8E76BFF46A0C022DA2E75A824AAB9624' -KEYID_ECC = 'E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39' +KEYID_DSA = "8BB9AD793E8E6153AF0F9A4416530D5E920F5C65" +KEYID_RSA = "A34A13BE8E76BFF46A0C022DA2E75A824AAB9624" +KEYID_ECC = "E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39" def cmdstr(cmd): - """Get a nicely quoted shell command.""" - ret = [] - for arg in cmd: - if not re.match(r'^[a-zA-Z0-9/_.=-]+$', arg): - arg = f'"{arg}"' - ret.append(arg) - return ' '.join(ret) + """Get a nicely quoted shell command.""" + ret = [] + for arg in cmd: + if not re.match(r"^[a-zA-Z0-9/_.=-]+$", arg): + arg = f'"{arg}"' + ret.append(arg) + return " ".join(ret) def run(opts, cmd, check=True, **kwargs): - """Helper around subprocess.run to include logging.""" - print('+', cmdstr(cmd)) - if opts.dryrun: - cmd = ['true', '--'] + cmd - try: - return subprocess.run(cmd, check=check, **kwargs) - except subprocess.CalledProcessError as e: - print(f'aborting: {e}', file=sys.stderr) - sys.exit(1) + """Helper around subprocess.run to include logging.""" + print("+", cmdstr(cmd)) + if opts.dryrun: + cmd = ["true", "--"] + cmd + try: + return subprocess.run(cmd, check=check, **kwargs) + except subprocess.CalledProcessError as e: + print(f"aborting: {e}", file=sys.stderr) + sys.exit(1) def import_release_key(opts): - """Import the public key of the official release repo signing key.""" - # Extract the key from our repo launcher. - launcher = getattr(opts, 'launcher', os.path.join(TOPDIR, 'repo')) - print(f'Importing keys from "{launcher}" launcher script') - with open(launcher, encoding='utf-8') as fp: - data = fp.read() - - keys = re.findall( - r'\n-----BEGIN PGP PUBLIC KEY BLOCK-----\n[^-]*' - r'\n-----END PGP PUBLIC KEY BLOCK-----\n', data, flags=re.M) - run(opts, ['gpg', '--import'], input='\n'.join(keys).encode('utf-8')) - - print('Marking keys as fully trusted') - run(opts, ['gpg', '--import-ownertrust'], - input=f'{KEYID_DSA}:6:\n'.encode('utf-8')) + """Import the public key of the official release repo signing key.""" + # Extract the key from our repo launcher. + launcher = getattr(opts, "launcher", os.path.join(TOPDIR, "repo")) + print(f'Importing keys from "{launcher}" launcher script') + with open(launcher, encoding="utf-8") as fp: + data = fp.read() + + keys = re.findall( + r"\n-----BEGIN PGP PUBLIC KEY BLOCK-----\n[^-]*" + r"\n-----END PGP PUBLIC KEY BLOCK-----\n", + data, + flags=re.M, + ) + run(opts, ["gpg", "--import"], input="\n".join(keys).encode("utf-8")) + + print("Marking keys as fully trusted") + run( + opts, + ["gpg", "--import-ownertrust"], + input=f"{KEYID_DSA}:6:\n".encode("utf-8"), + ) -- cgit v1.2.3-54-g00ecf