From ecfe3ee8deee02e779f5647ff479a66d68dd9cce Mon Sep 17 00:00:00 2001 From: Gil Date: Fri, 3 Apr 2020 16:13:55 -0700 Subject: [PATCH] Python 3 compatibility fixes (#5285) --- scripts/check_cmake_files.py | 4 ++-- scripts/lib/checker.py | 5 +++-- scripts/lib/git.py | 15 +++++++++------ scripts/make_release_notes.py | 6 ++++-- scripts/setup_check.sh | 1 + 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/check_cmake_files.py b/scripts/check_cmake_files.py index 3087284e91..76a28e0efc 100755 --- a/scripts/check_cmake_files.py +++ b/scripts/check_cmake_files.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2019 Google +# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -233,7 +233,7 @@ def group_by_cmakelists(filenames): g.list_file = filename g.list_files, g.ignored_files = read_listed_source_files(filename) - return sorted(list(groups.values())) + return sorted(list(groups.values()), key=lambda g: g.list_file) def find_all_errors(groups): diff --git a/scripts/lib/checker.py b/scripts/lib/checker.py index 80e64814db..aa67c7f37a 100644 --- a/scripts/lib/checker.py +++ b/scripts/lib/checker.py @@ -1,4 +1,4 @@ -# Copyright 2019 Google +# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ from __future__ import division import math import multiprocessing.pool +import six import sys import threading @@ -54,7 +55,7 @@ class Result(object): def __init__(self, num_errors, output): self.errors = num_errors - self.output = output + self.output = six.ensure_text(output) @staticmethod def from_list(errors): diff --git a/scripts/lib/git.py b/scripts/lib/git.py index 603ad3c889..8fe29556dd 100644 --- a/scripts/lib/git.py +++ b/scripts/lib/git.py @@ -1,4 +1,4 @@ -# Copyright 2019 Google +# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,11 +11,14 @@ # 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 lib import source -import command_trace + import os +import six import subprocess +from lib import command_trace +from lib import source + def find_changed_or_files(all, rev_or_files, patterns): """Finds files. @@ -102,7 +105,7 @@ def find_lines_matching(pattern, sources=None): proc.terminate() proc.wait() - return ''.join(result) + return six.ensure_text(b''.join(result)) def make_patterns(dirs): @@ -132,11 +135,11 @@ def is_within_repo(): def get_repo_root(): """Returns the absolute path to the root of the current git repo.""" command = ['git', 'rev-parse', '--show-toplevel'] - return subprocess.check_output(command).rstrip() + return six.ensure_text(subprocess.check_output(command).rstrip()) def _null_split_output(command): """Runs the given command and splits its output on the null byte.""" command_trace.log(command) - result = subprocess.check_output(command) + result = six.ensure_text(subprocess.check_output(command)) return [name for name in result.rstrip().split('\0') if name] diff --git a/scripts/make_release_notes.py b/scripts/make_release_notes.py index 8dd3a3a37e..c68787c827 100755 --- a/scripts/make_release_notes.py +++ b/scripts/make_release_notes.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Copyright 2019 Google +# Copyright 2019 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import re import subprocess import string +import six NO_HEADING = 'PRODUCT HAS NO HEADING' @@ -78,7 +79,8 @@ def main(): def find_local_repo(): - url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']) + url = six.ensure_text( + subprocess.check_output(['git', 'config', '--get', 'remote.origin.url'])) # ssh or https style URL m = re.match(r'^(?:git@github\.com:|https://github\.com/)(.*)\.git$', url) diff --git a/scripts/setup_check.sh b/scripts/setup_check.sh index 7c4d0176cf..bf9649bd5b 100755 --- a/scripts/setup_check.sh +++ b/scripts/setup_check.sh @@ -25,6 +25,7 @@ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c6f1cbd/Fo brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c13eda8/Formula/swiftformat.rb pip install flake8 +pip install six # Using actions/checkout@v2 creates a shallow clone that's missing the master # branch. If it's not present, add it.