From 1b262b57844ac2c2cefeb2e064a97f7dd2ffc197 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 2 Jun 2020 00:22:36 -0700 Subject: [PATCH] Fix failures with latest gpylint Change-Id: Id80000b530b0582b907730db9311075a7f5307fa --- gyp_packager.py | 4 +++- packager/app/test/packager_test.py | 8 +++++++- packager/tools/git/check_formatting.py | 8 ++++++-- packager/tools/pssh/pssh-box.py | 8 +++++--- packager/version/generate_version_string.py | 6 ++++-- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/gyp_packager.py b/gyp_packager.py index bfd047c85f..e62452912c 100755 --- a/gyp_packager.py +++ b/gyp_packager.py @@ -30,6 +30,8 @@ Step 1 is only required if there is any gyp file change. Otherwise, you may just run ninja. """ +from __future__ import print_function + import os import sys @@ -108,7 +110,7 @@ if __name__ == '__main__': else: os.environ['GYP_GENERATOR_FLAGS'] = gyp_generator_flags - print 'Updating projects from gyp files...' + print('Updating projects from gyp files...') sys.stdout.flush() # Off we go... diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 188465e798..5aec6796d5 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -623,7 +623,13 @@ class PackagerFunctionalTest(PackagerAppTest): self.assertEqual(self.packager.MpdGenerator(flags), 0) def testVersion(self): - self.assertRegexpMatches( + # To support python version 2, which does not have assertRegex. + if 'assertRegex' not in dir(self): + assert_regex = self.assertRegexpMatches + else: + assert_regex = self.assertRegex + + assert_regex( self.packager.Version(), '^packager(.exe)? version ' r'((?P[\w\.]+)-)?(?P[a-f\d]+)-(debug|release)[\r\n]+.*$') diff --git a/packager/tools/git/check_formatting.py b/packager/tools/git/check_formatting.py index bfd8d7cd8e..55926a1f6c 100755 --- a/packager/tools/git/check_formatting.py +++ b/packager/tools/git/check_formatting.py @@ -32,6 +32,8 @@ Steps to install clang-format on your system if you don't have it already: """ +from __future__ import print_function + import subprocess import sys @@ -49,8 +51,10 @@ if __name__ == '__main__': if output not in [ 'no modified files to format\n', 'clang-format did not modify any files\n' ]: - print output, '\n' - print 'Code style is not correct. Please run ', ' '.join(command), '\n' + print(output) + print() + print('Code style is not correct. Please run {}.'.format(' '.join(command))) + print() sys.exit(1) else: sys.exit(0) diff --git a/packager/tools/pssh/pssh-box.py b/packager/tools/pssh/pssh-box.py index 70c67d6730..66a0ab0fd2 100755 --- a/packager/tools/pssh/pssh-box.py +++ b/packager/tools/pssh/pssh-box.py @@ -7,6 +7,8 @@ """A utility to parse and generate PSSH boxes.""" +from __future__ import print_function + import argparse import base64 import itertools @@ -419,13 +421,13 @@ def main(all_args): if output_format == 'human' or not output_format: for box in boxes: - print box.human_string() + print(box.human_string()) else: box_data = ''.join([x.binary_string() for x in boxes]) if output_format == 'hex': - print base64.b16encode(box_data) + print(base64.b16encode(box_data)) else: - print base64.b64encode(box_data) + print(base64.b64encode(box_data)) if __name__ == '__main__': diff --git a/packager/version/generate_version_string.py b/packager/version/generate_version_string.py index 814dec3b8a..17c241724a 100755 --- a/packager/version/generate_version_string.py +++ b/packager/version/generate_version_string.py @@ -7,6 +7,8 @@ # https://developers.google.com/open-source/licenses/bsd """This script is used to generate version string for packager.""" +from __future__ import print_function + import subprocess # To support python version before 2.7, which does not have @@ -47,6 +49,6 @@ if __name__ == '__main__': version_hash = 'unknown-version' if version_tag: - print '{0}-{1}'.format(version_tag, version_hash) + print('{0}-{1}'.format(version_tag, version_hash)) else: - print version_hash + print(version_hash)