Skip to content

Commit ecfe3ee

Browse files
authored
Python 3 compatibility fixes (#5285)
1 parent af7898c commit ecfe3ee

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

scripts/check_cmake_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2019 Google
3+
# Copyright 2019 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -233,7 +233,7 @@ def group_by_cmakelists(filenames):
233233
g.list_file = filename
234234
g.list_files, g.ignored_files = read_listed_source_files(filename)
235235

236-
return sorted(list(groups.values()))
236+
return sorted(list(groups.values()), key=lambda g: g.list_file)
237237

238238

239239
def find_all_errors(groups):

scripts/lib/checker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google
1+
# Copyright 2019 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
import math
1818
import multiprocessing.pool
19+
import six
1920
import sys
2021
import threading
2122

@@ -54,7 +55,7 @@ class Result(object):
5455

5556
def __init__(self, num_errors, output):
5657
self.errors = num_errors
57-
self.output = output
58+
self.output = six.ensure_text(output)
5859

5960
@staticmethod
6061
def from_list(errors):

scripts/lib/git.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google
1+
# Copyright 2019 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,11 +11,14 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from lib import source
15-
import command_trace
14+
1615
import os
16+
import six
1717
import subprocess
1818

19+
from lib import command_trace
20+
from lib import source
21+
1922

2023
def find_changed_or_files(all, rev_or_files, patterns):
2124
"""Finds files.
@@ -102,7 +105,7 @@ def find_lines_matching(pattern, sources=None):
102105
proc.terminate()
103106
proc.wait()
104107

105-
return ''.join(result)
108+
return six.ensure_text(b''.join(result))
106109

107110

108111
def make_patterns(dirs):
@@ -132,11 +135,11 @@ def is_within_repo():
132135
def get_repo_root():
133136
"""Returns the absolute path to the root of the current git repo."""
134137
command = ['git', 'rev-parse', '--show-toplevel']
135-
return subprocess.check_output(command).rstrip()
138+
return six.ensure_text(subprocess.check_output(command).rstrip())
136139

137140

138141
def _null_split_output(command):
139142
"""Runs the given command and splits its output on the null byte."""
140143
command_trace.log(command)
141-
result = subprocess.check_output(command)
144+
result = six.ensure_text(subprocess.check_output(command))
142145
return [name for name in result.rstrip().split('\0') if name]

scripts/make_release_notes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2019 Google
3+
# Copyright 2019 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import subprocess
2323
import string
2424

25+
import six
2526

2627
NO_HEADING = 'PRODUCT HAS NO HEADING'
2728

@@ -78,7 +79,8 @@ def main():
7879

7980

8081
def find_local_repo():
81-
url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url'])
82+
url = six.ensure_text(
83+
subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']))
8284

8385
# ssh or https style URL
8486
m = re.match(r'^(?:git@github\.com:|https://github\.com/)(.*)\.git$', url)

scripts/setup_check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c6f1cbd/Fo
2525
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c13eda8/Formula/swiftformat.rb
2626

2727
pip install flake8
28+
pip install six
2829

2930
# Using actions/checkout@v2 creates a shallow clone that's missing the master
3031
# branch. If it's not present, add it.

0 commit comments

Comments
 (0)